comparison src/share/vm/graal/graalRuntime.cpp @ 21123:85b0935625c1

graalRuntime: make service file parsing more robust: - support various line endings (\r, \n and \r\n) - support # comments - support empty lines
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Mon, 27 Apr 2015 18:17:18 +0200
parents 4527d2428f37
children 93dc70e47fb0
comparison
equal deleted inserted replaced
21122:7f78f999512a 21123:85b0935625c1
1097 if (num_read == st.st_size) { 1097 if (num_read == st.st_size) {
1098 buffer[num_read] = '\0'; 1098 buffer[num_read] = '\0';
1099 GrowableArray<char*>* implNames = new GrowableArray<char*>(); 1099 GrowableArray<char*>* implNames = new GrowableArray<char*>();
1100 char* line = buffer; 1100 char* line = buffer;
1101 while (line - buffer < num_read) { 1101 while (line - buffer < num_read) {
1102 char* nl = strchr(line, '\n'); 1102 // find line end (\r, \n or \r\n)
1103 if (nl != NULL) { 1103 char* nextline = NULL;
1104 *nl = '\0'; 1104 char* cr = strchr(line, '\r');
1105 char* lf = strchr(line, '\n');
1106 if (cr != NULL && lf != NULL) {
1107 char* min = MIN2(cr, lf);
1108 *min = '\0';
1109 if (lf == cr + 1) {
1110 nextline = lf + 1;
1111 } else {
1112 nextline = min + 1;
1113 }
1114 } else if (cr != NULL) {
1115 *cr = '\0';
1116 nextline = cr + 1;
1117 } else if (lf != NULL) {
1118 *lf = '\0';
1119 nextline = lf + 1;
1105 } 1120 }
1106 // Turn all '.'s into '/'s 1121 // trim left
1107 for (size_t index = 0; line[index] != '\0'; index++) { 1122 while (*line == ' ' || *line == '\t') line++;
1108 if (line[index] == '.') { 1123 char* end = line + strlen(line);
1109 line[index] = '/'; 1124 // trim right
1125 while (end > line && (*(end -1) == ' ' || *(end -1) == '\t')) end--;
1126 *end = '\0';
1127 // skip comments and empty lines
1128 if (*line != '#' && strlen(line) > 0) {
1129 // Turn all '.'s into '/'s
1130 for (size_t index = 0; line[index] != '\0'; index++) {
1131 if (line[index] == '.') {
1132 line[index] = '/';
1133 }
1110 } 1134 }
1135 implNames->append(line);
1111 } 1136 }
1112 implNames->append(line); 1137 if (nextline != NULL) {
1113 if (nl != NULL) { 1138 line = nextline;
1114 line = nl + 1;
1115 } else { 1139 } else {
1116 // File without newline at the end 1140 // File without newline at the end
1117 break; 1141 break;
1118 } 1142 }
1119 } 1143 }