commit 265d3245af26672f1839bdfc87e1c1198546ee78
parent 53d4224be9a73916eec82fd13e3fe60fef3555a0
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Mon, 7 Oct 2019 09:10:06 +0200
rcfile: process extensions to file-matching commands straightaway
When 'extendsyntax' is used with a 'header' or 'magic' command, it
must be processed immediately. It is pointless to store the command,
because when then it is processed (when the syntax gets used), it is
too late to have any effect.
This fixes https://savannah.gnu.org/bugs/?56997.
With-help-from: Brand Huntsman <alpha@qzx.com>
Bug existed since version 4.3, commit cba9d8d0.
Diffstat:
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/src/rcfile.c b/src/rcfile.c
@@ -1001,6 +1001,7 @@ void parse_rcfile(FILE *rcstream, bool just_syntax, bool intros_only)
while ((len = getline(&buffer, &size, rcstream)) > 0) {
char *ptr, *keyword, *option;
+ bool drop_open = FALSE;
int set = 0;
size_t i;
@@ -1032,6 +1033,7 @@ void parse_rcfile(FILE *rcstream, bool just_syntax, bool intros_only)
if (!just_syntax && strcasecmp(keyword, "extendsyntax") == 0) {
augmentstruct *newitem, *extra;
char *syntaxname = ptr;
+ char *argument;
syntaxtype *sint;
check_for_nonempty_syntax();
@@ -1047,12 +1049,23 @@ void parse_rcfile(FILE *rcstream, bool just_syntax, bool intros_only)
continue;
}
+ argument = strdup(ptr);
+ keyword = ptr;
+ ptr = parse_next_word(ptr);
+
+ /* File-matching commands need to be processed immediately;
+ * other commands are stored for possible later processing. */
+ if (strcmp(keyword, "header") == 0 || strcmp(keyword, "magic") == 0) {
+ free(argument);
+ live_syntax = sint;
+ opensyntax = TRUE;
+ drop_open = TRUE;
+ } else {
newitem = nmalloc(sizeof(augmentstruct));;
- /* Store the content of an 'extendsyntax', for later parsing. */
newitem->filename = strdup(nanorc);
newitem->lineno = lineno;
- newitem->data = strdup(ptr);
+ newitem->data = argument;
newitem->next = NULL;
if (sint->augmentations != NULL) {
@@ -1064,6 +1077,7 @@ void parse_rcfile(FILE *rcstream, bool just_syntax, bool intros_only)
sint->augmentations = newitem;
continue;
+ }
}
/* Try to parse the keyword. */
@@ -1120,6 +1134,9 @@ void parse_rcfile(FILE *rcstream, bool just_syntax, bool intros_only)
else if (intros_only)
jot_error(N_("Command \"%s\" not understood"), keyword);
+ if (drop_open)
+ opensyntax = FALSE;
+
if (set == 0)
continue;