new feature: interpret also <filename>:<linenumber> when opening a file

Various tools will output filenames with line numbers in the format
<filename>:<line>:<column>.  Support this format in addition to the
+<line>,<column> format when opening files.

Signed-off-by: Benjamin Valentin <benpicco@googlemail.com>
Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
This commit is contained in:
Benjamin Valentin 2023-01-29 23:43:00 +01:00 committed by Benno Schulenberg
parent b5157dd9cb
commit 5290a85afd
2 changed files with 27 additions and 3 deletions

View File

@ -2482,8 +2482,32 @@ int main(int argc, char **argv)
continue;
} else
#endif
if (!open_buffer(argv[optind++], TRUE))
continue;
{
char *filename = argv[optind++];
char *colon = filename + (*filename ? 1 : 0);
/* Search for a colon, to open the file on a specific line. */
while ((colon = strchr(colon, ':'))) {
/* If the colon is escaped, unescape it and skip it. */
if (*(colon - 1) == '\\') {
memmove(colon - 1, colon, strlen(colon) + 1);
continue;
}
/* If parsing succeeds, cut off the line suffix. */
if (parse_line_column(colon + 1, &givenline, &givencol)) {
*colon = 0;
break;
}
/* Parsing failed; skip this colon. */
++colon;
}
if (!open_buffer(filename, TRUE))
continue;
}
/* If a position was given on the command line, go there. */
if (givenline != 0 || givencol != 0)

View File

@ -137,7 +137,7 @@ bool parse_line_column(const char *str, ssize_t *line, ssize_t *column)
while (*str == ' ')
str++;
comma = strpbrk(str, "m,. /;");
comma = strpbrk(str, "m,. /;:");
if (comma == NULL)
return parse_num(str, line);