Commit f9375267 authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

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
No related merge requests found
Showing with 18 additions and 15 deletions
+18 -15
......@@ -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.
......
......@@ -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,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment