diff --git a/ChangeLog b/ChangeLog index 5562b65f..ef74d0fd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,8 @@ * src/nano.h: Delete a now-unused struct member. * src/global.c (free_list_item): Elide this now too tiny function. * scr/global.c (thanks_for_all_the_fish): Rename three variables. + * src/rcfile.c (parse_colors): Tweak a few things. + * src/color.c (color_update): Rename a variable. 2016-03-01 Benno Schulenberg * src/rcfile.c (parse_syntax), src/color.c (color_update): Don't diff --git a/src/color.c b/src/color.c index e127e7ba..3026c2d6 100644 --- a/src/color.c +++ b/src/color.c @@ -164,7 +164,7 @@ bool found_in_list(regexlisttype *head, const char *shibboleth) void color_update(void) { syntaxtype *sint; - colortype *tmpcolor; + colortype *ink; assert(openfile != NULL); @@ -291,21 +291,19 @@ void color_update(void) } } - for (tmpcolor = openfile->colorstrings; tmpcolor != NULL; - tmpcolor = tmpcolor->next) { - /* tmpcolor->start_regex and tmpcolor->end_regex have already - * been checked for validity elsewhere. Compile their specified - * regexes if we haven't already. */ - if (tmpcolor->start == NULL) { - tmpcolor->start = (regex_t *)nmalloc(sizeof(regex_t)); - regcomp(tmpcolor->start, fixbounds(tmpcolor->start_regex), - REG_EXTENDED | (tmpcolor->icase ? REG_ICASE : 0)); + /* If a syntax was found, compile its specified regexes, which have + * already been checked for validity when they were read in. */ + for (ink = openfile->colorstrings; 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)); } - if (tmpcolor->end_regex != NULL && tmpcolor->end == NULL) { - tmpcolor->end = (regex_t *)nmalloc(sizeof(regex_t)); - regcomp(tmpcolor->end, fixbounds(tmpcolor->end_regex), - REG_EXTENDED | (tmpcolor->icase ? REG_ICASE : 0)); + 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)); } } } diff --git a/src/rcfile.c b/src/rcfile.c index 8e1a62d5..e7dd7692 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -711,18 +711,16 @@ void parse_colors(char *ptr, bool icase) continue; } - ptr++; - - fgstr = ptr; + fgstr = ++ptr; ptr = parse_next_regex(ptr); if (ptr == NULL) break; - newcolor = (colortype *)nmalloc(sizeof(colortype)); - /* Save the starting regex string if it's valid, and set up the * color information. */ if (nregcomp(fgstr, icase ? REG_ICASE : 0)) { + newcolor = (colortype *)nmalloc(sizeof(colortype)); + newcolor->fg = fg; newcolor->bg = bg; newcolor->bright = bright; @@ -747,16 +745,14 @@ void parse_colors(char *ptr, bool icase) #endif /* Need to recompute endcolor now so we can extend * colors to syntaxes. */ - for (endcolor = endsyntax->color; endcolor->next != NULL; endcolor = endcolor->next) - ; + for (endcolor = endsyntax->color; endcolor->next != NULL;) + endcolor = endcolor->next; endcolor->next = newcolor; } endcolor = newcolor; - } else { - free(newcolor); + } else cancelled = TRUE; - } if (expectend) { if (ptr == NULL || strncasecmp(ptr, "end=", 4) != 0) { @@ -771,9 +767,7 @@ void parse_colors(char *ptr, bool icase) continue; } - ptr++; - - fgstr = ptr; + fgstr = ++ptr; ptr = parse_next_regex(ptr); if (ptr == NULL) break; @@ -783,9 +777,9 @@ void parse_colors(char *ptr, bool icase) if (cancelled) continue; - /* Save the ending regex string if it's valid. */ - newcolor->end_regex = (nregcomp(fgstr, icase ? REG_ICASE : - 0)) ? mallocstrcpy(NULL, fgstr) : NULL; + /* If it's valid, save the ending regex string. */ + if (nregcomp(fgstr, icase ? REG_ICASE : 0)) + newcolor->end_regex = mallocstrcpy(NULL, fgstr); /* Lame way to skip another static counter. */ newcolor->id = endsyntax->nmultis;