awk: support for whitespace between array name and bracket
This commit is contained in:
parent
708929bc32
commit
4db12454e9
@ -291,11 +291,32 @@ scanreg()
|
|||||||
return REGEXP;
|
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)
|
Ungetc(c)
|
||||||
{
|
{
|
||||||
c0 = c;
|
if (unget_depth == UNGET_DEPTH) error("unget buffer overflow");
|
||||||
|
unget[unget_depth++] = c;
|
||||||
|
|
||||||
if (linep > line) {
|
if (linep > line) {
|
||||||
if (--linep < line)
|
if (--linep < line)
|
||||||
@ -308,9 +329,8 @@ Getc()
|
|||||||
register int c;
|
register int c;
|
||||||
char *s, *t;
|
char *s, *t;
|
||||||
|
|
||||||
if (c0) {
|
if (unget_depth > 0)
|
||||||
c = c0; c0 = 0;
|
c = unget[--unget_depth];
|
||||||
}
|
|
||||||
else if (srcprg)
|
else if (srcprg)
|
||||||
c = *srcprg ? *srcprg++ : EOF;
|
c = *srcprg ? *srcprg++ : EOF;
|
||||||
else
|
else
|
||||||
|
@ -265,7 +265,7 @@ stat()
|
|||||||
case DELETE:
|
case DELETE:
|
||||||
lex();
|
lex();
|
||||||
u = getvar(text, hashtab, ARR);
|
u = getvar(text, hashtab, ARR);
|
||||||
if (Getc() != '[')
|
if (!isarrayindex())
|
||||||
synerr("'[' expected");
|
synerr("'[' expected");
|
||||||
p = doarray(u);
|
p = doarray(u);
|
||||||
p->n_type = DELETE;
|
p->n_type = DELETE;
|
||||||
@ -842,7 +842,7 @@ g1:
|
|||||||
lex();
|
lex();
|
||||||
break;
|
break;
|
||||||
case IDENT: case ARG:
|
case IDENT: case ARG:
|
||||||
if ((c = Getc()) == '[') { /* array */
|
if (isarrayindex()) { /* array */
|
||||||
/* 940403 */
|
/* 940403 */
|
||||||
if (sym == ARG) {
|
if (sym == ARG) {
|
||||||
u = (CELL *)emalloc(sizeof(CELL));
|
u = (CELL *)emalloc(sizeof(CELL));
|
||||||
@ -855,7 +855,6 @@ g1:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Ungetc(c);
|
|
||||||
if (sym == ARG) {
|
if (sym == ARG) {
|
||||||
u = mkcell(POS, NULL, (double)sym1);
|
u = mkcell(POS, NULL, (double)sym1);
|
||||||
p = node1(ARG, u);
|
p = node1(ARG, u);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user