aboutsummaryrefslogtreecommitdiff
path: root/findutils/grep.c
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/grep.c
parent62a90cdd7435f09f4bb8673e8b7b213067f9d5cc (diff)
downloadbusybox-1d42665b6b0571b9fa5d3b10fbf2dd03382f0ba2.tar.gz
*: 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/grep.c')
-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 @@
*
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
*/
-/* BB_AUDIT SUSv3 defects - unsupported option -x. */
+/* BB_AUDIT SUSv3 defects - unsupported option -x "match whole line only". */
/* BB_AUDIT GNU defects - always acts as -a. */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/grep.html */
/*
@@ -299,7 +299,7 @@ static int grep_file(FILE *file)
free(before_buf[curpos]);
before_buf[curpos] = line;
curpos = (curpos + 1) % lines_before;
- /* avoid free(line) - we took line */
+ /* avoid free(line) - we took the line */
line = NULL;
}
}
@@ -371,7 +371,10 @@ static void load_regexes_from_file(llist_t *fopt)
}
}
-static int file_action_grep(const char *filename, struct stat *statbuf ATTRIBUTE_UNUSED, void* matched, int depth ATTRIBUTE_UNUSED)
+static int file_action_grep(const char *filename,
+ struct stat *statbuf ATTRIBUTE_UNUSED,
+ void* matched,
+ int depth ATTRIBUTE_UNUSED)
{
FILE *file = fopen(filename, "r");
if (file == NULL) {
@@ -405,35 +408,28 @@ int grep_main(int argc, char **argv)
{
FILE *file;
int matched;
- char *mopt;
llist_t *fopt = NULL;
/* do normal option parsing */
#if ENABLE_FEATURE_GREP_CONTEXT
- char *slines_after;
- char *slines_before;
- char *Copt;
+ int Copt;
- opt_complementary = "H-h:e::f::C-AB";
+ /* -H unsets -h; -C unsets -A,-B; -e,-f are lists;
+ * -m,-A,-B,-C have numeric param */
+ opt_complementary = "H-h:C-AB:e::f::m+:A+:B+:C+";
getopt32(argv,
OPTSTR_GREP,
- &pattern_head, &fopt, &mopt,
- &slines_after, &slines_before, &Copt);
+ &pattern_head, &fopt, &max_matches,
+ &lines_after, &lines_before, &Copt);
if (option_mask32 & OPT_C) {
/* -C unsets prev -A and -B, but following -A or -B
may override it */
if (!(option_mask32 & OPT_A)) /* not overridden */
- slines_after = Copt;
+ lines_after = Copt;
if (!(option_mask32 & OPT_B)) /* not overridden */
- slines_before = Copt;
- option_mask32 |= OPT_A|OPT_B; /* for parser */
- }
- if (option_mask32 & OPT_A) {
- lines_after = xatoi_u(slines_after);
- }
- if (option_mask32 & OPT_B) {
- lines_before = xatoi_u(slines_before);
+ lines_before = Copt;
+ //option_mask32 |= OPT_A|OPT_B; /* for parser */
}
/* sanity checks */
if (option_mask32 & (OPT_c|OPT_q|OPT_l|OPT_L)) {
@@ -444,13 +440,11 @@ int grep_main(int argc, char **argv)
before_buf = xzalloc(lines_before * sizeof(char *));
#else
/* with auto sanity checks */
- opt_complementary = "H-h:e::f::c-n:q-n:l-n";
+ /* -H unsets -h; -c,-q or -l unset -n; -e,-f are lists; -m N */
+ opt_complementary = "H-h:c-n:q-n:l-n:e::f::m+";
getopt32(argv, OPTSTR_GREP,
- &pattern_head, &fopt, &mopt);
+ &pattern_head, &fopt, &max_matches);
#endif
- if (option_mask32 & OPT_m) {
- max_matches = xatoi_u(mopt);
- }
invert_search = ((option_mask32 & OPT_v) != 0); /* 0 | 1 */
if (pattern_head != NULL) {
@@ -481,8 +475,8 @@ int grep_main(int argc, char **argv)
argv += optind;
argc -= optind;
- /* if we didn't get a pattern from a -e and no command file was specified,
- * argv[optind] should be the pattern. no pattern, no worky */
+ /* if we didn't get a pattern from -e and no command file was specified,
+ * first parameter should be the pattern. no pattern, no worky */
if (pattern_head == NULL) {
char *pattern;
if (*argv == NULL)
@@ -508,7 +502,7 @@ int grep_main(int argc, char **argv)
do {
cur_file = *argv++;
file = stdin;
- if (!cur_file || (*cur_file == '-' && !cur_file[1])) {
+ if (!cur_file || LONE_DASH(cur_file)) {
cur_file = "(standard input)";
} else {
if (option_mask32 & OPT_r) {