commit f1e238a9af2a30c67252d099e8f32698dead2ed9
parent 5290a85afd67271af311e565d98fe279f73473a6
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Thu, 9 Mar 2023 12:56:17 +0100
tweaks: condense the code that searches for a colon plus line number
Diffstat:
1 file changed, 9 insertions(+), 15 deletions(-)
diff --git a/src/nano.c b/src/nano.c
@@ -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))