Commit 1d5134d9 authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

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
No related merge requests found
Showing with 40 additions and 18 deletions
+40 -18
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
* src/*.h, src/rcfile.c (parse_magictype, parse_headers): Rename them * src/*.h, src/rcfile.c (parse_magictype, parse_headers): Rename them
to parse_magic_exp() and parse_header_exp() to be more fitting, further to parse_magic_exp() and parse_header_exp() to be more fitting, further
symmetrify them, and improve some comments. 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 <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
......
...@@ -153,7 +153,7 @@ void color_update(void) ...@@ -153,7 +153,7 @@ void color_update(void)
syntaxtype *tmpsyntax; syntaxtype *tmpsyntax;
syntaxtype *defsyntax = NULL; syntaxtype *defsyntax = NULL;
colortype *tmpcolor, *defcolor = NULL; colortype *tmpcolor, *defcolor = NULL;
exttype *e; regexlisttype *e;
/* Var magicstring will stay NULL if we fail to get a magic result. */ /* Var magicstring will stay NULL if we fail to get a magic result. */
#ifdef HAVE_LIBMAGIC #ifdef HAVE_LIBMAGIC
......
...@@ -1624,8 +1624,7 @@ void thanks_for_all_the_fish(void) ...@@ -1624,8 +1624,7 @@ void thanks_for_all_the_fish(void)
free(syntaxes->desc); free(syntaxes->desc);
while (syntaxes->extensions != NULL) { while (syntaxes->extensions != NULL) {
exttype *bob = syntaxes->extensions; regexlisttype *bob = syntaxes->extensions;
syntaxes->extensions = bob->next; syntaxes->extensions = bob->next;
free(bob->ext_regex); free(bob->ext_regex);
if (bob->ext != NULL) { if (bob->ext != NULL) {
...@@ -1634,6 +1633,26 @@ void thanks_for_all_the_fish(void) ...@@ -1634,6 +1633,26 @@ void thanks_for_all_the_fish(void)
} }
free(bob); 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) { while (syntaxes->color != NULL) {
colortype *bob = syntaxes->color; colortype *bob = syntaxes->color;
......
...@@ -226,23 +226,23 @@ typedef struct colortype { ...@@ -226,23 +226,23 @@ typedef struct colortype {
/* Basic id for assigning to lines later. */ /* Basic id for assigning to lines later. */
} colortype; } colortype;
typedef struct exttype { typedef struct regexlisttype {
char *ext_regex; char *ext_regex;
/* The regexstrings for the things that match this syntax. */ /* The regexstrings for the things that match this syntax. */
regex_t *ext; regex_t *ext;
/* The compiled regexes. */ /* The compiled regexes. */
struct exttype *next; struct regexlisttype *next;
/* Next set of regexes. */ /* Next set of regexes. */
} exttype; } regexlisttype;
typedef struct syntaxtype { typedef struct syntaxtype {
char *desc; char *desc;
/* The name of this syntax. */ /* The name of this syntax. */
exttype *extensions; regexlisttype *extensions;
/* The list of extensions that this syntax applies to. */ /* The list of extensions that this syntax applies to. */
exttype *headers; regexlisttype *headers;
/* The list of headerlines that this syntax applies to. */ /* The list of headerlines that this syntax applies to. */
exttype *magics; regexlisttype *magics;
/* The list of libmagic results that this syntax applies to. */ /* The list of libmagic results that this syntax applies to. */
colortype *color; colortype *color;
/* The colors used in this syntax. */ /* The colors used in this syntax. */
......
...@@ -257,7 +257,7 @@ void parse_syntax(char *ptr) ...@@ -257,7 +257,7 @@ void parse_syntax(char *ptr)
{ {
const char *fileregptr = NULL, *nameptr = NULL; const char *fileregptr = NULL, *nameptr = NULL;
syntaxtype *tmpsyntax, *prev_syntax; syntaxtype *tmpsyntax, *prev_syntax;
exttype *endext = NULL; regexlisttype *endext = NULL;
/* The end of the extensions list for this syntax. */ /* The end of the extensions list for this syntax. */
assert(ptr != NULL); assert(ptr != NULL);
...@@ -346,7 +346,7 @@ void parse_syntax(char *ptr) ...@@ -346,7 +346,7 @@ void parse_syntax(char *ptr)
/* Now load the extension regexes into their part of the struct. */ /* Now load the extension regexes into their part of the struct. */
while (*ptr != '\0') { while (*ptr != '\0') {
exttype *newext; regexlisttype *newext;
while (*ptr != '"' && *ptr != '\0') while (*ptr != '"' && *ptr != '\0')
ptr++; ptr++;
...@@ -361,7 +361,7 @@ void parse_syntax(char *ptr) ...@@ -361,7 +361,7 @@ void parse_syntax(char *ptr)
if (ptr == NULL) if (ptr == NULL)
break; break;
newext = (exttype *)nmalloc(sizeof(exttype)); newext = (regexlisttype *)nmalloc(sizeof(regexlisttype));
/* Save the extension regex if it's valid. */ /* Save the extension regex if it's valid. */
if (nregcomp(fileregptr, REG_NOSUB)) { if (nregcomp(fileregptr, REG_NOSUB)) {
...@@ -383,7 +383,7 @@ void parse_syntax(char *ptr) ...@@ -383,7 +383,7 @@ void parse_syntax(char *ptr)
void parse_magic_exp(char *ptr) void parse_magic_exp(char *ptr)
{ {
#ifdef HAVE_LIBMAGIC #ifdef HAVE_LIBMAGIC
exttype *endmagic = NULL; regexlisttype *endmagic = NULL;
assert(ptr != NULL); assert(ptr != NULL);
...@@ -411,7 +411,7 @@ void parse_magic_exp(char *ptr) ...@@ -411,7 +411,7 @@ void parse_magic_exp(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') {
const char *regexstring; const char *regexstring;
exttype *newmagic; regexlisttype *newmagic;
while (*ptr != '"' && *ptr != '\0') while (*ptr != '"' && *ptr != '\0')
ptr++; ptr++;
...@@ -426,7 +426,7 @@ void parse_magic_exp(char *ptr) ...@@ -426,7 +426,7 @@ void parse_magic_exp(char *ptr)
if (ptr == NULL) if (ptr == NULL)
break; break;
newmagic = (exttype *)nmalloc(sizeof(exttype)); newmagic = (regexlisttype *)nmalloc(sizeof(regexlisttype));
/* Save the regex string if it's valid. */ /* Save the regex string if it's valid. */
if (nregcomp(regexstring, REG_NOSUB)) { if (nregcomp(regexstring, REG_NOSUB)) {
...@@ -876,7 +876,7 @@ bool parse_color_names(char *combostr, short *fg, short *bg, bool *bright) ...@@ -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. */ /* Parse the header-line regexes that may influence the choice of syntax. */
void parse_header_exp(char *ptr) void parse_header_exp(char *ptr)
{ {
exttype *endheader = NULL; regexlisttype *endheader = NULL;
assert(ptr != NULL); assert(ptr != NULL);
...@@ -893,7 +893,7 @@ void parse_header_exp(char *ptr) ...@@ -893,7 +893,7 @@ void parse_header_exp(char *ptr)
while (*ptr != '\0') { while (*ptr != '\0') {
const char *regexstring; const char *regexstring;
exttype *newheader; regexlisttype *newheader;
if (*ptr != '"') { if (*ptr != '"') {
rcfile_error( rcfile_error(
...@@ -909,7 +909,7 @@ void parse_header_exp(char *ptr) ...@@ -909,7 +909,7 @@ void parse_header_exp(char *ptr)
if (ptr == NULL) if (ptr == NULL)
break; break;
newheader = (exttype *)nmalloc(sizeof(exttype)); newheader = (regexlisttype *)nmalloc(sizeof(regexlisttype));
/* Save the regex string if it's valid */ /* Save the regex string if it's valid */
if (nregcomp(regexstring, 0)) { if (nregcomp(regexstring, 0)) {
......
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