From: Benno Schulenberg Date: Wed, 14 May 2014 10:09:42 +0000 (+0000) Subject: Moving the magic check to after the headerline check. X-Git-Tag: v2.3.3~47 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=f9375267c7eb2d492aba05315db165aaf1a6e086;p=nano.git 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 --- diff --git a/ChangeLog b/ChangeLog index 3ce987da..748a61d4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 * src/text.c (do_linter): Make an error message somewhat clearer. diff --git a/src/color.c b/src/color.c index f064fae1..af4261d2 100644 --- a/src/color.c +++ b/src/color.c @@ -249,25 +249,27 @@ 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"); + fprintf(stderr, "No result from file extension, trying headerline...\n"); #endif for (tmpsyntax = syntaxes; tmpsyntax != NULL; tmpsyntax = tmpsyntax->next) { - for (e = tmpsyntax->magics; e != NULL; e = e->next) { + + for (e = tmpsyntax->headers; 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); + fprintf(stderr, "Comparing header regex \"%s\" to fileage \"%s\"...\n", + e->ext_regex, openfile->fileage->data); #endif - /* Set colorstrings if we match the magic-string regex. */ - if (magicstring && regexec(e->ext, magicstring, 0, NULL, 0) == 0) { + /* Set colorstrings if we match the header-line regex. */ + if (regexec(e->ext, openfile->fileage->data, 0, NULL, 0) == 0) { openfile->syntax = tmpsyntax; openfile->colorstrings = tmpsyntax->color; break; @@ -278,17 +280,17 @@ void color_update(void) } } } -#endif /* HAVE_LIBMAGIC */ - /* If we haven't matched anything yet, try the headers. */ +#ifdef HAVE_LIBMAGIC + /* Check magic if we don't have an answer yet. */ if (openfile->colorstrings == NULL) { #ifdef DEBUG - fprintf(stderr, "No match for file extensions, looking at headers...\n"); + fprintf(stderr, "No result from headerline either, trying libmagic...\n"); #endif for (tmpsyntax = syntaxes; tmpsyntax != NULL; tmpsyntax = tmpsyntax->next) { - for (e = tmpsyntax->headers; e != NULL; e = e->next) { + for (e = tmpsyntax->magics; e != NULL; e = e->next) { bool not_compiled = (e->ext == NULL); if (not_compiled) { @@ -296,11 +298,10 @@ void color_update(void) regcomp(e->ext, fixbounds(e->ext_regex), REG_EXTENDED); } #ifdef DEBUG - fprintf(stderr, "Comparing header regex \"%s\" to fileage \"%s\"...\n", - e->ext_regex, openfile->fileage->data); + fprintf(stderr, "Matching regex \"%s\" against \"%s\"\n", e->ext_regex, magicstring); #endif - /* Set colorstrings if we match the header-line regex. */ - if (regexec(e->ext, openfile->fileage->data, 0, NULL, 0) == 0) { + /* 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; @@ -311,6 +312,7 @@ void color_update(void) } } } +#endif /* HAVE_LIBMAGIC */ } /* If we didn't find any syntax yet, and we do have a default one,