From: Benno Schulenberg Date: Sun, 13 Mar 2016 19:37:21 +0000 (+0000) Subject: Combining the regular-expression flags at compile time instead of at run time. X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=6ed646215451099743aaa4443596f325d7f9c549;p=nano.git Combining the regular-expression flags at compile time instead of at run time. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5732 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index ea7e65a1..9ba4ccb1 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 (tiny change) * autogen.sh, README.SVN: Mention SVN instead of CVS. diff --git a/src/color.c b/src/color.c index 388ef137..bbf1f85d 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 990cc238..138cf0b5 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 1090db45..8af1bebb 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 26bd0fea..37636860 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)