awk: support for whitespace between array name and bracket

This commit is contained in:
David van Moolenbroek 2009-08-15 12:05:41 +00:00
parent 708929bc32
commit 4db12454e9
2 changed files with 27 additions and 8 deletions

View file

@ -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

View file

@ -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);