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
This commit is contained in:
Benno Schulenberg 2016-03-13 19:37:21 +00:00
parent 57c50baa61
commit 6ed6462154
5 changed files with 17 additions and 19 deletions

View File

@ -2,6 +2,8 @@
* src/search.c (regexp_init): Allow using the word boundary markers * src/search.c (regexp_init): Allow using the word boundary markers
\< and \> in search strings on non-GNU systems. This is a partial \< and \> in search strings on non-GNU systems. This is a partial
fix for Savannah bug #47325 reported by Thomas Rosenau. 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) 2016-03-13 Thomas Rosenau <thomasr@fantasymail.de> (tiny change)
* autogen.sh, README.SVN: Mention SVN instead of CVS. * autogen.sh, README.SVN: Mention SVN instead of CVS.

View File

@ -283,14 +283,12 @@ void color_update(void)
for (ink = sint->color; ink != NULL; ink = ink->next) { for (ink = sint->color; ink != NULL; ink = ink->next) {
if (ink->start == NULL) { if (ink->start == NULL) {
ink->start = (regex_t *)nmalloc(sizeof(regex_t)); ink->start = (regex_t *)nmalloc(sizeof(regex_t));
regcomp(ink->start, fixbounds(ink->start_regex), regcomp(ink->start, fixbounds(ink->start_regex), ink->rex_flags);
REG_EXTENDED | (ink->icase ? REG_ICASE : 0));
} }
if (ink->end_regex != NULL && ink->end == NULL) { if (ink->end_regex != NULL && ink->end == NULL) {
ink->end = (regex_t *)nmalloc(sizeof(regex_t)); ink->end = (regex_t *)nmalloc(sizeof(regex_t));
regcomp(ink->end, fixbounds(ink->end_regex), regcomp(ink->end, fixbounds(ink->end_regex), ink->rex_flags);
REG_EXTENDED | (ink->icase ? REG_ICASE : 0));
} }
} }
} }

View File

@ -209,11 +209,11 @@ typedef struct colortype {
/* This syntax's background color. */ /* This syntax's background color. */
bool bright; bool bright;
/* Is this color A_BOLD? */ /* Is this color A_BOLD? */
bool icase;
/* Is this regex string case insensitive? */
int pairnum; int pairnum;
/* The color pair number used for this foreground color and /* The color pair number used for this foreground color and
* background color. */ * background color. */
int rex_flags;
/* The regex compilation flags (with or without REG_ICASE). */
char *start_regex; char *start_regex;
/* The start (or all) of the regex string. */ /* The start (or all) of the regex string. */
regex_t *start; regex_t *start;

View File

@ -561,11 +561,9 @@ void rcfile_error(const char *msg, ...);
char *parse_argument(char *ptr); char *parse_argument(char *ptr);
#ifndef DISABLE_COLOR #ifndef DISABLE_COLOR
char *parse_next_regex(char *ptr); char *parse_next_regex(char *ptr);
bool nregcomp(const char *regex, int eflags);
void parse_syntax(char *ptr); void parse_syntax(char *ptr);
void parse_includes(char *ptr); void parse_includes(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);
bool parse_color_names(char *combostr, short *fg, short *bg, bool *bright); bool parse_color_names(char *combostr, short *fg, short *bg, bool *bright);
void grab_and_store(const char *kind, char *ptr, regexlisttype **storage); void grab_and_store(const char *kind, char *ptr, regexlisttype **storage);
#endif #endif

View File

@ -244,11 +244,11 @@ char *parse_next_regex(char *ptr)
/* Compile the regular expression regex to see if it's valid. Return /* Compile the regular expression regex to see if it's valid. Return
* TRUE if it is, and FALSE otherwise. */ * 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; regex_t preg;
const char *r = fixbounds(regex); const char *r = fixbounds(regex);
int rc = regcomp(&preg, r, REG_EXTENDED | eflags); int rc = regcomp(&preg, r, compile_flags);
if (rc != 0) { if (rc != 0) {
size_t len = regerror(rc, &preg, NULL, 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 /* 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 * file's associated colors. rex_flags are the regex compilation flags
* as case insensitive. */ * to use, excluding or including REG_ICASE for case (in)sensitivity. */
void parse_colors(char *ptr, bool icase) void parse_colors(char *ptr, int rex_flags)
{ {
short fg, bg; short fg, bg;
bool bright = FALSE; bool bright = FALSE;
@ -680,7 +680,7 @@ void parse_colors(char *ptr, bool icase)
if (ptr == NULL) if (ptr == NULL)
break; break;
goodstart = nregcomp(fgstr, icase ? REG_ICASE : 0); goodstart = nregcomp(fgstr, rex_flags);
/* If the starting regex is valid, initialize a new color struct, /* If the starting regex is valid, initialize a new color struct,
* and hook it in at the tail of the linked list. */ * 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->fg = fg;
newcolor->bg = bg; newcolor->bg = bg;
newcolor->bright = bright; newcolor->bright = bright;
newcolor->icase = icase; newcolor->rex_flags = rex_flags;
newcolor->start_regex = mallocstrcpy(NULL, fgstr); newcolor->start_regex = mallocstrcpy(NULL, fgstr);
newcolor->start = NULL; newcolor->start = NULL;
@ -736,7 +736,7 @@ void parse_colors(char *ptr, bool icase)
continue; continue;
/* If it's valid, save the ending regex string. */ /* 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); newcolor->end_regex = mallocstrcpy(NULL, fgstr);
/* Lame way to skip another static counter. */ /* Lame way to skip another static counter. */
@ -830,7 +830,7 @@ void grab_and_store(const char *kind, char *ptr, regexlisttype **storage)
return; return;
/* If the regex string is malformed, skip it. */ /* If the regex string is malformed, skip it. */
if (!nregcomp(regexstring, REG_NOSUB)) if (!nregcomp(regexstring, REG_EXTENDED | REG_NOSUB))
continue; continue;
/* Copy the regex into a struct, and hook this in at the end. */ /* Copy the regex into a struct, and hook this in at the end. */
@ -1009,9 +1009,9 @@ void parse_rcfile(FILE *rcstream
; ;
#endif #endif
else if (strcasecmp(keyword, "color") == 0) else if (strcasecmp(keyword, "color") == 0)
parse_colors(ptr, FALSE); parse_colors(ptr, REG_EXTENDED);
else if (strcasecmp(keyword, "icolor") == 0) else if (strcasecmp(keyword, "icolor") == 0)
parse_colors(ptr, TRUE); parse_colors(ptr, REG_EXTENDED | REG_ICASE);
else if (strcasecmp(keyword, "linter") == 0) else if (strcasecmp(keyword, "linter") == 0)
pick_up_name("linter", ptr, &live_syntax->linter); pick_up_name("linter", ptr, &live_syntax->linter);
else if (strcasecmp(keyword, "formatter") == 0) else if (strcasecmp(keyword, "formatter") == 0)