Hello tech@,
parse_char_class does a really fancy *s != '\n' dance.
I say we remove it and let regcomp determine if we have a properly
formatted char_class.
This changes our error message for a unbalanced char_class from:
unbalanced brackets ([])
to:
brackets ([ ]) not balanced
OK?
martijn@
Index: re.c
===
RCS file: /cvs/src/bin/ed/re.c,v
retrieving revision 1.17
diff -u -p -r1.17 re.c
--- re.c22 Mar 2016 17:58:28 - 1.17
+++ re.c18 Jun 2018 16:38:51 -
@@ -94,16 +94,10 @@ extract_pattern(int delimiter)
char *nd;
int len;
- for (nd = ibufp; *nd != delimiter && *nd != '\n'; nd++)
+ for (nd = ibufp; *nd != delimiter && *nd != '\n'; nd++) {
switch (*nd) {
default:
break;
- case '[':
- if ((nd = parse_char_class(++nd)) == NULL) {
- seterrmsg("unbalanced brackets ([])");
- return NULL;
- }
- break;
case '\\':
if (*++nd == '\n') {
seterrmsg("trailing backslash (\\)");
@@ -111,29 +105,11 @@ extract_pattern(int delimiter)
}
break;
}
+ }
len = nd - ibufp;
REALLOC(lhbuf, lhbufsz, len + 1, NULL);
memcpy(lhbuf, ibufp, len);
lhbuf[len] = '\0';
ibufp = nd;
return (isbinary) ? NUL_TO_NEWLINE(lhbuf, len) : lhbuf;
-}
-
-
-/* parse_char_class: expand a POSIX character class */
-static char *
-parse_char_class(char *s)
-{
- int c, d;
-
- if (*s == '^')
- s++;
- if (*s == ']')
- s++;
- for (; *s != ']' && *s != '\n'; s++)
- if (*s == '[' && ((d = *(s+1)) == '.' || d == ':' || d == '='))
- for (s++, c = *++s; *s != ']' || c != d; s++)
- if ((c = *s) == '\n')
- return NULL;
- return (*s == ']') ? s : NULL;
}