From b68c01b7533f733c6ebf57f67568594b8c08b1e3 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Mon, 16 May 2005 23:23:15 +0000 Subject: [PATCH] move duplicate code from the +LINE,COLUMN feature into a separate function, parse_line_column() git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2517 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 4 ++-- src/nano.c | 15 ++------------- src/proto.h | 1 + src/utils.c | 15 +++++++++++++++ 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index b3315e69..31f2b931 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,8 +15,8 @@ CVS code - various comments. (DLR) - Add the ability to open a file on a specified column as well as a specified line, by allowing an argument of the form - +LINE,COLUMN. Changes to main(), nano.1, and nano.texi. (DLR, - suggested by PFTank) + +LINE,COLUMN. New function parse_line_column(); changes to + main(), nano.1, and nano.texi. (DLR, suggested by PFTank) - cut.c: cut_line() - Set placewewant properly after cutting a line, to avoid a diff --git a/src/nano.c b/src/nano.c index ec564212..c3869d64 100644 --- a/src/nano.c +++ b/src/nano.c @@ -4427,13 +4427,7 @@ int main(int argc, char **argv) * non-option argument, and it is followed by at least one other * argument, the filename it applies to. */ if (0 < optind && optind < argc - 1 && argv[optind][0] == '+') { - char *comma = strchr(&argv[optind][1], ','); - - if (comma != NULL) - parse_num(&argv[optind][comma - argv[optind] + 1], - &startcol); - - startline = atoi(&argv[optind][1]); + parse_line_column(&argv[optind][1], &startline, &startcol); optind++; } @@ -4453,12 +4447,7 @@ int main(int argc, char **argv) * applies to. */ if (i < argc - 1 && argv[i][0] == '+' && iline == 1 && icol == 1) { - char *comma = strchr(&argv[i][1], ','); - - if (comma != NULL) - parse_num(&argv[i][comma - argv[i] + 1], &icol); - - iline = atoi(&argv[i][1]); + parse_line_column(&argv[i][1], &iline, &icol); } else { load_buffer(argv[i]); diff --git a/src/proto.h b/src/proto.h index 4d16a9a2..3af2a555 100644 --- a/src/proto.h +++ b/src/proto.h @@ -547,6 +547,7 @@ int regexp_bol_or_eol(const regex_t *preg, const char *string); int digits(size_t n); void get_homedir(void); bool parse_num(const char *str, ssize_t *val); +void parse_line_column(const char *str, int *line, ssize_t *column); void align(char **strp); void null_at(char **data, size_t index); void unsunder(char *str, size_t true_len); diff --git a/src/utils.c b/src/utils.c index 5cd86d3c..de7b43d3 100644 --- a/src/utils.c +++ b/src/utils.c @@ -105,6 +105,21 @@ bool parse_num(const char *str, ssize_t *val) return TRUE; } +void parse_line_column(const char *str, int *line, ssize_t *column) +{ + char *comma; + + assert(str != NULL); + + comma = strchr(str, ','); + + if (comma != NULL && column != NULL) + parse_num(&str[comma - str + 1], column); + + if (line != NULL) + *line = atoi(str); +} + /* Fix the memory allocation for a string. */ void align(char **strp) { -- 2.39.5