From 4db12454e927afcfbefe3199f5504b9e56dc6a2f Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Sat, 15 Aug 2009 12:05:41 +0000 Subject: [PATCH] awk: support for whitespace between array name and bracket --- commands/awk/l.c | 30 +++++++++++++++++++++++++----- commands/awk/y.c | 5 ++--- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/commands/awk/l.c b/commands/awk/l.c index ffa5520b6..8e86c50cc 100755 --- a/commands/awk/l.c +++ b/commands/awk/l.c @@ -291,11 +291,32 @@ scanreg() return REGEXP; } -static int c0; +isarrayindex() +{ + int c, c2; + +next: + while ((c = Getc()) == ' ' || c == '\t') + ; + if (c == '\\') { + if ((c2 = Getc()) == '\n') { + lineno++; + goto next; + } + Ungetc(c2); + } + if (c != '[') Ungetc(c); + + return (c == '['); +} + +#define UNGET_DEPTH 2 +static int unget[UNGET_DEPTH], unget_depth; Ungetc(c) { - c0 = c; + if (unget_depth == UNGET_DEPTH) error("unget buffer overflow"); + unget[unget_depth++] = c; if (linep > line) { if (--linep < line) @@ -308,9 +329,8 @@ Getc() register int c; char *s, *t; - if (c0) { - c = c0; c0 = 0; - } + if (unget_depth > 0) + c = unget[--unget_depth]; else if (srcprg) c = *srcprg ? *srcprg++ : EOF; else diff --git a/commands/awk/y.c b/commands/awk/y.c index d3575d2f9..6b5d8933d 100755 --- a/commands/awk/y.c +++ b/commands/awk/y.c @@ -265,7 +265,7 @@ stat() case DELETE: lex(); u = getvar(text, hashtab, ARR); - if (Getc() != '[') + if (!isarrayindex()) synerr("'[' expected"); p = doarray(u); p->n_type = DELETE; @@ -842,7 +842,7 @@ g1: lex(); break; case IDENT: case ARG: - if ((c = Getc()) == '[') { /* array */ + if (isarrayindex()) { /* array */ /* 940403 */ if (sym == ARG) { u = (CELL *)emalloc(sizeof(CELL)); @@ -855,7 +855,6 @@ g1: } } else { - Ungetc(c); if (sym == ARG) { u = mkcell(POS, NULL, (double)sym1); p = node1(ARG, u); -- 2.44.0