aboutsummaryrefslogtreecommitdiff
path: root/editors/awk.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-01-01 23:53:52 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-01-01 23:53:52 +0000
commite1d3e034a922d2f88cdb8f9aae51acecacf3d749 (patch)
treedbbc43770fb3088099d9cd1b4bf90cba0ada3601 /editors/awk.c
parent6dc6ebbf44f01f31b683ddde36f0ba694b98bbdd (diff)
downloadbusybox-w32-e1d3e034a922d2f88cdb8f9aae51acecacf3d749.tar.gz
busybox-w32-e1d3e034a922d2f88cdb8f9aae51acecacf3d749.tar.bz2
busybox-w32-e1d3e034a922d2f88cdb8f9aae51acecacf3d749.zip
awk: style fixes
Diffstat (limited to 'editors/awk.c')
-rw-r--r--editors/awk.c50
1 files changed, 23 insertions, 27 deletions
diff --git a/editors/awk.c b/editors/awk.c
index f48b0e43f..f8b26662a 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -848,20 +848,16 @@ static uint32_t next_token(uint32_t expected)
848 int l; 848 int l;
849 849
850 if (t.rollback) { 850 if (t.rollback) {
851
852 t.rollback = FALSE; 851 t.rollback = FALSE;
853 852
854 } else if (concat_inserted) { 853 } else if (concat_inserted) {
855
856 concat_inserted = FALSE; 854 concat_inserted = FALSE;
857 t.tclass = save_tclass; 855 t.tclass = save_tclass;
858 t.info = save_info; 856 t.info = save_info;
859 857
860 } else { 858 } else {
861
862 p = pos; 859 p = pos;
863 860 readnext:
864 readnext:
865 skip_spaces(&p); 861 skip_spaces(&p);
866 lineno = t.lineno; 862 lineno = t.lineno;
867 if (*p == '#') 863 if (*p == '#')
@@ -939,7 +935,7 @@ static uint32_t next_token(uint32_t expected)
939 /* it's a name (var/array/function), 935 /* it's a name (var/array/function),
940 * otherwise it's something wrong 936 * otherwise it's something wrong
941 */ 937 */
942 if (! isalnum_(*p)) 938 if (!isalnum_(*p))
943 syntax_error(EMSG_UNEXP_TOKEN); 939 syntax_error(EMSG_UNEXP_TOKEN);
944 940
945 t.string = --p; 941 t.string = --p;
@@ -949,7 +945,7 @@ static uint32_t next_token(uint32_t expected)
949 *(p-1) = '\0'; 945 *(p-1) = '\0';
950 tc = TC_VARIABLE; 946 tc = TC_VARIABLE;
951 /* also consume whitespace between functionname and bracket */ 947 /* also consume whitespace between functionname and bracket */
952 if (! (expected & TC_VARIABLE)) skip_spaces(&p); 948 if (!(expected & TC_VARIABLE)) skip_spaces(&p);
953 if (*p == '(') { 949 if (*p == '(') {
954 tc = TC_FUNCTION; 950 tc = TC_FUNCTION;
955 } else { 951 } else {
@@ -1395,14 +1391,14 @@ static regex_t *as_regex(node *op, regex_t *preg)
1395/* gradually increasing buffer */ 1391/* gradually increasing buffer */
1396static void qrealloc(char **b, int n, int *size) 1392static void qrealloc(char **b, int n, int *size)
1397{ 1393{
1398 if (! *b || n >= *size) 1394 if (!*b || n >= *size)
1399 *b = xrealloc(*b, *size = n + (n>>1) + 80); 1395 *b = xrealloc(*b, *size = n + (n>>1) + 80);
1400} 1396}
1401 1397
1402/* resize field storage space */ 1398/* resize field storage space */
1403static void fsrealloc(int size) 1399static void fsrealloc(int size)
1404{ 1400{
1405 static int maxfields = 0; 1401 static int maxfields; /* = 0;*/
1406 int i; 1402 int i;
1407 1403
1408 if (size >= maxfields) { 1404 if (size >= maxfields) {
@@ -1416,8 +1412,8 @@ static void fsrealloc(int size)
1416 } 1412 }
1417 1413
1418 if (size < nfields) { 1414 if (size < nfields) {
1419 for (i=size; i<nfields; i++) { 1415 for (i = size; i < nfields; i++) {
1420 clrvar(Fields+i); 1416 clrvar(Fields + i);
1421 } 1417 }
1422 } 1418 }
1423 nfields = size; 1419 nfields = size;
@@ -1457,8 +1453,8 @@ static int awk_split(char *s, node *spl, char **slist)
1457 } 1453 }
1458 } else if (c[0] == '\0') { /* null split */ 1454 } else if (c[0] == '\0') { /* null split */
1459 while (*s) { 1455 while (*s) {
1460 *(s1++) = *(s++); 1456 *s1++ = *s++;
1461 *(s1++) = '\0'; 1457 *s1++ = '\0';
1462 n++; 1458 n++;
1463 } 1459 }
1464 } else if (c[0] != ' ') { /* single-character split */ 1460 } else if (c[0] != ' ') { /* single-character split */
@@ -1468,17 +1464,17 @@ static int awk_split(char *s, node *spl, char **slist)
1468 } 1464 }
1469 if (*s1) n++; 1465 if (*s1) n++;
1470 while ((s1 = strpbrk(s1, c))) { 1466 while ((s1 = strpbrk(s1, c))) {
1471 *(s1++) = '\0'; 1467 *s1++ = '\0';
1472 n++; 1468 n++;
1473 } 1469 }
1474 } else { /* space split */ 1470 } else { /* space split */
1475 while (*s) { 1471 while (*s) {
1476 s = skip_whitespace(s); 1472 s = skip_whitespace(s);
1477 if (! *s) break; 1473 if (!*s) break;
1478 n++; 1474 n++;
1479 while (*s && !isspace(*s)) 1475 while (*s && !isspace(*s))
1480 *(s1++) = *(s++); 1476 *s1++ = *s++;
1481 *(s1++) = '\0'; 1477 *s1++ = '\0';
1482 } 1478 }
1483 } 1479 }
1484 return n; 1480 return n;
@@ -1517,7 +1513,7 @@ static void handle_special(var *v)
1517 char *b, *sep, *s; 1513 char *b, *sep, *s;
1518 int sl, l, len, i, bsize; 1514 int sl, l, len, i, bsize;
1519 1515
1520 if (! (v->type & VF_SPECIAL)) 1516 if (!(v->type & VF_SPECIAL))
1521 return; 1517 return;
1522 1518
1523 if (v == V[NF]) { 1519 if (v == V[NF]) {
@@ -1540,7 +1536,8 @@ static void handle_special(var *v)
1540 memcpy(b+len, s, l); 1536 memcpy(b+len, s, l);
1541 len += l; 1537 len += l;
1542 } 1538 }
1543 if (b) b[len] = '\0'; 1539 if (b)
1540 b[len] = '\0';
1544 setvar_p(V[F0], b); 1541 setvar_p(V[F0], b);
1545 is_f0_split = TRUE; 1542 is_f0_split = TRUE;
1546 1543
@@ -1556,7 +1553,7 @@ static void handle_special(var *v)
1556 } else if (v == V[IGNORECASE]) { 1553 } else if (v == V[IGNORECASE]) {
1557 icase = istrue(v); 1554 icase = istrue(v);
1558 1555
1559 } else { /* $n */ 1556 } else { /* $n */
1560 n = getvar_i(V[NF]); 1557 n = getvar_i(V[NF]);
1561 setvar_i(V[NF], n > v-Fields ? n : v-Fields+1); 1558 setvar_i(V[NF], n > v-Fields ? n : v-Fields+1);
1562 /* right here v is invalid. Just to note... */ 1559 /* right here v is invalid. Just to note... */
@@ -1781,7 +1778,6 @@ static char *awk_printf(node *n)
1781 1778
1782 /* if there was an error while sprintf, return value is negative */ 1779 /* if there was an error while sprintf, return value is negative */
1783 if (i < j) i = j; 1780 if (i < j) i = j;
1784
1785 } 1781 }
1786 1782
1787 b = xrealloc(b, i + 1); 1783 b = xrealloc(b, i + 1);
@@ -1965,7 +1961,7 @@ static var *exec_builtin(node *op, var *res)
1965 1961
1966 case B_up: 1962 case B_up:
1967 to_xxx = toupper; 1963 to_xxx = toupper;
1968lo_cont: 1964 lo_cont:
1969 s1 = s = xstrdup(as[0]); 1965 s1 = s = xstrdup(as[0]);
1970 while (*s1) { 1966 while (*s1) {
1971 *s1 = (*to_xxx)(*s1); 1967 *s1 = (*to_xxx)(*s1);
@@ -2053,6 +2049,7 @@ static var *evaluate(node *op, var *res)
2053 static var *fnargs = NULL; 2049 static var *fnargs = NULL;
2054 static unsigned seed = 1; 2050 static unsigned seed = 1;
2055 static regex_t sreg; 2051 static regex_t sreg;
2052
2056 node *op1; 2053 node *op1;
2057 var *v1; 2054 var *v1;
2058 union { 2055 union {
@@ -2072,7 +2069,7 @@ static var *evaluate(node *op, var *res)
2072 uint32_t info; 2069 uint32_t info;
2073 } X; 2070 } X;
2074 2071
2075 if (! op) 2072 if (!op)
2076 return setvar_s(res, NULL); 2073 return setvar_s(res, NULL);
2077 2074
2078 v1 = nvalloc(2); 2075 v1 = nvalloc(2);
@@ -2224,9 +2221,8 @@ static var *evaluate(node *op, var *res)
2224 2221
2225 case XC( OC_FNARG ): 2222 case XC( OC_FNARG ):
2226 L.v = &fnargs[op->l.i]; 2223 L.v = &fnargs[op->l.i];
2227 2224 v_cont:
2228v_cont: 2225 res = op->r.n ? findvar(iamarray(L.v), R.s) : L.v;
2229 res = (op->r.n) ? findvar(iamarray(L.v), R.s) : L.v;
2230 break; 2226 break;
2231 2227
2232 case XC( OC_IN ): 2228 case XC( OC_IN ):
@@ -2240,7 +2236,7 @@ v_cont:
2240 2236
2241 case XC( OC_MATCH ): 2237 case XC( OC_MATCH ):
2242 op1 = op->r.n; 2238 op1 = op->r.n;
2243re_cont: 2239 re_cont:
2244 X.re = as_regex(op1, &sreg); 2240 X.re = as_regex(op1, &sreg);
2245 R.i = regexec(X.re, L.s, 0, NULL, 0); 2241 R.i = regexec(X.re, L.s, 0, NULL, 0);
2246 if (X.re == &sreg) regfree(X.re); 2242 if (X.re == &sreg) regfree(X.re);