diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-04-16 22:34:39 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-04-16 22:34:39 +0000 |
commit | c7b004ef7b6f0abdceeb863623c83300bdb0e59e (patch) | |
tree | 7b0d54cc6fa9cd93fdd53593d8324e7c86f705c8 /shell/hush.c | |
parent | 318604b951e5f74ff9889274d82f908ac5818fac (diff) | |
download | busybox-w32-c7b004ef7b6f0abdceeb863623c83300bdb0e59e.tar.gz busybox-w32-c7b004ef7b6f0abdceeb863623c83300bdb0e59e.tar.bz2 busybox-w32-c7b004ef7b6f0abdceeb863623c83300bdb0e59e.zip |
shells: remove few statics and duplicated code
(much more of the same remains, alas)
function old new delta
doset 330 332 +2
warn 53 51 -2
onecommand 463 461 -2
ioecho 40 38 -2
forkexec 1412 1410 -2
err 81 79 -2
setdash 59 56 -3
flag 4 - -4
msh_main 1389 1384 -5
eval 388 381 -7
subgetc 759 747 -12
static.local 14 - -14
b_adduint 70 52 -18
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 1/10 up/down: 2/-73) Total: -71 bytes
git-svn-id: svn://busybox.net/trunk/busybox@18462 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'shell/hush.c')
-rw-r--r-- | shell/hush.c | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/shell/hush.c b/shell/hush.c index 9489fb276..6173afc80 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -20,7 +20,6 @@ | |||
20 | * rewrites. | 20 | * rewrites. |
21 | * | 21 | * |
22 | * Other credits: | 22 | * Other credits: |
23 | * simple_itoa() was lifted from boa-0.93.15 | ||
24 | * b_addchr() derived from similar w_addchar function in glibc-2.2 | 23 | * b_addchr() derived from similar w_addchar function in glibc-2.2 |
25 | * setup_redirect(), redirect_opt_num(), and big chunks of main() | 24 | * setup_redirect(), redirect_opt_num(), and big chunks of main() |
26 | * and many builtins derived from contributions by Erik Andersen | 25 | * and many builtins derived from contributions by Erik Andersen |
@@ -280,7 +279,7 @@ struct built_in_command { | |||
280 | /* belongs in busybox.h */ | 279 | /* belongs in busybox.h */ |
281 | static int max(int a, int b) | 280 | static int max(int a, int b) |
282 | { | 281 | { |
283 | return (a>b)?a:b; | 282 | return (a > b) ? a : b; |
284 | } | 283 | } |
285 | 284 | ||
286 | /* This should be in utility.c */ | 285 | /* This should be in utility.c */ |
@@ -811,23 +810,12 @@ static int b_addqchr(o_string *o, int ch, int quote) | |||
811 | return b_addchr(o, ch); | 810 | return b_addchr(o, ch); |
812 | } | 811 | } |
813 | 812 | ||
814 | /* belongs in utility.c */ | ||
815 | static char *simple_itoa(unsigned i) | ||
816 | { | ||
817 | static char local[sizeof(int)*3 + 2]; | ||
818 | char *p = &local[sizeof(int)*3 + 2 - 1]; | ||
819 | *p-- = '\0'; | ||
820 | do { | ||
821 | *p-- = '0' + i % 10; | ||
822 | i /= 10; | ||
823 | } while (i > 0); | ||
824 | return p + 1; | ||
825 | } | ||
826 | |||
827 | static int b_adduint(o_string *o, unsigned i) | 813 | static int b_adduint(o_string *o, unsigned i) |
828 | { | 814 | { |
829 | int r; | 815 | int r; |
830 | char *p = simple_itoa(i); | 816 | char buf[sizeof(unsigned)*3 + 1]; |
817 | char *p = buf; | ||
818 | *(utoa_to_buf(i, buf, sizeof(buf))) = '\0'; | ||
831 | /* no escape checking necessary */ | 819 | /* no escape checking necessary */ |
832 | do r = b_addchr(o, *p++); while (r == 0 && *p); | 820 | do r = b_addchr(o, *p++); while (r == 0 && *p); |
833 | return r; | 821 | return r; |
@@ -2008,8 +1996,8 @@ static int reserved_word(o_string *dest, struct p_context *ctx) | |||
2008 | { "do", RES_DO, FLAG_DONE }, | 1996 | { "do", RES_DO, FLAG_DONE }, |
2009 | { "done", RES_DONE, FLAG_END } | 1997 | { "done", RES_DONE, FLAG_END } |
2010 | }; | 1998 | }; |
1999 | enum { NRES = sizeof(reserved_list)/sizeof(reserved_list[0]) }; | ||
2011 | const struct reserved_combo *r; | 2000 | const struct reserved_combo *r; |
2012 | #define NRES sizeof(reserved_list)/sizeof(reserved_list[0]) | ||
2013 | 2001 | ||
2014 | for (r = reserved_list; r < reserved_list+NRES; r++) { | 2002 | for (r = reserved_list; r < reserved_list+NRES; r++) { |
2015 | if (strcmp(dest->data, r->literal) == 0) { | 2003 | if (strcmp(dest->data, r->literal) == 0) { |
@@ -2113,11 +2101,13 @@ static int done_command(struct p_context *ctx) | |||
2113 | struct child_prog *prog = ctx->child; | 2101 | struct child_prog *prog = ctx->child; |
2114 | 2102 | ||
2115 | if (prog && prog->group == NULL | 2103 | if (prog && prog->group == NULL |
2116 | && prog->argv == NULL | 2104 | && prog->argv == NULL |
2117 | && prog->redirects == NULL) { | 2105 | && prog->redirects == NULL |
2106 | ) { | ||
2118 | debug_printf("done_command: skipping null command\n"); | 2107 | debug_printf("done_command: skipping null command\n"); |
2119 | return 0; | 2108 | return 0; |
2120 | } else if (prog) { | 2109 | } |
2110 | if (prog) { | ||
2121 | pi->num_progs++; | 2111 | pi->num_progs++; |
2122 | debug_printf("done_command: num_progs incremented to %d\n", pi->num_progs); | 2112 | debug_printf("done_command: num_progs incremented to %d\n", pi->num_progs); |
2123 | } else { | 2113 | } else { |
@@ -2172,7 +2162,7 @@ static int redirect_dup_num(struct in_str *input) | |||
2172 | return -3; /* "-" represents "close me" */ | 2162 | return -3; /* "-" represents "close me" */ |
2173 | } | 2163 | } |
2174 | while (isdigit(ch)) { | 2164 | while (isdigit(ch)) { |
2175 | d = d*10+(ch-'0'); | 2165 | d = d*10 + (ch-'0'); |
2176 | ok = 1; | 2166 | ok = 1; |
2177 | b_getch(input); | 2167 | b_getch(input); |
2178 | ch = b_peek(input); | 2168 | ch = b_peek(input); |
@@ -2226,7 +2216,7 @@ static FILE *generate_stream_from_list(struct pipe *head) | |||
2226 | } else if (pid == 0) { | 2216 | } else if (pid == 0) { |
2227 | close(channel[0]); | 2217 | close(channel[0]); |
2228 | if (channel[1] != 1) { | 2218 | if (channel[1] != 1) { |
2229 | dup2(channel[1],1); | 2219 | dup2(channel[1], 1); |
2230 | close(channel[1]); | 2220 | close(channel[1]); |
2231 | } | 2221 | } |
2232 | _exit(run_list_real(head)); /* leaks memory */ | 2222 | _exit(run_list_real(head)); /* leaks memory */ |