formatter command into a single routine.
* src/rcfile.c (parse_header_exp, parse_magic_exp, grab_and_store):
Elide the first two functions, and reshuffle parameters in the last.
+ * src/rcfile.c (parse_syntax, parse_rcfile), src/color.c
+ (color_update): Turn the linked list of syntaxes upside-down, so that
+ the last-defined one comes first, so that searching can stop at the
+ first match instead of always having to run through the entire list.
2016-03-09 Benno Schulenberg <bensberg@justemail.net>
* src/rcfile.c (parse_syntax): Produce an adequate error message
if (strcmp(sint->name, syntaxstr) == 0) {
openfile->syntax = sint;
openfile->colorstrings = sint->color;
+ break;
}
}
if (found_in_list(sint->extensions, fullname)) {
openfile->syntax = sint;
openfile->colorstrings = sint->color;
+ break;
}
}
if (found_in_list(sint->headers, openfile->fileage->data)) {
openfile->syntax = sint;
openfile->colorstrings = sint->color;
+ break;
}
}
}
if (found_in_list(sint->magics, magicstring)) {
openfile->syntax = sint;
openfile->colorstrings = sint->color;
+ break;
}
}
}
if (strcmp(sint->name, "default") == 0) {
openfile->syntax = sint;
openfile->colorstrings = sint->color;
+ break;
}
}
}
/* Whether we're allowed to add to the last syntax. When a file ends,
* or when a new syntax command is seen, this bool becomes FALSE. */
static syntaxtype *endsyntax = NULL;
- /* The end of the list of syntaxes. */
+ /* The syntax that is currently being parsed. */
static colortype *endcolor = NULL;
/* The end of the color list for the current syntax. */
#endif
return;
}
- if (syntaxes == NULL) {
- syntaxes = (syntaxtype *)nmalloc(sizeof(syntaxtype));
- endsyntax = syntaxes;
- } else {
- endsyntax->next = (syntaxtype *)nmalloc(sizeof(syntaxtype));
- endsyntax = endsyntax->next;
-#ifdef DEBUG
- fprintf(stderr, "Adding new syntax after first one\n");
-#endif
- }
-
+ /* Initialize a new syntax struct. */
+ endsyntax = (syntaxtype *)nmalloc(sizeof(syntaxtype));
endsyntax->name = mallocstrcpy(NULL, nameptr);
endsyntax->extensions = NULL;
endsyntax->headers = NULL;
endsyntax->color = NULL;
endcolor = NULL;
endsyntax->nmultis = 0;
- endsyntax->next = NULL;
+
+ /* Hook the new syntax in at the top of the list. */
+ endsyntax->next = syntaxes;
+ syntaxes = endsyntax;
opensyntax = TRUE;
char *buf = NULL;
ssize_t len;
size_t n = 0;
-#ifndef DISABLE_COLOR
- syntaxtype *end_syn_save = NULL;
-#endif
while ((len = getline(&buf, &n, rcstream)) > 0) {
char *ptr, *keyword, *option;
opensyntax = FALSE;
continue;
} else {
- end_syn_save = endsyntax;
endsyntax = sint;
opensyntax = TRUE;
keyword = ptr;
#ifndef DISABLE_COLOR
/* If we temporarily reset endsyntax to allow extending,
* restore the value here. */
- if (end_syn_save != NULL) {
- endsyntax = end_syn_save;
- end_syn_save = NULL;
+ if (endsyntax != syntaxes) {
+ endsyntax = syntaxes;
opensyntax = FALSE;
}
#endif