diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-06-14 12:38:36 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-06-14 12:38:36 +0200 |
commit | c28cafb18d4ecf079d77f15a7b8d9ba6d4241b5a (patch) | |
tree | eae9b646e6b934911c2a263b02bea9507d00b487 | |
parent | 7a4021debaa1f89c0ee2ad41f446a8234f8261c7 (diff) | |
download | busybox-w32-c28cafb18d4ecf079d77f15a7b8d9ba6d4241b5a.tar.gz busybox-w32-c28cafb18d4ecf079d77f15a7b8d9ba6d4241b5a.tar.bz2 busybox-w32-c28cafb18d4ecf079d77f15a7b8d9ba6d4241b5a.zip |
xargs: trivial code shrink
function old new delta
process_stdin 343 336 -7
process0_stdin 124 117 -7
xargs_main 807 787 -20
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | findutils/xargs.c | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/findutils/xargs.c b/findutils/xargs.c index 857773df9..5c2668553 100644 --- a/findutils/xargs.c +++ b/findutils/xargs.c | |||
@@ -150,7 +150,6 @@ static void store_param(char *s) | |||
150 | * (buf has extra byte at the end to accomodate terminating NUL | 150 | * (buf has extra byte at the end to accomodate terminating NUL |
151 | * of "tail characters" string). | 151 | * of "tail characters" string). |
152 | * Otherwise, the returned pointer points to NUL byte. | 152 | * Otherwise, the returned pointer points to NUL byte. |
153 | * The args[] vector is NULL-terminated. | ||
154 | * On entry, buf[] may contain some "seed chars" which are to become | 153 | * On entry, buf[] may contain some "seed chars" which are to become |
155 | * the beginning of the first parameter. | 154 | * the beginning of the first parameter. |
156 | */ | 155 | */ |
@@ -241,7 +240,7 @@ static char* FAST_FUNC process_stdin(int n_max_chars, int n_max_arg, char *buf) | |||
241 | } | 240 | } |
242 | ret: | 241 | ret: |
243 | *p = '\0'; | 242 | *p = '\0'; |
244 | store_param(NULL); | 243 | /* store_param(NULL) - caller will do it */ |
245 | dbg_msg("return:'%s'", s); | 244 | dbg_msg("return:'%s'", s); |
246 | return s; | 245 | return s; |
247 | } | 246 | } |
@@ -293,7 +292,7 @@ static char* FAST_FUNC process_stdin(int n_max_chars, int n_max_arg, char *buf) | |||
293 | } | 292 | } |
294 | ret: | 293 | ret: |
295 | *p = '\0'; | 294 | *p = '\0'; |
296 | store_param(NULL); | 295 | /* store_param(NULL) - caller will do it */ |
297 | dbg_msg("return:'%s'", s); | 296 | dbg_msg("return:'%s'", s); |
298 | return s; | 297 | return s; |
299 | } | 298 | } |
@@ -334,7 +333,7 @@ static char* FAST_FUNC process0_stdin(int n_max_chars, int n_max_arg, char *buf) | |||
334 | } | 333 | } |
335 | ret: | 334 | ret: |
336 | *p = '\0'; | 335 | *p = '\0'; |
337 | store_param(NULL); | 336 | /* store_param(NULL) - caller will do it */ |
338 | dbg_msg("return:'%s'", s); | 337 | dbg_msg("return:'%s'", s); |
339 | return s; | 338 | return s; |
340 | } | 339 | } |
@@ -461,13 +460,10 @@ int xargs_main(int argc, char **argv) | |||
461 | 460 | ||
462 | buf = xzalloc(n_max_chars + 1); | 461 | buf = xzalloc(n_max_chars + 1); |
463 | 462 | ||
463 | n_max_arg = n_max_chars; | ||
464 | if (opt & OPT_UPTO_NUMBER) { | 464 | if (opt & OPT_UPTO_NUMBER) { |
465 | n_max_arg = xatou_range(max_args, 1, INT_MAX); | 465 | n_max_arg = xatou_range(max_args, 1, INT_MAX); |
466 | if (n_max_arg < n_max_chars) | ||
467 | goto skip; | ||
468 | } | 466 | } |
469 | n_max_arg = n_max_chars; | ||
470 | skip: | ||
471 | 467 | ||
472 | /* Allocate pointers for execvp */ | 468 | /* Allocate pointers for execvp */ |
473 | /* We can statically allocate (argc + n_max_arg + 1) elements | 469 | /* We can statically allocate (argc + n_max_arg + 1) elements |
@@ -489,6 +485,7 @@ int xargs_main(int argc, char **argv) | |||
489 | 485 | ||
490 | G.idx = argc; | 486 | G.idx = argc; |
491 | rem = read_args(n_max_chars, n_max_arg, buf); | 487 | rem = read_args(n_max_chars, n_max_arg, buf); |
488 | store_param(NULL); | ||
492 | 489 | ||
493 | if (!G.args[argc]) { | 490 | if (!G.args[argc]) { |
494 | if (*rem != '\0') | 491 | if (*rem != '\0') |
@@ -499,10 +496,11 @@ int xargs_main(int argc, char **argv) | |||
499 | opt |= OPT_NO_EMPTY; | 496 | opt |= OPT_NO_EMPTY; |
500 | 497 | ||
501 | if (opt & (OPT_INTERACTIVE | OPT_VERBOSE)) { | 498 | if (opt & (OPT_INTERACTIVE | OPT_VERBOSE)) { |
502 | for (i = 0; G.args[i]; i++) { | 499 | const char *fmt = " %s" + 1; |
503 | if (i) | 500 | char **args = G.args; |
504 | bb_putchar_stderr(' '); | 501 | for (i = 0; args[i]; i++) { |
505 | fputs(G.args[i], stderr); | 502 | fprintf(stderr, fmt, args[i]); |
503 | fmt = " %s"; | ||
506 | } | 504 | } |
507 | if (!(opt & OPT_INTERACTIVE)) | 505 | if (!(opt & OPT_INTERACTIVE)) |
508 | bb_putchar_stderr('\n'); | 506 | bb_putchar_stderr('\n'); |