* 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.
+ * 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.
2014-05-10 Chris Allegretta <chrisa@asty.org>
* src/rcfile.c (parse_color_names): Redefine false and true to
typedef struct exttype {
char *ext_regex;
- /* The extensions that match this syntax. */
+ /* The regexstrings for the things that match this syntax. */
regex_t *ext;
- /* The compiled extensions that match this syntax. */
+ /* The compiled regexes. */
struct exttype *next;
- /* Next set of extensions. */
+ /* Next set of regexes. */
} exttype;
typedef struct syntaxtype {
exttype *extensions;
/* The list of extensions that this syntax applies to. */
exttype *headers;
- /* Regexes to match on the 'header' (1st line) of the file. */
+ /* The list of headerlines that this syntax applies to. */
exttype *magics;
- /* Regexes to match libmagic results. */
+ /* The list of libmagic results that this syntax applies to. */
colortype *color;
/* The colors used in this syntax. */
char *linter;
- /* Command to lint this type of file. */
+ /* The command to lint this type of file. */
int nmultis;
/* How many multi-line strings this syntax has. */
struct syntaxtype *next;
void do_prompt_abort(void);
int do_yesno_prompt(bool all, const char *msg);
-/* All functions in rcfile.c. */
+/* Most functions in rcfile.c. */
#ifndef DISABLE_NANORC
void rcfile_error(const char *msg, ...);
char *parse_next_word(char *ptr);
char *parse_next_regex(char *ptr);
bool nregcomp(const char *regex, int eflags);
void parse_syntax(char *ptr);
-void parse_magic_syntax(char *ptr);
void parse_include(char *ptr);
short color_to_short(const char *colorname, bool *bright);
void parse_colors(char *ptr, bool icase);
}
/* Parse the magic regexes that may influence the choice of syntax. */
-void parse_magictype(char *ptr)
+void parse_magic_exp(char *ptr)
{
#ifdef HAVE_LIBMAGIC
- const char *fileregptr = NULL;
exttype *endmagic = NULL;
assert(ptr != NULL);
/* Now load the magic regexes into their part of the struct. */
while (*ptr != '\0') {
+ const char *regexstring;
exttype *newmagic;
while (*ptr != '"' && *ptr != '\0')
ptr++;
- fileregptr = ptr;
+ regexstring = ptr;
ptr = parse_next_regex(ptr);
if (ptr == NULL)
break;
newmagic = (exttype *)nmalloc(sizeof(exttype));
/* Save the regex string if it's valid. */
- if (nregcomp(fileregptr, REG_NOSUB)) {
- newmagic->ext_regex = mallocstrcpy(NULL, fileregptr);
+ if (nregcomp(regexstring, REG_NOSUB)) {
+ newmagic->ext_regex = mallocstrcpy(NULL, regexstring);
newmagic->ext = NULL;
if (endmagic == NULL)
}
/* Parse the header-line regexes that may influence the choice of syntax. */
-void parse_headers(char *ptr)
+void parse_header_exp(char *ptr)
{
- char *regstr;
exttype *endheader = NULL;
assert(ptr != NULL);
return;
}
- while (ptr != NULL && *ptr != '\0') {
+ while (*ptr != '\0') {
+ const char *regexstring;
exttype *newheader;
if (*ptr != '"') {
ptr++;
- regstr = ptr;
+ regexstring = ptr;
ptr = parse_next_regex(ptr);
if (ptr == NULL)
break;
newheader = (exttype *)nmalloc(sizeof(exttype));
/* Save the regex string if it's valid */
- if (nregcomp(regstr, 0)) {
- newheader->ext_regex = mallocstrcpy(NULL, regstr);
+ if (nregcomp(regexstring, 0)) {
+ newheader->ext_regex = mallocstrcpy(NULL, regexstring);
newheader->ext = NULL;
if (endheader == NULL)
parse_syntax(ptr);
}
else if (strcasecmp(keyword, "magic") == 0)
- parse_magictype(ptr);
+ parse_magic_exp(ptr);
else if (strcasecmp(keyword, "header") == 0)
- parse_headers(ptr);
+ parse_header_exp(ptr);
else if (strcasecmp(keyword, "color") == 0)
parse_colors(ptr, FALSE);
else if (strcasecmp(keyword, "icolor") == 0)