From 837b4e66e245ea80e7924bb41bc192c3f9d62ef0 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Thu, 10 Mar 2016 10:36:49 +0000 Subject: [PATCH] Folding the parsing of a linter and formatter command into a single routine. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5714 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 2 ++ src/rcfile.c | 47 ++++++++++------------------------------------- 2 files changed, 12 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index 50f54f00..cb018a1c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,8 @@ 2016-03-10 Benno Schulenberg * src/rcfile.c (grab_and_store): Do not accept 'header" and 'magic' commands for the default syntax. This fixes Savannah bug #47323. + * src/rcfile.c (pick_up_name): Fold the parsing of a linter and + formatter command into a single routine. 2016-03-09 Benno Schulenberg * src/rcfile.c (parse_syntax): Produce an adequate error message diff --git a/src/rcfile.c b/src/rcfile.c index 201a3b30..801a1623 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -877,57 +877,30 @@ void parse_magic_exp(char *ptr) } #endif /* HAVE_LIBMAGIC */ -/* Parse the linter requested for this syntax. */ -void parse_linter(char *ptr) +/* Parse and store the name given after a linter/formatter command. */ +void pick_up_name(const char *kind, char *ptr, char **storage) { assert(ptr != NULL); if (!opensyntax) { rcfile_error( - N_("Cannot add a linter without a syntax command")); - return; - } - - if (*ptr == '\0') { - rcfile_error(N_("Missing linter command")); - return; - } - - free(endsyntax->linter); - - /* Let them unset the linter by using "". */ - if (!strcmp(ptr, "\"\"")) - endsyntax->linter = NULL; - else - endsyntax->linter = mallocstrcpy(NULL, ptr); -} - -#ifndef DISABLE_SPELLER -/* Parse the formatter requested for this syntax. */ -void parse_formatter(char *ptr) -{ - assert(ptr != NULL); - - if (!opensyntax) { - rcfile_error( - N_("Cannot add formatter without a syntax command")); + N_("A '%s' command requires a preceding 'syntax' command"), kind); return; } if (*ptr == '\0') { - rcfile_error(N_("Missing formatter command")); + rcfile_error(N_("Missing command after '%s'"), kind); return; } - free(endsyntax->formatter); + free(*storage); - /* Let them unset the formatter by using "". */ + /* Allow unsetting the command by using an empty string. */ if (!strcmp(ptr, "\"\"")) - endsyntax->formatter = NULL; + *storage = NULL; else - endsyntax->formatter = mallocstrcpy(NULL, ptr); + *storage = mallocstrcpy(NULL, ptr); } -#endif /* !DISABLE_SPELLER */ #endif /* !DISABLE_COLOR */ /* Check whether the user has unmapped every shortcut for a @@ -1070,10 +1043,10 @@ void parse_rcfile(FILE *rcstream else if (strcasecmp(keyword, "icolor") == 0) parse_colors(ptr, TRUE); else if (strcasecmp(keyword, "linter") == 0) - parse_linter(ptr); + pick_up_name("linter", ptr, &endsyntax->linter); else if (strcasecmp(keyword, "formatter") == 0) #ifndef DISABLE_SPELLER - parse_formatter(ptr); + pick_up_name("formatter", ptr, &endsyntax->formatter); #else ; #endif -- 2.39.5