From a96b11b7ceb1e64c4e5aec8d8545ef838da4163d Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Sun, 29 Jan 2023 23:43:00 +0100 Subject: [PATCH] startup: add support for : format Many tools will output files with line numbers in the format ::. Support this format in addition to the +, format when opening files. Signed-off-by: Benjamin Valentin --- src/nano.c | 29 +++++++++++++++++++++++++++-- src/utils.c | 2 +- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/nano.c b/src/nano.c index 4d5e7ea6..980d295f 100644 --- a/src/nano.c +++ b/src/nano.c @@ -2482,8 +2482,33 @@ int main(int argc, char **argv) continue; } else #endif - if (!open_buffer(argv[optind++], TRUE)) - continue; + { + char *filename = argv[optind++]; + char *colon = filename + 1; + + /* Search for : to open file on a specific line. */ + while ((colon = strchr(colon, ':'))) { + + /* If : is escaped with \, unescape it and search for the next occurrence. */ + if (*(colon - 1) == '\\') { + size_t len = strlen(colon); + memmove(colon - 1, colon + 1, len); + continue; + } + + /* If parsing succeeds, cut of the line suffix. */ + if (parse_line_column(colon + 1, &givenline, &givencol)) { + *colon = 0; + break; + } + + /* Parsing failed, try to find another : */ + ++colon; + } + + if (!open_buffer(filename, TRUE)) + continue; + } /* If a position was given on the command line, go there. */ if (givenline != 0 || givencol != 0) diff --git a/src/utils.c b/src/utils.c index 18c6e35c..3be197e2 100644 --- a/src/utils.c +++ b/src/utils.c @@ -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); -- 2.37.2