>From 2cfc4c2c046dea89acb620e013f35f3b9644fa78 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. --- src/nano.c | 32 ++++++++++++++++++++++++++++++-- src/utils.c | 2 +- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/nano.c b/src/nano.c index 4d5e7ea6..bbc27e26 100644 --- a/src/nano.c +++ b/src/nano.c @@ -2482,8 +2482,36 @@ int main(int argc, char **argv) continue; } else #endif - if (!open_buffer(argv[optind++], TRUE)) - continue; + { + char *filename = argv[optind++]; + + /* search for : to open file on a specific line */ + char *colon = filename; + while ((colon = strchr(colon, ':'))) { + + /* if file starts with : skip that */ + if (colon == filename) { + ++colon; + continue; + } + + /* If : is escaped with \, unescape it and search for the next occurrence */ + if (*(colon - 1) == '\\') { + size_t len = strlen(colon); + memmove(colon - 1, colon, len); + colon[len - 1] = 0; + continue; + } + + /* if parsing succeeds, cut of the line suffix */ + if (parse_line_column(colon + 1, &givenline, &givencol)) + *colon = 0; + break; + } + + 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