# HG changeset patch # User Gilles Duboscq # Date 1430151438 -7200 # Node ID 85b0935625c1ded29f29cfe43fb6e40991bfa743 # Parent 7f78f999512a5a125f6421e5bf704f8b8fc5a71d graalRuntime: make service file parsing more robust: - support various line endings (\r, \n and \r\n) - support # comments - support empty lines diff -r 7f78f999512a -r 85b0935625c1 src/share/vm/graal/graalRuntime.cpp --- a/src/share/vm/graal/graalRuntime.cpp Mon Apr 27 16:11:46 2015 +0200 +++ b/src/share/vm/graal/graalRuntime.cpp Mon Apr 27 18:17:18 2015 +0200 @@ -1099,19 +1099,43 @@ GrowableArray* implNames = new GrowableArray(); char* line = buffer; while (line - buffer < num_read) { - char* nl = strchr(line, '\n'); - if (nl != NULL) { - *nl = '\0'; + // find line end (\r, \n or \r\n) + char* nextline = NULL; + char* cr = strchr(line, '\r'); + char* lf = strchr(line, '\n'); + if (cr != NULL && lf != NULL) { + char* min = MIN2(cr, lf); + *min = '\0'; + if (lf == cr + 1) { + nextline = lf + 1; + } else { + nextline = min + 1; + } + } else if (cr != NULL) { + *cr = '\0'; + nextline = cr + 1; + } else if (lf != NULL) { + *lf = '\0'; + nextline = lf + 1; } - // Turn all '.'s into '/'s - for (size_t index = 0; line[index] != '\0'; index++) { - if (line[index] == '.') { - line[index] = '/'; + // trim left + while (*line == ' ' || *line == '\t') line++; + char* end = line + strlen(line); + // trim right + while (end > line && (*(end -1) == ' ' || *(end -1) == '\t')) end--; + *end = '\0'; + // skip comments and empty lines + if (*line != '#' && strlen(line) > 0) { + // Turn all '.'s into '/'s + for (size_t index = 0; line[index] != '\0'; index++) { + if (line[index] == '.') { + line[index] = '/'; + } } + implNames->append(line); } - implNames->append(line); - if (nl != NULL) { - line = nl + 1; + if (nextline != NULL) { + line = nextline; } else { // File without newline at the end break;