aboutsummaryrefslogtreecommitdiff
path: root/regcomp.c
diff options
context:
space:
mode:
Diffstat (limited to 'regcomp.c')
-rw-r--r--regcomp.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/regcomp.c b/regcomp.c
index 8ff77ad..c00e19e 100644
--- a/regcomp.c
+++ b/regcomp.c
@@ -86,7 +86,7 @@ static chr newline(NOPARMS);
#ifdef REG_DEBUG
static const chr *ch(NOPARMS);
#endif
-static chr chrnamed(struct vars *, const chr *, const chr *, pchr);
+static pchr chrnamed(struct vars *, const chr *, const chr *, pchr);
/* === regc_color.c === */
static void initcm(struct vars *, struct colormap *);
static void freecm(struct colormap *);
@@ -193,7 +193,7 @@ struct vars {
int cflags; /* copy of compile flags */
int lasttype; /* type of previous token */
int nexttype; /* type of next token */
- chr nextvalue; /* value (if any) of next token */
+ pchr nextvalue; /* value (if any) of next token */
int lexcon; /* lexical context type (see lex.c) */
int nsubexp; /* subexpression count */
struct subre **subs; /* subRE pointer vector */
@@ -229,6 +229,12 @@ struct vars {
#define NOTE(b) (v->re->re_info |= (b)) /* note visible condition */
#define EMPTYARC(x, y) newarc(v->nfa, EMPTY, 0, x, y)
+#ifdef REGEX_UTF8
+#define DECODECHR(buf, c) wctomb((char *)buf, c)
+#else
+#define DECODECHR(buf, c) ((buf)[0] = (c), 1)
+#endif
+
/* token type codes, some also used as NFA arc types */
#define EMPTY 'n' /* no token present */
#define EOS 'e' /* end of string */
@@ -1458,7 +1464,9 @@ brackpart(
celt startc, endc;
struct cvec *cv;
const chr *startp, *endp;
- chr c[1];
+ chr buf[MB_LEN_MAX];
+ size_t buf_len;
+ pchr c;
/*
* Parse something, get rid of special cases, take shortcuts.
@@ -1470,7 +1478,7 @@ brackpart(
return;
break;
case PLAIN:
- c[0] = v->nextvalue;
+ c = v->nextvalue;
NEXT();
/*
@@ -1478,10 +1486,11 @@ brackpart(
*/
if (!SEE(RANGE)) {
- onechr(v, c[0], lp, rp);
+ onechr(v, c, lp, rp);
return;
}
- startc = element(v, c, c+1);
+ buf_len = DECODECHR(buf, c);
+ startc = element(v, buf, buf+buf_len);
NOERR();
break;
case COLLEL:
@@ -1525,9 +1534,9 @@ brackpart(
switch (v->nexttype) {
case PLAIN:
case RANGE:
- c[0] = v->nextvalue;
+ buf_len = DECODECHR(buf, v->nextvalue);
NEXT();
- endc = element(v, c, c+1);
+ endc = element(v, buf, buf+buf_len);
NOERR();
break;
case COLLEL:
@@ -1623,8 +1632,8 @@ dovec(
struct state *lp,
struct state *rp)
{
- chr ch, from, to;
- const chr *p;
+ pchr ch, from, to;
+ const pchr *p;
int i;
for (p = cv->chrs, i = cv->nchrs; i > 0; p++, i--) {