Moving the magic check to after the headerline check.

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4883 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
Benno Schulenberg 2014-05-14 10:09:42 +00:00
parent ee4e67aa1f
commit f9375267c7
2 changed files with 36 additions and 33 deletions

View File

@ -4,6 +4,7 @@
two-column characters properly. This fixes Savannah bug #31743.
* src/nano.c (precalc_multicolorinfo): Improve debugging messages,
and remove superfluous assignment (fileptr already equals endptr).
* src/color.c (color_update): Move magic check to after headerline.
2014-05-13 Benno Schulenberg <bensberg@justemail.net>
* src/text.c (do_linter): Make an error message somewhat clearer.

View File

@ -249,41 +249,10 @@ void color_update(void)
}
}
#ifdef HAVE_LIBMAGIC
/* Check magic if we don't have an answer yet. */
/* Check the headerline if the extension didn't match anything. */
if (openfile->colorstrings == NULL) {
#ifdef DEBUG
fprintf(stderr, "No match using extension, trying libmagic...\n");
#endif
for (tmpsyntax = syntaxes; tmpsyntax != NULL;
tmpsyntax = tmpsyntax->next) {
for (e = tmpsyntax->magics; e != NULL; e = e->next) {
bool not_compiled = (e->ext == NULL);
if (not_compiled) {
e->ext = (regex_t *)nmalloc(sizeof(regex_t));
regcomp(e->ext, fixbounds(e->ext_regex), REG_EXTENDED);
}
#ifdef DEBUG
fprintf(stderr, "Matching regex \"%s\" against \"%s\"\n", e->ext_regex, magicstring);
#endif
/* Set colorstrings if we match the magic-string regex. */
if (magicstring && regexec(e->ext, magicstring, 0, NULL, 0) == 0) {
openfile->syntax = tmpsyntax;
openfile->colorstrings = tmpsyntax->color;
break;
}
if (not_compiled)
nfreeregex(&e->ext);
}
}
}
#endif /* HAVE_LIBMAGIC */
/* If we haven't matched anything yet, try the headers. */
if (openfile->colorstrings == NULL) {
#ifdef DEBUG
fprintf(stderr, "No match for file extensions, looking at headers...\n");
fprintf(stderr, "No result from file extension, trying headerline...\n");
#endif
for (tmpsyntax = syntaxes; tmpsyntax != NULL;
tmpsyntax = tmpsyntax->next) {
@ -311,6 +280,39 @@ void color_update(void)
}
}
}
#ifdef HAVE_LIBMAGIC
/* Check magic if we don't have an answer yet. */
if (openfile->colorstrings == NULL) {
#ifdef DEBUG
fprintf(stderr, "No result from headerline either, trying libmagic...\n");
#endif
for (tmpsyntax = syntaxes; tmpsyntax != NULL;
tmpsyntax = tmpsyntax->next) {
for (e = tmpsyntax->magics; e != NULL; e = e->next) {
bool not_compiled = (e->ext == NULL);
if (not_compiled) {
e->ext = (regex_t *)nmalloc(sizeof(regex_t));
regcomp(e->ext, fixbounds(e->ext_regex), REG_EXTENDED);
}
#ifdef DEBUG
fprintf(stderr, "Matching regex \"%s\" against \"%s\"\n", e->ext_regex, magicstring);
#endif
/* Set colorstrings if we match the magic-string regex. */
if (magicstring && regexec(e->ext, magicstring, 0, NULL, 0) == 0) {
openfile->syntax = tmpsyntax;
openfile->colorstrings = tmpsyntax->color;
break;
}
if (not_compiled)
nfreeregex(&e->ext);
}
}
}
#endif /* HAVE_LIBMAGIC */
}
/* If we didn't find any syntax yet, and we do have a default one,