Turning the linked list of syntaxes upside-down, so that the last-defined one

comes first, so that a search can stop at the first match instead of always
having to run through the entire list.


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5716 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
Benno Schulenberg 2016-03-10 20:06:01 +00:00
parent ed296525f4
commit 04262f09a4
3 changed files with 18 additions and 20 deletions

View File

@ -5,6 +5,10 @@
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

View File

@ -186,6 +186,7 @@ void color_update(void)
if (strcmp(sint->name, syntaxstr) == 0) {
openfile->syntax = sint;
openfile->colorstrings = sint->color;
break;
}
}
@ -216,6 +217,7 @@ void color_update(void)
if (found_in_list(sint->extensions, fullname)) {
openfile->syntax = sint;
openfile->colorstrings = sint->color;
break;
}
}
@ -231,6 +233,7 @@ void color_update(void)
if (found_in_list(sint->headers, openfile->fileage->data)) {
openfile->syntax = sint;
openfile->colorstrings = sint->color;
break;
}
}
}
@ -271,6 +274,7 @@ void color_update(void)
if (found_in_list(sint->magics, magicstring)) {
openfile->syntax = sint;
openfile->colorstrings = sint->color;
break;
}
}
}
@ -287,6 +291,7 @@ void color_update(void)
if (strcmp(sint->name, "default") == 0) {
openfile->syntax = sint;
openfile->colorstrings = sint->color;
break;
}
}
}

View File

@ -124,7 +124,7 @@ static bool opensyntax = FALSE;
/* 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
@ -298,17 +298,8 @@ void parse_syntax(char *ptr)
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;
@ -318,7 +309,10 @@ void parse_syntax(char *ptr)
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;
@ -928,9 +922,6 @@ void parse_rcfile(FILE *rcstream
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;
@ -973,7 +964,6 @@ void parse_rcfile(FILE *rcstream
opensyntax = FALSE;
continue;
} else {
end_syn_save = endsyntax;
endsyntax = sint;
opensyntax = TRUE;
keyword = ptr;
@ -1047,9 +1037,8 @@ void parse_rcfile(FILE *rcstream
#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