aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-07-18 18:31:11 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-07-18 18:31:11 +0000
commitb78c782c85705494634a936f6a9b0c6fcaf0860a (patch)
treef0d3440f7acc4b6fd25dcc2081c30f4146da1d3a
parent91afdf8096c3f3e434686d1b585ab5cde72c9f03 (diff)
downloadbusybox-w32-b78c782c85705494634a936f6a9b0c6fcaf0860a.tar.gz
busybox-w32-b78c782c85705494634a936f6a9b0c6fcaf0860a.tar.bz2
busybox-w32-b78c782c85705494634a936f6a9b0c6fcaf0860a.zip
awk: style fixes; remove one xstrdup/free pair; testsuite
-rw-r--r--editors/awk.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/editors/awk.c b/editors/awk.c
index 940a7948e..c087a5d4e 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -600,7 +600,7 @@ static void *hash_find(xhash *hash, const char *name)
600 int l; 600 int l;
601 601
602 hi = hash_search(hash, name); 602 hi = hash_search(hash, name);
603 if (! hi) { 603 if (!hi) {
604 if (++hash->nel / hash->csize > 10) 604 if (++hash->nel / hash->csize > 10)
605 hash_rebuild(hash); 605 hash_rebuild(hash);
606 606
@@ -1339,7 +1339,7 @@ static void chain_group(void)
1339 n3 = parse_expr(TC_SEQTERM); 1339 n3 = parse_expr(TC_SEQTERM);
1340 n = chain_loop(n3); 1340 n = chain_loop(n3);
1341 n->l.n = n2; 1341 n->l.n = n2;
1342 if (! n2) 1342 if (!n2)
1343 n->info = OC_EXEC; 1343 n->info = OC_EXEC;
1344 } 1344 }
1345 break; 1345 break;
@@ -1446,7 +1446,7 @@ static node *mk_splitter(const char *s, tsplitter *spl)
1446 n = &spl->n; 1446 n = &spl->n;
1447 if ((n->info & OPCLSMASK) == OC_REGEXP) { 1447 if ((n->info & OPCLSMASK) == OC_REGEXP) {
1448 regfree(re); 1448 regfree(re);
1449 regfree(ire); 1449 regfree(ire); // TODO: nuke ire, use re+1?
1450 } 1450 }
1451 if (strlen(s) > 1) { 1451 if (strlen(s) > 1) {
1452 mk_re_node(s, n, re); 1452 mk_re_node(s, n, re);
@@ -1511,7 +1511,7 @@ static int awk_split(const char *s, node *spl, char **slist)
1511 int l, n = 0; 1511 int l, n = 0;
1512 char c[4]; 1512 char c[4];
1513 char *s1; 1513 char *s1;
1514 regmatch_t pmatch[2]; 1514 regmatch_t pmatch[2]; // TODO: why [2]? [1] is enough...
1515 1515
1516 /* in worst case, each char would be a separate field */ 1516 /* in worst case, each char would be a separate field */
1517 *slist = s1 = xzalloc(strlen(s) * 2 + 3); 1517 *slist = s1 = xzalloc(strlen(s) * 2 + 3);
@@ -1732,7 +1732,7 @@ static int awk_getline(rstream *rsm, var *v)
1732 c = (char) rsplitter.n.info; 1732 c = (char) rsplitter.n.info;
1733 rp = 0; 1733 rp = 0;
1734 1734
1735 if (! m) qrealloc(&m, 256, &size); 1735 if (!m) qrealloc(&m, 256, &size);
1736 do { 1736 do {
1737 b = m + a; 1737 b = m + a;
1738 so = eo = p; 1738 so = eo = p;
@@ -1748,7 +1748,7 @@ static int awk_getline(rstream *rsm, var *v)
1748 } 1748 }
1749 } else if (c != '\0') { 1749 } else if (c != '\0') {
1750 s = strchr(b+pp, c); 1750 s = strchr(b+pp, c);
1751 if (! s) s = memchr(b+pp, '\0', p - pp); 1751 if (!s) s = memchr(b+pp, '\0', p - pp);
1752 if (s) { 1752 if (s) {
1753 so = eo = s-b; 1753 so = eo = s-b;
1754 eo++; 1754 eo++;
@@ -1900,8 +1900,8 @@ static int awk_sub(node *rn, const char *repl, int nm, var *src, var *dest, int
1900 regex_t sreg, *re; 1900 regex_t sreg, *re;
1901 1901
1902 re = as_regex(rn, &sreg); 1902 re = as_regex(rn, &sreg);
1903 if (! src) src = intvar[F0]; 1903 if (!src) src = intvar[F0];
1904 if (! dest) dest = intvar[F0]; 1904 if (!dest) dest = intvar[F0];
1905 1905
1906 i = di = 0; 1906 i = di = 0;
1907 sp = getvar_s(src); 1907 sp = getvar_s(src);
@@ -1946,7 +1946,8 @@ static int awk_sub(node *rn, const char *repl, int nm, var *src, var *dest, int
1946 sp += eo; 1946 sp += eo;
1947 if (i == nm) break; 1947 if (i == nm) break;
1948 if (eo == so) { 1948 if (eo == so) {
1949 if (! (ds[di++] = *sp++)) break; 1949 ds[di] = *sp++;
1950 if (!ds[di++]) break;
1950 } 1951 }
1951 } 1952 }
1952 1953
@@ -2797,13 +2798,16 @@ int awk_main(int argc, char **argv)
2797 2798
2798 /* Huh, people report that sometimes environ is NULL. Oh well. */ 2799 /* Huh, people report that sometimes environ is NULL. Oh well. */
2799 if (environ) for (envp = environ; *envp; envp++) { 2800 if (environ) for (envp = environ; *envp; envp++) {
2800 char *s = xstrdup(*envp); 2801 /* environ is writable, thus we don't strdup it needlessly */
2802 char *s = *envp;
2801 char *s1 = strchr(s, '='); 2803 char *s1 = strchr(s, '=');
2802 if (s1) { 2804 if (s1) {
2803 *s1++ = '\0'; 2805 *s1 = '\0';
2804 setvar_u(findvar(iamarray(intvar[ENVIRON]), s), s1); 2806 /* Both findvar and setvar_u take const char*
2807 * as 2nd arg -> environment is not trashed */
2808 setvar_u(findvar(iamarray(intvar[ENVIRON]), s), s1 + 1);
2809 *s1 = '=';
2805 } 2810 }
2806 free(s);
2807 } 2811 }
2808 opt_complementary = "v::"; 2812 opt_complementary = "v::";
2809 opt = getopt32(argc, argv, "F:v:f:W:", &opt_F, &opt_v, &g_progname, &opt_W); 2813 opt = getopt32(argc, argv, "F:v:f:W:", &opt_F, &opt_v, &g_progname, &opt_W);