diff --git a/ChangeLog b/ChangeLog index ea7e65a1b1b6c97384c8725243f954b38cf508b3..9ba4ccb1a8e1b451f1f79ca511e97248b88ad3a7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ * src/search.c (regexp_init): Allow using the word boundary markers \< and \> in search strings on non-GNU systems. This is a partial fix for Savannah bug #47325 reported by Thomas Rosenau. + * src/rcfile.c (parse_rcfile, parse_colors, nregcomp): Combine the + regular-expression flags at compile time instead of at run time. 2016-03-13 Thomas Rosenau <thomasr@fantasymail.de> (tiny change) * autogen.sh, README.SVN: Mention SVN instead of CVS. diff --git a/src/color.c b/src/color.c index 388ef137e68bda22b1bd733d6e49473e653853bf..bbf1f85ddae30f4192a098cf4003d287e4d82e93 100644 --- a/src/color.c +++ b/src/color.c @@ -283,14 +283,12 @@ void color_update(void) for (ink = sint->color; ink != NULL; ink = ink->next) { if (ink->start == NULL) { ink->start = (regex_t *)nmalloc(sizeof(regex_t)); - regcomp(ink->start, fixbounds(ink->start_regex), - REG_EXTENDED | (ink->icase ? REG_ICASE : 0)); + regcomp(ink->start, fixbounds(ink->start_regex), ink->rex_flags); } if (ink->end_regex != NULL && ink->end == NULL) { ink->end = (regex_t *)nmalloc(sizeof(regex_t)); - regcomp(ink->end, fixbounds(ink->end_regex), - REG_EXTENDED | (ink->icase ? REG_ICASE : 0)); + regcomp(ink->end, fixbounds(ink->end_regex), ink->rex_flags); } } } diff --git a/src/nano.h b/src/nano.h index 990cc238193d159edee51cf92ad16895bf013d39..138cf0b5070e3a0bb31e9c36e3f80ed4f4b643be 100644 --- a/src/nano.h +++ b/src/nano.h @@ -209,11 +209,11 @@ typedef struct colortype { /* This syntax's background color. */ bool bright; /* Is this color A_BOLD? */ - bool icase; - /* Is this regex string case insensitive? */ int pairnum; /* The color pair number used for this foreground color and * background color. */ + int rex_flags; + /* The regex compilation flags (with or without REG_ICASE). */ char *start_regex; /* The start (or all) of the regex string. */ regex_t *start; diff --git a/src/proto.h b/src/proto.h index 1090db4513e70ca9ef2ab49385a1c693a059101b..8af1bebbfd724bcecce0cec2c5787bedf1587671 100644 --- a/src/proto.h +++ b/src/proto.h @@ -561,11 +561,9 @@ void rcfile_error(const char *msg, ...); char *parse_argument(char *ptr); #ifndef DISABLE_COLOR char *parse_next_regex(char *ptr); -bool nregcomp(const char *regex, int eflags); void parse_syntax(char *ptr); void parse_includes(char *ptr); short color_to_short(const char *colorname, bool *bright); -void parse_colors(char *ptr, bool icase); bool parse_color_names(char *combostr, short *fg, short *bg, bool *bright); void grab_and_store(const char *kind, char *ptr, regexlisttype **storage); #endif diff --git a/src/rcfile.c b/src/rcfile.c index 26bd0fea36a9a1a42e15e925c080613999316014..376368604be038886471d0baa0535e04acab1c11 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -244,11 +244,11 @@ char *parse_next_regex(char *ptr) /* Compile the regular expression regex to see if it's valid. Return * TRUE if it is, and FALSE otherwise. */ -bool nregcomp(const char *regex, int eflags) +bool nregcomp(const char *regex, int compile_flags) { regex_t preg; const char *r = fixbounds(regex); - int rc = regcomp(&preg, r, REG_EXTENDED | eflags); + int rc = regcomp(&preg, r, compile_flags); if (rc != 0) { size_t len = regerror(rc, &preg, NULL, 0); @@ -622,9 +622,9 @@ short color_to_short(const char *colorname, bool *bright) } /* Parse the color string in the line at ptr, and add it to the current - * file's associated colors. If icase is TRUE, treat the color string - * as case insensitive. */ -void parse_colors(char *ptr, bool icase) + * file's associated colors. rex_flags are the regex compilation flags + * to use, excluding or including REG_ICASE for case (in)sensitivity. */ +void parse_colors(char *ptr, int rex_flags) { short fg, bg; bool bright = FALSE; @@ -680,7 +680,7 @@ void parse_colors(char *ptr, bool icase) if (ptr == NULL) break; - goodstart = nregcomp(fgstr, icase ? REG_ICASE : 0); + goodstart = nregcomp(fgstr, rex_flags); /* If the starting regex is valid, initialize a new color struct, * and hook it in at the tail of the linked list. */ @@ -690,7 +690,7 @@ void parse_colors(char *ptr, bool icase) newcolor->fg = fg; newcolor->bg = bg; newcolor->bright = bright; - newcolor->icase = icase; + newcolor->rex_flags = rex_flags; newcolor->start_regex = mallocstrcpy(NULL, fgstr); newcolor->start = NULL; @@ -736,7 +736,7 @@ void parse_colors(char *ptr, bool icase) continue; /* If it's valid, save the ending regex string. */ - if (nregcomp(fgstr, icase ? REG_ICASE : 0)) + if (nregcomp(fgstr, rex_flags)) newcolor->end_regex = mallocstrcpy(NULL, fgstr); /* Lame way to skip another static counter. */ @@ -830,7 +830,7 @@ void grab_and_store(const char *kind, char *ptr, regexlisttype **storage) return; /* If the regex string is malformed, skip it. */ - if (!nregcomp(regexstring, REG_NOSUB)) + if (!nregcomp(regexstring, REG_EXTENDED | REG_NOSUB)) continue; /* Copy the regex into a struct, and hook this in at the end. */ @@ -1009,9 +1009,9 @@ void parse_rcfile(FILE *rcstream ; #endif else if (strcasecmp(keyword, "color") == 0) - parse_colors(ptr, FALSE); + parse_colors(ptr, REG_EXTENDED); else if (strcasecmp(keyword, "icolor") == 0) - parse_colors(ptr, TRUE); + parse_colors(ptr, REG_EXTENDED | REG_ICASE); else if (strcasecmp(keyword, "linter") == 0) pick_up_name("linter", ptr, &live_syntax->linter); else if (strcasecmp(keyword, "formatter") == 0)