From 8e01293b3453228eaedc2772de4670be49f21952 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Mon, 12 May 2014 12:57:00 +0000 Subject: [PATCH] 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 --- ChangeLog | 3 +++ src/rcfile.c | 40 ++++++++++++++++------------------------ 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index c2b83f51..35d4dac7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,9 @@ * src/rcfile.c: Improve some comments, and remove some others that are mispasted or superfluous. * 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 * src/rcfile.c (parse_color_names): Redefine false and true to diff --git a/src/rcfile.c b/src/rcfile.c index ce654050..9b6ab7e8 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -118,8 +118,6 @@ static char *nanorc = NULL; #ifndef DISABLE_COLOR static syntaxtype *endsyntax = NULL; /* The end of the list of syntaxes. */ -static exttype *endheader = NULL; - /* End of header list. */ static colortype *endcolor = NULL; /* The end of the color list for the current syntax. */ #endif @@ -321,7 +319,6 @@ void parse_syntax(char *ptr) endsyntax->desc = mallocstrcpy(NULL, nameptr); endsyntax->color = NULL; endcolor = NULL; - endheader = NULL; endsyntax->extensions = NULL; endsyntax->headers = NULL; endsyntax->magics = NULL; @@ -387,7 +384,7 @@ void parse_magictype(char *ptr) { #ifdef HAVE_LIBMAGIC const char *fileregptr = NULL; - exttype *endext = NULL; + exttype *endmagic = NULL; assert(ptr != NULL); @@ -414,7 +411,7 @@ void parse_magictype(char *ptr) /* Now load the magic regexes into their part of the struct. */ while (*ptr != '\0') { - exttype *newext; + exttype *newmagic; while (*ptr != '"' && *ptr != '\0') ptr++; @@ -429,21 +426,21 @@ void parse_magictype(char *ptr) if (ptr == NULL) 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)) { - newext->ext_regex = mallocstrcpy(NULL, fileregptr); - newext->ext = NULL; + newmagic->ext_regex = mallocstrcpy(NULL, fileregptr); + newmagic->ext = NULL; - if (endext == NULL) - endsyntax->magics = newext; + if (endmagic == NULL) + endsyntax->magics = newmagic; else - endext->next = newext; - endext = newext; - endext->next = NULL; + endmagic->next = newmagic; + endmagic = newmagic; + endmagic->next = NULL; } else - free(newext); + free(newmagic); } #endif /* HAVE_LIBMAGIC */ } @@ -880,6 +877,7 @@ bool parse_color_names(char *combostr, short *fg, short *bg, bool *bright) void parse_headers(char *ptr) { char *regstr; + exttype *endheader = NULL; assert(ptr != NULL); @@ -917,19 +915,13 @@ void parse_headers(char *ptr) if (nregcomp(regstr, 0)) { newheader->ext_regex = mallocstrcpy(NULL, regstr); newheader->ext = NULL; - newheader->next = NULL; -#ifdef DEBUG - fprintf(stderr, "Starting a new header entry: %s\n", newheader->ext_regex); -#endif - - if (endheader == NULL) { + if (endheader == NULL) endsyntax->headers = newheader; - } else { + else endheader->next = newheader; - } - endheader = newheader; + endheader->next = NULL; } else free(newheader); }