* 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 <chrisa@asty.org>
* src/rcfile.c (parse_color_names): Redefine false and true to
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
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) {
}
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;
/* 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. */
{
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);
/* Now load the extension regexes into their part of the struct. */
while (*ptr != '\0') {
- exttype *newext;
+ regexlisttype *newext;
while (*ptr != '"' && *ptr != '\0')
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)) {
void parse_magic_exp(char *ptr)
{
#ifdef HAVE_LIBMAGIC
- exttype *endmagic = NULL;
+ regexlisttype *endmagic = NULL;
assert(ptr != NULL);
/* 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++;
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)) {
/* 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);
while (*ptr != '\0') {
const char *regexstring;
- exttype *newheader;
+ regexlisttype *newheader;
if (*ptr != '"') {
rcfile_error(
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)) {