From 3e0ebe0f9c4548d57b9b2f4a35824ddf95dfe79b Mon Sep 17 00:00:00 2001 From: tedu Date: Mon, 8 Sep 2014 15:45:20 +0000 Subject: add \ support to regcomp. prompted by renewed interest from jsg because such support is reportedly common and in somewhat wide use. undocumented for now because we don't endorse this. ok jsg millert --- lib/libc/regex/regcomp.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'lib/libc/regex/regcomp.c') diff --git a/lib/libc/regex/regcomp.c b/lib/libc/regex/regcomp.c index d49b921302d..d52febf337d 100644 --- a/lib/libc/regex/regcomp.c +++ b/lib/libc/regex/regcomp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: regcomp.c,v 1.24 2014/05/06 15:48:38 tedu Exp $ */ +/* $OpenBSD: regcomp.c,v 1.25 2014/09/08 15:45:20 tedu Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 Henry Spencer. * Copyright (c) 1992, 1993, 1994 @@ -81,6 +81,7 @@ static char p_b_coll_elem(struct parse *, int); static char othercase(int); static void bothcases(struct parse *, int); static void ordinary(struct parse *, int); +static void backslash(struct parse *, int); static void nonnewline(struct parse *); static void repeat(struct parse *, sopno, int, int); static int seterr(struct parse *, int); @@ -349,7 +350,7 @@ p_ere_exp(struct parse *p) case '\\': REQUIRE(MORE(), REG_EESCAPE); c = GETNEXT(); - ordinary(p, c); + backslash(p, c); break; case '{': /* okay as ordinary except if digit follows */ REQUIRE(!MORE() || !isdigit((uch)PEEK()), REG_BADRPT); @@ -501,6 +502,12 @@ p_simp_re(struct parse *p, case '[': p_bracket(p); break; + case BACKSL|'<': + EMIT(OBOW, 0); + break; + case BACKSL|'>': + EMIT(OEOW, 0); + break; case BACKSL|'{': SETERROR(REG_BADRPT); break; @@ -895,6 +902,25 @@ ordinary(struct parse *p, int ch) } } +/* + * do something magic with this character, but only if it's extra magic + */ +static void +backslash(struct parse *p, int ch) +{ + switch (ch) { + case '<': + EMIT(OBOW, 0); + break; + case '>': + EMIT(OEOW, 0); + break; + default: + ordinary(p, ch); + break; + } +} + /* - nonnewline - emit REG_NEWLINE version of OANY * -- cgit v1.2.3-59-g8ed1b