summaryrefslogtreecommitdiffhomepage
path: root/editors
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-03-12 16:57:06 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-03-12 16:57:06 +0100
commit39fe4d159920f9b1b4ee537479216dc331d73b9c (patch)
tree81d8fe21e86e72222962e3c93b4297845d33f7df /editors
parent58f108eb339957f58d5a6034d82b09c4d50b53e3 (diff)
awk: code shrink
function old new delta exec_builtin 1538 1489 -49 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'editors')
-rw-r--r--editors/awk.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/editors/awk.c b/editors/awk.c
index d7c114e05..2510192a6 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -2103,7 +2103,6 @@ static NOINLINE var *exec_builtin(node *op, var *res)
uint32_t isr, info;
int nargs;
time_t tt;
- char *s, *s1;
int i, l, ll, n;
tv = nvalloc(4);
@@ -2135,7 +2134,9 @@ static NOINLINE var *exec_builtin(node *op, var *res)
#endif
break;
- case B_sp:
+ case B_sp: {
+ char *s, *s1;
+
if (nargs > 2) {
spl = (an[2]->info & OPCLSMASK) == OC_REGEXP ?
an[2] : mk_splitter(getvar_s(evaluate(an[2], &tv[2])), &tspl);
@@ -2147,12 +2148,15 @@ static NOINLINE var *exec_builtin(node *op, var *res)
s1 = s;
clear_array(iamarray(av[1]));
for (i = 1; i <= n; i++)
- setari_u(av[1], i, nextword(&s1));
- free(s);
+ setari_u(av[1], i, nextword(&s));
+ free(s1);
setvar_i(res, n);
break;
+ }
+
+ case B_ss: {
+ char *s;
- case B_ss:
l = strlen(as[0]);
i = getvar_i(av[1]) - 1;
if (i > l)
@@ -2165,6 +2169,7 @@ static NOINLINE var *exec_builtin(node *op, var *res)
s = xstrndup(as[0]+i, n);
setvar_p(res, s);
break;
+ }
/* Bitwise ops must assume that operands are unsigned. GNU Awk 3.1.5:
* awk '{ print or(-1,1) }' gives "4.29497e+09", not "-2.xxxe+09" */
@@ -2193,7 +2198,8 @@ static NOINLINE var *exec_builtin(node *op, var *res)
break;
case B_lo:
- case B_up:
+ case B_up: {
+ char *s, *s1;
s1 = s = xstrdup(as[0]);
while (*s1) {
//*s1 = (info == B_up) ? toupper(*s1) : tolower(*s1);
@@ -2203,6 +2209,7 @@ static NOINLINE var *exec_builtin(node *op, var *res)
}
setvar_p(res, s);
break;
+ }
case B_ix:
n = 0;
@@ -2210,14 +2217,14 @@ static NOINLINE var *exec_builtin(node *op, var *res)
l = strlen(as[0]) - ll;
if (ll > 0 && l >= 0) {
if (!icase) {
- s = strstr(as[0], as[1]);
+ char *s = strstr(as[0], as[1]);
if (s)
n = (s - as[0]) + 1;
} else {
/* this piece of code is terribly slow and
* really should be rewritten
*/
- for (i=0; i<=l; i++) {
+ for (i = 0; i <= l; i++) {
if (strncasecmp(as[0]+i, as[1], ll) == 0) {
n = i+1;
break;