From 1d5134d93e799820afcb91e1f84371a7d4b6f0dd Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Mon, 12 May 2014 14:31:54 +0000 Subject: [PATCH] Renaming the struct type 'exttype' to 'regexlisttype', and upon exit also freeing the regexes for libmagic results and headerlines. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4862 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 3 +++ src/color.c | 2 +- src/global.c | 23 +++++++++++++++++++++-- src/nano.h | 12 ++++++------ src/rcfile.c | 18 +++++++++--------- 5 files changed, 40 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 488ce533..21e0251d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,9 @@ * src/*.h, src/rcfile.c (parse_magictype, parse_headers): Rename them to parse_magic_exp() and parse_header_exp() to be more fitting, further symmetrify them, and improve some comments. + * src/nano.h, src/color.c, src/global.c, src/rcfile.c: Rename struct + type 'exttype' to 'regexlisttype', to better match its functions, and + upon exit also free the regexes for libmagic results and headerlines. 2014-05-10 Chris Allegretta * src/rcfile.c (parse_color_names): Redefine false and true to diff --git a/src/color.c b/src/color.c index e5d38588..41a5c094 100644 --- a/src/color.c +++ b/src/color.c @@ -153,7 +153,7 @@ void color_update(void) syntaxtype *tmpsyntax; syntaxtype *defsyntax = NULL; colortype *tmpcolor, *defcolor = NULL; - exttype *e; + regexlisttype *e; /* Var magicstring will stay NULL if we fail to get a magic result. */ #ifdef HAVE_LIBMAGIC diff --git a/src/global.c b/src/global.c index c0ee1a2d..6430c343 100644 --- a/src/global.c +++ b/src/global.c @@ -1624,8 +1624,7 @@ void thanks_for_all_the_fish(void) free(syntaxes->desc); while (syntaxes->extensions != NULL) { - exttype *bob = syntaxes->extensions; - + regexlisttype *bob = syntaxes->extensions; syntaxes->extensions = bob->next; free(bob->ext_regex); if (bob->ext != NULL) { @@ -1634,6 +1633,26 @@ void thanks_for_all_the_fish(void) } free(bob); } + while (syntaxes->headers != NULL) { + regexlisttype *bob = syntaxes->headers; + syntaxes->headers = bob->next; + free(bob->ext_regex); + if (bob->ext != NULL) { + regfree(bob->ext); + free(bob->ext); + } + free(bob); + } + while (syntaxes->magics != NULL) { + regexlisttype *bob = syntaxes->magics; + syntaxes->magics = bob->next; + free(bob->ext_regex); + if (bob->ext != NULL) { + regfree(bob->ext); + free(bob->ext); + } + free(bob); + } while (syntaxes->color != NULL) { colortype *bob = syntaxes->color; diff --git a/src/nano.h b/src/nano.h index 1724970e..07336b50 100644 --- a/src/nano.h +++ b/src/nano.h @@ -226,23 +226,23 @@ typedef struct colortype { /* Basic id for assigning to lines later. */ } colortype; -typedef struct exttype { +typedef struct regexlisttype { char *ext_regex; /* The regexstrings for the things that match this syntax. */ regex_t *ext; /* The compiled regexes. */ - struct exttype *next; + struct regexlisttype *next; /* Next set of regexes. */ -} exttype; +} regexlisttype; typedef struct syntaxtype { char *desc; /* The name of this syntax. */ - exttype *extensions; + regexlisttype *extensions; /* The list of extensions that this syntax applies to. */ - exttype *headers; + regexlisttype *headers; /* The list of headerlines that this syntax applies to. */ - exttype *magics; + regexlisttype *magics; /* The list of libmagic results that this syntax applies to. */ colortype *color; /* The colors used in this syntax. */ diff --git a/src/rcfile.c b/src/rcfile.c index bef5909e..28004913 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -257,7 +257,7 @@ void parse_syntax(char *ptr) { const char *fileregptr = NULL, *nameptr = NULL; syntaxtype *tmpsyntax, *prev_syntax; - exttype *endext = NULL; + regexlisttype *endext = NULL; /* The end of the extensions list for this syntax. */ assert(ptr != NULL); @@ -346,7 +346,7 @@ void parse_syntax(char *ptr) /* Now load the extension regexes into their part of the struct. */ while (*ptr != '\0') { - exttype *newext; + regexlisttype *newext; while (*ptr != '"' && *ptr != '\0') ptr++; @@ -361,7 +361,7 @@ void parse_syntax(char *ptr) if (ptr == NULL) break; - newext = (exttype *)nmalloc(sizeof(exttype)); + newext = (regexlisttype *)nmalloc(sizeof(regexlisttype)); /* Save the extension regex if it's valid. */ if (nregcomp(fileregptr, REG_NOSUB)) { @@ -383,7 +383,7 @@ void parse_syntax(char *ptr) void parse_magic_exp(char *ptr) { #ifdef HAVE_LIBMAGIC - exttype *endmagic = NULL; + regexlisttype *endmagic = NULL; assert(ptr != NULL); @@ -411,7 +411,7 @@ void parse_magic_exp(char *ptr) /* Now load the magic regexes into their part of the struct. */ while (*ptr != '\0') { const char *regexstring; - exttype *newmagic; + regexlisttype *newmagic; while (*ptr != '"' && *ptr != '\0') ptr++; @@ -426,7 +426,7 @@ void parse_magic_exp(char *ptr) if (ptr == NULL) break; - newmagic = (exttype *)nmalloc(sizeof(exttype)); + newmagic = (regexlisttype *)nmalloc(sizeof(regexlisttype)); /* Save the regex string if it's valid. */ if (nregcomp(regexstring, REG_NOSUB)) { @@ -876,7 +876,7 @@ bool parse_color_names(char *combostr, short *fg, short *bg, bool *bright) /* Parse the header-line regexes that may influence the choice of syntax. */ void parse_header_exp(char *ptr) { - exttype *endheader = NULL; + regexlisttype *endheader = NULL; assert(ptr != NULL); @@ -893,7 +893,7 @@ void parse_header_exp(char *ptr) while (*ptr != '\0') { const char *regexstring; - exttype *newheader; + regexlisttype *newheader; if (*ptr != '"') { rcfile_error( @@ -909,7 +909,7 @@ void parse_header_exp(char *ptr) if (ptr == NULL) break; - newheader = (exttype *)nmalloc(sizeof(exttype)); + newheader = (regexlisttype *)nmalloc(sizeof(regexlisttype)); /* Save the regex string if it's valid */ if (nregcomp(regexstring, 0)) { -- 2.39.5