Commit cf4f80da authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

Renaming and symmetrifying two functions, and improving some comments.

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4861 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
parent 8e01293b
Showing with 23 additions and 21 deletions
+23 -21
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
* src/rcfile.c (parse_magictype, parse_headers): Handle the libmagic * src/rcfile.c (parse_magictype, parse_headers): Handle the libmagic
and headerline regexes in the same manner, eliding a static variable and headerline regexes in the same manner, eliding a static variable
while renaming some others. 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> 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
......
...@@ -228,11 +228,11 @@ typedef struct colortype { ...@@ -228,11 +228,11 @@ typedef struct colortype {
typedef struct exttype { typedef struct exttype {
char *ext_regex; char *ext_regex;
/* The extensions that match this syntax. */ /* The regexstrings for the things that match this syntax. */
regex_t *ext; regex_t *ext;
/* The compiled extensions that match this syntax. */ /* The compiled regexes. */
struct exttype *next; struct exttype *next;
/* Next set of extensions. */ /* Next set of regexes. */
} exttype; } exttype;
typedef struct syntaxtype { typedef struct syntaxtype {
...@@ -241,13 +241,13 @@ typedef struct syntaxtype { ...@@ -241,13 +241,13 @@ typedef struct syntaxtype {
exttype *extensions; exttype *extensions;
/* The list of extensions that this syntax applies to. */ /* The list of extensions that this syntax applies to. */
exttype *headers; exttype *headers;
/* Regexes to match on the 'header' (1st line) of the file. */ /* The list of headerlines that this syntax applies to. */
exttype *magics; exttype *magics;
/* Regexes to match libmagic results. */ /* 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. */
char *linter; char *linter;
/* Command to lint this type of file. */ /* The command to lint this type of file. */
int nmultis; int nmultis;
/* How many multi-line strings this syntax has. */ /* How many multi-line strings this syntax has. */
struct syntaxtype *next; struct syntaxtype *next;
......
...@@ -542,7 +542,7 @@ int do_prompt(bool allow_tabs, ...@@ -542,7 +542,7 @@ int do_prompt(bool allow_tabs,
void do_prompt_abort(void); void do_prompt_abort(void);
int do_yesno_prompt(bool all, const char *msg); int do_yesno_prompt(bool all, const char *msg);
/* All functions in rcfile.c. */ /* Most functions in rcfile.c. */
#ifndef DISABLE_NANORC #ifndef DISABLE_NANORC
void rcfile_error(const char *msg, ...); void rcfile_error(const char *msg, ...);
char *parse_next_word(char *ptr); char *parse_next_word(char *ptr);
...@@ -551,7 +551,6 @@ char *parse_argument(char *ptr); ...@@ -551,7 +551,6 @@ char *parse_argument(char *ptr);
char *parse_next_regex(char *ptr); char *parse_next_regex(char *ptr);
bool nregcomp(const char *regex, int eflags); bool nregcomp(const char *regex, int eflags);
void parse_syntax(char *ptr); void parse_syntax(char *ptr);
void parse_magic_syntax(char *ptr);
void parse_include(char *ptr); void parse_include(char *ptr);
short color_to_short(const char *colorname, bool *bright); short color_to_short(const char *colorname, bool *bright);
void parse_colors(char *ptr, bool icase); void parse_colors(char *ptr, bool icase);
......
...@@ -380,10 +380,9 @@ void parse_syntax(char *ptr) ...@@ -380,10 +380,9 @@ void parse_syntax(char *ptr)
} }
/* Parse the magic regexes that may influence the choice of syntax. */ /* 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 #ifdef HAVE_LIBMAGIC
const char *fileregptr = NULL;
exttype *endmagic = NULL; exttype *endmagic = NULL;
assert(ptr != NULL); assert(ptr != NULL);
...@@ -411,6 +410,7 @@ void parse_magictype(char *ptr) ...@@ -411,6 +410,7 @@ void parse_magictype(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;
exttype *newmagic; exttype *newmagic;
while (*ptr != '"' && *ptr != '\0') while (*ptr != '"' && *ptr != '\0')
...@@ -421,7 +421,7 @@ void parse_magictype(char *ptr) ...@@ -421,7 +421,7 @@ void parse_magictype(char *ptr)
ptr++; ptr++;
fileregptr = ptr; regexstring = ptr;
ptr = parse_next_regex(ptr); ptr = parse_next_regex(ptr);
if (ptr == NULL) if (ptr == NULL)
break; break;
...@@ -429,8 +429,8 @@ void parse_magictype(char *ptr) ...@@ -429,8 +429,8 @@ void parse_magictype(char *ptr)
newmagic = (exttype *)nmalloc(sizeof(exttype)); newmagic = (exttype *)nmalloc(sizeof(exttype));
/* Save the regex string if it's valid. */ /* Save the regex string if it's valid. */
if (nregcomp(fileregptr, REG_NOSUB)) { if (nregcomp(regexstring, REG_NOSUB)) {
newmagic->ext_regex = mallocstrcpy(NULL, fileregptr); newmagic->ext_regex = mallocstrcpy(NULL, regexstring);
newmagic->ext = NULL; newmagic->ext = NULL;
if (endmagic == NULL) if (endmagic == NULL)
...@@ -874,9 +874,8 @@ bool parse_color_names(char *combostr, short *fg, short *bg, bool *bright) ...@@ -874,9 +874,8 @@ 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_headers(char *ptr) void parse_header_exp(char *ptr)
{ {
char *regstr;
exttype *endheader = NULL; exttype *endheader = NULL;
assert(ptr != NULL); assert(ptr != NULL);
...@@ -892,7 +891,8 @@ void parse_headers(char *ptr) ...@@ -892,7 +891,8 @@ void parse_headers(char *ptr)
return; return;
} }
while (ptr != NULL && *ptr != '\0') { while (*ptr != '\0') {
const char *regexstring;
exttype *newheader; exttype *newheader;
if (*ptr != '"') { if (*ptr != '"') {
...@@ -904,7 +904,7 @@ void parse_headers(char *ptr) ...@@ -904,7 +904,7 @@ void parse_headers(char *ptr)
ptr++; ptr++;
regstr = ptr; regexstring = ptr;
ptr = parse_next_regex(ptr); ptr = parse_next_regex(ptr);
if (ptr == NULL) if (ptr == NULL)
break; break;
...@@ -912,8 +912,8 @@ void parse_headers(char *ptr) ...@@ -912,8 +912,8 @@ void parse_headers(char *ptr)
newheader = (exttype *)nmalloc(sizeof(exttype)); newheader = (exttype *)nmalloc(sizeof(exttype));
/* Save the regex string if it's valid */ /* Save the regex string if it's valid */
if (nregcomp(regstr, 0)) { if (nregcomp(regexstring, 0)) {
newheader->ext_regex = mallocstrcpy(NULL, regstr); newheader->ext_regex = mallocstrcpy(NULL, regexstring);
newheader->ext = NULL; newheader->ext = NULL;
if (endheader == NULL) if (endheader == NULL)
...@@ -1078,9 +1078,9 @@ void parse_rcfile(FILE *rcstream ...@@ -1078,9 +1078,9 @@ void parse_rcfile(FILE *rcstream
parse_syntax(ptr); parse_syntax(ptr);
} }
else if (strcasecmp(keyword, "magic") == 0) else if (strcasecmp(keyword, "magic") == 0)
parse_magictype(ptr); parse_magic_exp(ptr);
else if (strcasecmp(keyword, "header") == 0) else if (strcasecmp(keyword, "header") == 0)
parse_headers(ptr); parse_header_exp(ptr);
else if (strcasecmp(keyword, "color") == 0) else if (strcasecmp(keyword, "color") == 0)
parse_colors(ptr, FALSE); parse_colors(ptr, FALSE);
else if (strcasecmp(keyword, "icolor") == 0) else if (strcasecmp(keyword, "icolor") == 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