diff --git a/ChangeLog b/ChangeLog index 50f54f00c5e0e1d7503bd0463ab50e30786a249d..cb018a1cb5b1d761c922bb29921a448355aeebe2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,8 @@ 2016-03-10 Benno Schulenberg <bensberg@justemail.net> * 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 <bensberg@justemail.net> * src/rcfile.c (parse_syntax): Produce an adequate error message diff --git a/src/rcfile.c b/src/rcfile.c index 201a3b3046e65b2e36d9fd7b688f8d6b97388d8f..801a16232c2564312189228eb364f1e4bce711a8 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