tweaks: condense the code that searches for a colon plus line number

This commit is contained in:
Benno Schulenberg 2023-03-09 12:56:17 +01:00
parent 5290a85afd
commit f1e238a9af

View File

@ -2486,23 +2486,17 @@ int main(int argc, char **argv)
char *filename = argv[optind++];
char *colon = filename + (*filename ? 1 : 0);
/* Search for a colon, to open the file on a specific line. */
/* Search the filename for a colon. If the colon is preceded by
* a backslash, elide the backslash and skip the colon. If there
* is a valid number after the colon, chop colon and number off.
* The number is later used to place the cursor on that line. */
while ((colon = strchr(colon, ':'))) {
/* If the colon is escaped, unescape it and skip it. */
if (*(colon - 1) == '\\') {
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;
else if (parse_line_column(colon + 1, &givenline, &givencol))
*colon = '\0';
else
++colon;
}
if (!open_buffer(filename, TRUE))