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
}
#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
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