tweaks: rename a function and its parameters, to be more fitting

Also, reshuffle their order, and improve or adjust some comments.
And change the type of 'pairnum' to short, what ncurses uses too.
master
Benno Schulenberg 2019-06-05 13:00:35 +02:00
parent 57b3f83cfe
commit 7c1b649eb8
2 changed files with 23 additions and 26 deletions

View File

@ -187,15 +187,14 @@ typedef struct colortype {
/* This syntax's foreground color. */ /* This syntax's foreground color. */
short bg; short bg;
/* This syntax's background color. */ /* This syntax's background color. */
int pairnum; short pairnum;
/* The color pair number used for this foreground color and /* The pair number for this foreground/background color combination. */
* background color. */
int attributes; int attributes;
/* Pair number and brightness composed into ready-to-use attributes. */ /* Pair number and brightness composed into ready-to-use attributes. */
regex_t *start; regex_t *start;
/* The compiled start (or all) of the regex string. */ /* The compiled regular expression for 'start=', or the only one. */
regex_t *end; regex_t *end;
/* The compiled end (if any) of the regex string. */ /* The compiled regular expression for 'end=', if any. */
struct colortype *next; struct colortype *next;
/* Next set of colors. */ /* Next set of colors. */
int id; int id;

View File

@ -267,27 +267,27 @@ char *parse_next_regex(char *ptr)
return ptr; return ptr;
} }
/* Compile the regular expression regex to see if it's valid. Return /* Compile the given regular expression and store the result in packed (when
* TRUE if it is, and FALSE otherwise. */ * this pointer is not NULL). Return TRUE when the expression is valid. */
bool nregcomp(regex_t **compiled, const char *regex, int compile_flags) bool compile(const char *expression, int rex_flags, regex_t **packed)
{ {
regex_t *preg = nmalloc(sizeof(regex_t)); regex_t *compiled = nmalloc(sizeof(regex_t));
int rc = regcomp(preg, regex, compile_flags); int rc = regcomp(compiled, expression, rex_flags);
if (rc != 0) { if (rc != 0) {
size_t len = regerror(rc, preg, NULL, 0); size_t len = regerror(rc, compiled, NULL, 0);
char *str = charalloc(len); char *str = charalloc(len);
regerror(rc, preg, str, len); regerror(rc, compiled, str, len);
rcfile_error(N_("Bad regex \"%s\": %s"), regex, str); rcfile_error(N_("Bad regex \"%s\": %s"), expression, str);
free(str); free(str);
} }
if (compiled == NULL || rc != 0) { if (packed == NULL || rc != 0) {
regfree(preg); regfree(compiled);
free(preg); free(compiled);
} else } else
*compiled = preg; *packed = compiled;
return (rc == 0); return (rc == 0);
} }
@ -767,18 +767,17 @@ void parse_colors(char *ptr, int rex_flags)
goodstart = FALSE; goodstart = FALSE;
} else { } else {
newcolor = (colortype *)nmalloc(sizeof(colortype)); newcolor = (colortype *)nmalloc(sizeof(colortype));
goodstart = nregcomp(&newcolor->start, item, rex_flags); goodstart = compile(item, rex_flags, &newcolor->start);
} }
/* If the starting regex is valid, initialize a new color struct, /* If the start regex is valid, fill in the rest of the data, and
* and hook it in at the tail of the linked list. */ * hook the new color struct in at the tail of the linked list. */
if (goodstart) { if (goodstart) {
newcolor->fg = fg; newcolor->fg = fg;
newcolor->bg = bg; newcolor->bg = bg;
newcolor->attributes = attributes; newcolor->attributes = attributes;
newcolor->end = NULL; newcolor->end = NULL;
newcolor->next = NULL; newcolor->next = NULL;
if (lastcolor == NULL) if (lastcolor == NULL)
@ -814,13 +813,12 @@ void parse_colors(char *ptr, int rex_flags)
continue; continue;
} }
/* If the start regex was invalid, skip past the end regex /* If the start regex was invalid, the end regex cannot be saved. */
* to stay in sync. */
if (!goodstart) if (!goodstart)
continue; continue;
/* If it's valid, save the ending regex string. */ /* Save the compiled ending regex (when it's valid). */
nregcomp(&newcolor->end, item, rex_flags); compile(item, rex_flags, &newcolor->end);
/* Lame way to skip another static counter. */ /* Lame way to skip another static counter. */
newcolor->id = live_syntax->nmultis; newcolor->id = live_syntax->nmultis;
@ -889,7 +887,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(NULL, regexstring, NANO_REG_EXTENDED | REG_NOSUB)) if (!compile(regexstring, NANO_REG_EXTENDED | REG_NOSUB, NULL))
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. */