Christian Weisgerber <na...@mips.inka.de> writes: > Jérémie Courrèges-Anglas: > >> If no one chimes in, ok to delete it. This being said, here's a >> compile-tested (and may^Wprobably incomplete) attempt to convert it to >> regex(3). > >> +@@ -392,7 +392,7 @@ static void build_ts(char *gi, char* cp) >> + tok = Split(cp, &i, S_STRDUP); >> + T.var_RE_name = tok[0]; >> + ExpandVariables(tok[1], buf, 0); >> +- if (!(T.var_RE_value=regcomp(buf))) { >> ++ if (regcomp(&T.var_RE_value, buf, REG_BASIC|REG_NOSUB)) { >> + fprintf(stderr, "Regex error in VarREValue Content: %s\n", >> + tok[1]); >> + } > > We need REG_EXTENDED. > > There is a subtle problem in the error case: var_RE_value will have > an undefined value. However, over in translate.c, regexec() is > blindly called with whatever regcomp() returned.
Right. >> +@@ -415,11 +415,23 @@ FindTrans( >> + if (!QRelation(e, t->parent, REL_Parent)) continue; >> + >> + if (t->context) { /* no context specified -> a match */ >> ++ char *cp; >> ++ int do_regex = 0; >> ++ >> ++ for (do_regex=0,cp=t->context; *cp; cp++) { >> ++ if (!isalnum(*cp) && *cp != '-' && *cp != '.' && *cp != ' >> ') { >> ++ do_regex = 1; >> ++ break; >> ++ } >> ++ } >> ++ > > Ewww. Copy/pasted from traninit.c, what did you expect? ;) >> + FindContext(e, t->depth, context); >> + >> + /* If reg expr set, do regex compare; else just string compare. */ >> +- if (t->context_re) { >> +- if (! regexec(t->context_re, context)) continue; >> ++ if (do_regex) { >> ++ if (regexec(&t->context_re, context, 0, NULL, >> ++ REG_NOTBOL|REG_NOTEOL) != 0) >> ++ continue; >> + } > > Why REG_NOTBOL|REG_NOTEOL? I don't think this matches the v8_regexec() > semantics. *shrug*. That's unfinished at best, I had yet to do tests (because I don't understand what the eflags description in regex(3)). > My current thinking is to use wrappers, something along these lines: > > regex_t *v8regcomp(...) > { > regex_t *re; > if (!(re = malloc(...))) > return NULL; > if (regcomp(re, ...)) { > free(re); > return NULL; > } > return re; > } > > int v8regexec(regex_t re, ...) > { > if (!re) > return 0; > return !regexec(re, ...); > } > > This would allow us to preserve (regex_t *)NULL to stand for a > nonexistent/invalid regular expression. Sounds nice. *If* we actually want to keep it. ;) -- jca | PGP: 0x06A11494 / 61DB D9A0 00A4 67CF 2A90 8961 6191 8FBF 06A1 1494