aboutsummaryrefslogtreecommitdiff
path: root/findutils
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-03-17 09:09:09 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-03-17 09:09:09 +0000
commit1d42665b6b0571b9fa5d3b10fbf2dd03382f0ba2 (patch)
tree7ec8969fc2b07a2b7dc37f96435e5eddf7daf7fd /findutils
parent62a90cdd7435f09f4bb8673e8b7b213067f9d5cc (diff)
downloadbusybox-w32-1d42665b6b0571b9fa5d3b10fbf2dd03382f0ba2.tar.gz
busybox-w32-1d42665b6b0571b9fa5d3b10fbf2dd03382f0ba2.tar.bz2
busybox-w32-1d42665b6b0571b9fa5d3b10fbf2dd03382f0ba2.zip
*: shrink: use Vladimir's "o+" specifier instead of xatou(opt_param)
function old new delta getopt32 1370 1385 +15 sulogin_main 490 494 +4 realpath_main 84 86 +2 sleep_main 76 77 +1 mt_main 256 257 +1 printenv_main 75 74 -1 fdformat_main 546 545 -1 usleep_main 44 42 -2 setlogcons_main 77 75 -2 ed_main 2654 2649 -5 deallocvt_main 69 64 -5 addgroup_main 373 368 -5 mkfs_minix_main 2989 2982 -7 tail_main 1221 1213 -8 sv_main 1254 1241 -13 du_main 348 328 -20 tftp_main 325 302 -23 split_main 581 558 -23 nc_main 1000 977 -23 diff_main 891 868 -23 arping_main 1797 1770 -27 ls_main 893 847 -46 od_main 2797 2750 -47 readprofile_main 1944 1895 -49 tcpudpsvd_main 1973 1922 -51 udhcpc_main 2590 2513 -77 grep_main 824 722 -102 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 5/22 up/down: 23/-560) Total: -537 bytes text data bss dec hex filename 796973 658 7428 805059 c48c3 busybox_old 796479 662 7420 804561 c46d1 busybox_unstripped
Diffstat (limited to 'findutils')
-rw-r--r--findutils/grep.c48
1 files changed, 21 insertions, 27 deletions
diff --git a/findutils/grep.c b/findutils/grep.c
index c4cfcb852..259026ee5 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. 8 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
9 */ 9 */
10/* BB_AUDIT SUSv3 defects - unsupported option -x. */ 10/* BB_AUDIT SUSv3 defects - unsupported option -x "match whole line only". */
11/* BB_AUDIT GNU defects - always acts as -a. */ 11/* BB_AUDIT GNU defects - always acts as -a. */
12/* http://www.opengroup.org/onlinepubs/007904975/utilities/grep.html */ 12/* http://www.opengroup.org/onlinepubs/007904975/utilities/grep.html */
13/* 13/*
@@ -299,7 +299,7 @@ static int grep_file(FILE *file)
299 free(before_buf[curpos]); 299 free(before_buf[curpos]);
300 before_buf[curpos] = line; 300 before_buf[curpos] = line;
301 curpos = (curpos + 1) % lines_before; 301 curpos = (curpos + 1) % lines_before;
302 /* avoid free(line) - we took line */ 302 /* avoid free(line) - we took the line */
303 line = NULL; 303 line = NULL;
304 } 304 }
305 } 305 }
@@ -371,7 +371,10 @@ static void load_regexes_from_file(llist_t *fopt)
371 } 371 }
372} 372}
373 373
374static int file_action_grep(const char *filename, struct stat *statbuf ATTRIBUTE_UNUSED, void* matched, int depth ATTRIBUTE_UNUSED) 374static int file_action_grep(const char *filename,
375 struct stat *statbuf ATTRIBUTE_UNUSED,
376 void* matched,
377 int depth ATTRIBUTE_UNUSED)
375{ 378{
376 FILE *file = fopen(filename, "r"); 379 FILE *file = fopen(filename, "r");
377 if (file == NULL) { 380 if (file == NULL) {
@@ -405,35 +408,28 @@ int grep_main(int argc, char **argv)
405{ 408{
406 FILE *file; 409 FILE *file;
407 int matched; 410 int matched;
408 char *mopt;
409 llist_t *fopt = NULL; 411 llist_t *fopt = NULL;
410 412
411 /* do normal option parsing */ 413 /* do normal option parsing */
412#if ENABLE_FEATURE_GREP_CONTEXT 414#if ENABLE_FEATURE_GREP_CONTEXT
413 char *slines_after; 415 int Copt;
414 char *slines_before;
415 char *Copt;
416 416
417 opt_complementary = "H-h:e::f::C-AB"; 417 /* -H unsets -h; -C unsets -A,-B; -e,-f are lists;
418 * -m,-A,-B,-C have numeric param */
419 opt_complementary = "H-h:C-AB:e::f::m+:A+:B+:C+";
418 getopt32(argv, 420 getopt32(argv,
419 OPTSTR_GREP, 421 OPTSTR_GREP,
420 &pattern_head, &fopt, &mopt, 422 &pattern_head, &fopt, &max_matches,
421 &slines_after, &slines_before, &Copt); 423 &lines_after, &lines_before, &Copt);
422 424
423 if (option_mask32 & OPT_C) { 425 if (option_mask32 & OPT_C) {
424 /* -C unsets prev -A and -B, but following -A or -B 426 /* -C unsets prev -A and -B, but following -A or -B
425 may override it */ 427 may override it */
426 if (!(option_mask32 & OPT_A)) /* not overridden */ 428 if (!(option_mask32 & OPT_A)) /* not overridden */
427 slines_after = Copt; 429 lines_after = Copt;
428 if (!(option_mask32 & OPT_B)) /* not overridden */ 430 if (!(option_mask32 & OPT_B)) /* not overridden */
429 slines_before = Copt; 431 lines_before = Copt;
430 option_mask32 |= OPT_A|OPT_B; /* for parser */ 432 //option_mask32 |= OPT_A|OPT_B; /* for parser */
431 }
432 if (option_mask32 & OPT_A) {
433 lines_after = xatoi_u(slines_after);
434 }
435 if (option_mask32 & OPT_B) {
436 lines_before = xatoi_u(slines_before);
437 } 433 }
438 /* sanity checks */ 434 /* sanity checks */
439 if (option_mask32 & (OPT_c|OPT_q|OPT_l|OPT_L)) { 435 if (option_mask32 & (OPT_c|OPT_q|OPT_l|OPT_L)) {
@@ -444,13 +440,11 @@ int grep_main(int argc, char **argv)
444 before_buf = xzalloc(lines_before * sizeof(char *)); 440 before_buf = xzalloc(lines_before * sizeof(char *));
445#else 441#else
446 /* with auto sanity checks */ 442 /* with auto sanity checks */
447 opt_complementary = "H-h:e::f::c-n:q-n:l-n"; 443 /* -H unsets -h; -c,-q or -l unset -n; -e,-f are lists; -m N */
444 opt_complementary = "H-h:c-n:q-n:l-n:e::f::m+";
448 getopt32(argv, OPTSTR_GREP, 445 getopt32(argv, OPTSTR_GREP,
449 &pattern_head, &fopt, &mopt); 446 &pattern_head, &fopt, &max_matches);
450#endif 447#endif
451 if (option_mask32 & OPT_m) {
452 max_matches = xatoi_u(mopt);
453 }
454 invert_search = ((option_mask32 & OPT_v) != 0); /* 0 | 1 */ 448 invert_search = ((option_mask32 & OPT_v) != 0); /* 0 | 1 */
455 449
456 if (pattern_head != NULL) { 450 if (pattern_head != NULL) {
@@ -481,8 +475,8 @@ int grep_main(int argc, char **argv)
481 argv += optind; 475 argv += optind;
482 argc -= optind; 476 argc -= optind;
483 477
484 /* if we didn't get a pattern from a -e and no command file was specified, 478 /* if we didn't get a pattern from -e and no command file was specified,
485 * argv[optind] should be the pattern. no pattern, no worky */ 479 * first parameter should be the pattern. no pattern, no worky */
486 if (pattern_head == NULL) { 480 if (pattern_head == NULL) {
487 char *pattern; 481 char *pattern;
488 if (*argv == NULL) 482 if (*argv == NULL)
@@ -508,7 +502,7 @@ int grep_main(int argc, char **argv)
508 do { 502 do {
509 cur_file = *argv++; 503 cur_file = *argv++;
510 file = stdin; 504 file = stdin;
511 if (!cur_file || (*cur_file == '-' && !cur_file[1])) { 505 if (!cur_file || LONE_DASH(cur_file)) {
512 cur_file = "(standard input)"; 506 cur_file = "(standard input)";
513 } else { 507 } else {
514 if (option_mask32 & OPT_r) { 508 if (option_mask32 & OPT_r) {