awk: style fixes

This commit is contained in:
Denis Vlasenko 2007-01-01 23:53:52 +00:00
parent 6dc6ebbf44
commit e1d3e034a9

View File

@ -848,20 +848,16 @@ static uint32_t next_token(uint32_t expected)
int l; int l;
if (t.rollback) { if (t.rollback) {
t.rollback = FALSE; t.rollback = FALSE;
} else if (concat_inserted) { } else if (concat_inserted) {
concat_inserted = FALSE; concat_inserted = FALSE;
t.tclass = save_tclass; t.tclass = save_tclass;
t.info = save_info; t.info = save_info;
} else { } else {
p = pos; p = pos;
readnext:
readnext:
skip_spaces(&p); skip_spaces(&p);
lineno = t.lineno; lineno = t.lineno;
if (*p == '#') if (*p == '#')
@ -939,7 +935,7 @@ static uint32_t next_token(uint32_t expected)
/* it's a name (var/array/function), /* it's a name (var/array/function),
* otherwise it's something wrong * otherwise it's something wrong
*/ */
if (! isalnum_(*p)) if (!isalnum_(*p))
syntax_error(EMSG_UNEXP_TOKEN); syntax_error(EMSG_UNEXP_TOKEN);
t.string = --p; t.string = --p;
@ -949,7 +945,7 @@ static uint32_t next_token(uint32_t expected)
*(p-1) = '\0'; *(p-1) = '\0';
tc = TC_VARIABLE; tc = TC_VARIABLE;
/* also consume whitespace between functionname and bracket */ /* also consume whitespace between functionname and bracket */
if (! (expected & TC_VARIABLE)) skip_spaces(&p); if (!(expected & TC_VARIABLE)) skip_spaces(&p);
if (*p == '(') { if (*p == '(') {
tc = TC_FUNCTION; tc = TC_FUNCTION;
} else { } else {
@ -1395,14 +1391,14 @@ static regex_t *as_regex(node *op, regex_t *preg)
/* gradually increasing buffer */ /* gradually increasing buffer */
static void qrealloc(char **b, int n, int *size) static void qrealloc(char **b, int n, int *size)
{ {
if (! *b || n >= *size) if (!*b || n >= *size)
*b = xrealloc(*b, *size = n + (n>>1) + 80); *b = xrealloc(*b, *size = n + (n>>1) + 80);
} }
/* resize field storage space */ /* resize field storage space */
static void fsrealloc(int size) static void fsrealloc(int size)
{ {
static int maxfields = 0; static int maxfields; /* = 0;*/
int i; int i;
if (size >= maxfields) { if (size >= maxfields) {
@ -1416,8 +1412,8 @@ static void fsrealloc(int size)
} }
if (size < nfields) { if (size < nfields) {
for (i=size; i<nfields; i++) { for (i = size; i < nfields; i++) {
clrvar(Fields+i); clrvar(Fields + i);
} }
} }
nfields = size; nfields = size;
@ -1457,8 +1453,8 @@ static int awk_split(char *s, node *spl, char **slist)
} }
} else if (c[0] == '\0') { /* null split */ } else if (c[0] == '\0') { /* null split */
while (*s) { while (*s) {
*(s1++) = *(s++); *s1++ = *s++;
*(s1++) = '\0'; *s1++ = '\0';
n++; n++;
} }
} else if (c[0] != ' ') { /* single-character split */ } else if (c[0] != ' ') { /* single-character split */
@ -1468,17 +1464,17 @@ static int awk_split(char *s, node *spl, char **slist)
} }
if (*s1) n++; if (*s1) n++;
while ((s1 = strpbrk(s1, c))) { while ((s1 = strpbrk(s1, c))) {
*(s1++) = '\0'; *s1++ = '\0';
n++; n++;
} }
} else { /* space split */ } else { /* space split */
while (*s) { while (*s) {
s = skip_whitespace(s); s = skip_whitespace(s);
if (! *s) break; if (!*s) break;
n++; n++;
while (*s && !isspace(*s)) while (*s && !isspace(*s))
*(s1++) = *(s++); *s1++ = *s++;
*(s1++) = '\0'; *s1++ = '\0';
} }
} }
return n; return n;
@ -1517,7 +1513,7 @@ static void handle_special(var *v)
char *b, *sep, *s; char *b, *sep, *s;
int sl, l, len, i, bsize; int sl, l, len, i, bsize;
if (! (v->type & VF_SPECIAL)) if (!(v->type & VF_SPECIAL))
return; return;
if (v == V[NF]) { if (v == V[NF]) {
@ -1540,7 +1536,8 @@ static void handle_special(var *v)
memcpy(b+len, s, l); memcpy(b+len, s, l);
len += l; len += l;
} }
if (b) b[len] = '\0'; if (b)
b[len] = '\0';
setvar_p(V[F0], b); setvar_p(V[F0], b);
is_f0_split = TRUE; is_f0_split = TRUE;
@ -1556,7 +1553,7 @@ static void handle_special(var *v)
} else if (v == V[IGNORECASE]) { } else if (v == V[IGNORECASE]) {
icase = istrue(v); icase = istrue(v);
} else { /* $n */ } else { /* $n */
n = getvar_i(V[NF]); n = getvar_i(V[NF]);
setvar_i(V[NF], n > v-Fields ? n : v-Fields+1); setvar_i(V[NF], n > v-Fields ? n : v-Fields+1);
/* right here v is invalid. Just to note... */ /* right here v is invalid. Just to note... */
@ -1781,7 +1778,6 @@ static char *awk_printf(node *n)
/* if there was an error while sprintf, return value is negative */ /* if there was an error while sprintf, return value is negative */
if (i < j) i = j; if (i < j) i = j;
} }
b = xrealloc(b, i + 1); b = xrealloc(b, i + 1);
@ -1965,7 +1961,7 @@ static var *exec_builtin(node *op, var *res)
case B_up: case B_up:
to_xxx = toupper; to_xxx = toupper;
lo_cont: lo_cont:
s1 = s = xstrdup(as[0]); s1 = s = xstrdup(as[0]);
while (*s1) { while (*s1) {
*s1 = (*to_xxx)(*s1); *s1 = (*to_xxx)(*s1);
@ -2053,6 +2049,7 @@ static var *evaluate(node *op, var *res)
static var *fnargs = NULL; static var *fnargs = NULL;
static unsigned seed = 1; static unsigned seed = 1;
static regex_t sreg; static regex_t sreg;
node *op1; node *op1;
var *v1; var *v1;
union { union {
@ -2072,7 +2069,7 @@ static var *evaluate(node *op, var *res)
uint32_t info; uint32_t info;
} X; } X;
if (! op) if (!op)
return setvar_s(res, NULL); return setvar_s(res, NULL);
v1 = nvalloc(2); v1 = nvalloc(2);
@ -2224,9 +2221,8 @@ static var *evaluate(node *op, var *res)
case XC( OC_FNARG ): case XC( OC_FNARG ):
L.v = &fnargs[op->l.i]; L.v = &fnargs[op->l.i];
v_cont:
v_cont: res = op->r.n ? findvar(iamarray(L.v), R.s) : L.v;
res = (op->r.n) ? findvar(iamarray(L.v), R.s) : L.v;
break; break;
case XC( OC_IN ): case XC( OC_IN ):
@ -2240,7 +2236,7 @@ v_cont:
case XC( OC_MATCH ): case XC( OC_MATCH ):
op1 = op->r.n; op1 = op->r.n;
re_cont: re_cont:
X.re = as_regex(op1, &sreg); X.re = as_regex(op1, &sreg);
R.i = regexec(X.re, L.s, 0, NULL, 0); R.i = regexec(X.re, L.s, 0, NULL, 0);
if (X.re == &sreg) regfree(X.re); if (X.re == &sreg) regfree(X.re);