tweaks: condense the code that searches for a colon plus line number
This commit is contained in:
parent
5290a85afd
commit
f1e238a9af
24
src/nano.c
24
src/nano.c
@ -2486,23 +2486,17 @@ int main(int argc, char **argv)
|
|||||||
char *filename = argv[optind++];
|
char *filename = argv[optind++];
|
||||||
char *colon = filename + (*filename ? 1 : 0);
|
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, ':'))) {
|
while ((colon = strchr(colon, ':'))) {
|
||||||
|
if (*(colon - 1) == '\\')
|
||||||
/* If the colon is escaped, unescape it and skip it. */
|
|
||||||
if (*(colon - 1) == '\\') {
|
|
||||||
memmove(colon - 1, colon, strlen(colon) + 1);
|
memmove(colon - 1, colon, strlen(colon) + 1);
|
||||||
continue;
|
else if (parse_line_column(colon + 1, &givenline, &givencol))
|
||||||
}
|
*colon = '\0';
|
||||||
|
else
|
||||||
/* If parsing succeeds, cut off the line suffix. */
|
++colon;
|
||||||
if (parse_line_column(colon + 1, &givenline, &givencol)) {
|
|
||||||
*colon = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Parsing failed; skip this colon. */
|
|
||||||
++colon;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!open_buffer(filename, TRUE))
|
if (!open_buffer(filename, TRUE))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user