summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugh Graham <hugh@cvs.openbsd.org>2006-04-16 02:10:19 +0000
committerHugh Graham <hugh@cvs.openbsd.org>2006-04-16 02:10:19 +0000
commit9057cdc872e4985a9cda981d827ddda9126a06d2 (patch)
tree0d61fd2ed5ec5ef32eabcf9bdfaa1ba78ffb895e
parent9f1f0f20b74cf75d9bcc4beab180a9808e6c8ed4 (diff)
Handle / inside []s properly.
OK by otto and millert. Offered back to bell-labs.
-rw-r--r--usr.bin/awk/lex.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/usr.bin/awk/lex.c b/usr.bin/awk/lex.c
index 737f589ea66..eaf09d1cd45 100644
--- a/usr.bin/awk/lex.c
+++ b/usr.bin/awk/lex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lex.c,v 1.8 2004/12/30 01:52:48 millert Exp $ */
+/* $OpenBSD: lex.c,v 1.9 2006/04/16 02:10:18 hugh Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
@@ -514,7 +514,7 @@ void startreg(void) /* next call to yylex will return a regular expression */
int regexpr(void)
{
- int c;
+ int c, openclass = 0;
static char *buf = 0;
static int bufsz = 500;
char *bp;
@@ -522,7 +522,7 @@ int regexpr(void)
if (buf == 0 && (buf = (char *) malloc(bufsz)) == NULL)
FATAL("out of space for rex expr");
bp = buf;
- for ( ; (c = input()) != '/' && c != 0; ) {
+ for ( ; ((c = input()) != '/' || openclass == 1) && c != 0; ) {
if (!adjbuf(&buf, &bufsz, bp-buf+3, 500, &bp, 0))
FATAL("out of space for reg expr %.10s...", buf);
if (c == '\n') {
@@ -533,6 +533,10 @@ int regexpr(void)
*bp++ = '\\';
*bp++ = input();
} else {
+ if (c == '[')
+ openclass = 1;
+ else if (c == ']')
+ openclass = 0;
*bp++ = c;
}
}