Handling the libmagic and headerline regexes in the same manner.

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4860 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Benno Schulenberg 2014-05-12 12:57:00 +00:00
parent d2892ad396
commit 8e01293b34
2 changed files with 19 additions and 24 deletions

View File

@ -4,6 +4,9 @@
* src/rcfile.c: Improve some comments, and remove some others that * src/rcfile.c: Improve some comments, and remove some others that
are mispasted or superfluous. are mispasted or superfluous.
* doc/texinfo/nano.texi: Add missing parenthesis, remove blank line. * doc/texinfo/nano.texi: Add missing parenthesis, remove blank line.
* src/rcfile.c (parse_magictype, parse_headers): Handle the libmagic
and headerline regexes in the same manner, eliding a static variable
while renaming some others.
2014-05-10 Chris Allegretta <chrisa@asty.org> 2014-05-10 Chris Allegretta <chrisa@asty.org>
* src/rcfile.c (parse_color_names): Redefine false and true to * src/rcfile.c (parse_color_names): Redefine false and true to

View File

@ -118,8 +118,6 @@ static char *nanorc = NULL;
#ifndef DISABLE_COLOR #ifndef DISABLE_COLOR
static syntaxtype *endsyntax = NULL; static syntaxtype *endsyntax = NULL;
/* The end of the list of syntaxes. */ /* The end of the list of syntaxes. */
static exttype *endheader = NULL;
/* End of header list. */
static colortype *endcolor = NULL; static colortype *endcolor = NULL;
/* The end of the color list for the current syntax. */ /* The end of the color list for the current syntax. */
#endif #endif
@ -321,7 +319,6 @@ void parse_syntax(char *ptr)
endsyntax->desc = mallocstrcpy(NULL, nameptr); endsyntax->desc = mallocstrcpy(NULL, nameptr);
endsyntax->color = NULL; endsyntax->color = NULL;
endcolor = NULL; endcolor = NULL;
endheader = NULL;
endsyntax->extensions = NULL; endsyntax->extensions = NULL;
endsyntax->headers = NULL; endsyntax->headers = NULL;
endsyntax->magics = NULL; endsyntax->magics = NULL;
@ -387,7 +384,7 @@ void parse_magictype(char *ptr)
{ {
#ifdef HAVE_LIBMAGIC #ifdef HAVE_LIBMAGIC
const char *fileregptr = NULL; const char *fileregptr = NULL;
exttype *endext = NULL; exttype *endmagic = NULL;
assert(ptr != NULL); assert(ptr != NULL);
@ -414,7 +411,7 @@ void parse_magictype(char *ptr)
/* Now load the magic regexes into their part of the struct. */ /* Now load the magic regexes into their part of the struct. */
while (*ptr != '\0') { while (*ptr != '\0') {
exttype *newext; exttype *newmagic;
while (*ptr != '"' && *ptr != '\0') while (*ptr != '"' && *ptr != '\0')
ptr++; ptr++;
@ -429,21 +426,21 @@ void parse_magictype(char *ptr)
if (ptr == NULL) if (ptr == NULL)
break; break;
newext = (exttype *)nmalloc(sizeof(exttype)); newmagic = (exttype *)nmalloc(sizeof(exttype));
/* Save the regex if it's valid. */ /* Save the regex string if it's valid. */
if (nregcomp(fileregptr, REG_NOSUB)) { if (nregcomp(fileregptr, REG_NOSUB)) {
newext->ext_regex = mallocstrcpy(NULL, fileregptr); newmagic->ext_regex = mallocstrcpy(NULL, fileregptr);
newext->ext = NULL; newmagic->ext = NULL;
if (endext == NULL) if (endmagic == NULL)
endsyntax->magics = newext; endsyntax->magics = newmagic;
else else
endext->next = newext; endmagic->next = newmagic;
endext = newext; endmagic = newmagic;
endext->next = NULL; endmagic->next = NULL;
} else } else
free(newext); free(newmagic);
} }
#endif /* HAVE_LIBMAGIC */ #endif /* HAVE_LIBMAGIC */
} }
@ -880,6 +877,7 @@ bool parse_color_names(char *combostr, short *fg, short *bg, bool *bright)
void parse_headers(char *ptr) void parse_headers(char *ptr)
{ {
char *regstr; char *regstr;
exttype *endheader = NULL;
assert(ptr != NULL); assert(ptr != NULL);
@ -917,19 +915,13 @@ void parse_headers(char *ptr)
if (nregcomp(regstr, 0)) { if (nregcomp(regstr, 0)) {
newheader->ext_regex = mallocstrcpy(NULL, regstr); newheader->ext_regex = mallocstrcpy(NULL, regstr);
newheader->ext = NULL; newheader->ext = NULL;
newheader->next = NULL;
#ifdef DEBUG if (endheader == NULL)
fprintf(stderr, "Starting a new header entry: %s\n", newheader->ext_regex);
#endif
if (endheader == NULL) {
endsyntax->headers = newheader; endsyntax->headers = newheader;
} else { else
endheader->next = newheader; endheader->next = newheader;
}
endheader = newheader; endheader = newheader;
endheader->next = NULL;
} else } else
free(newheader); free(newheader);
} }