aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Beppu <beppu@lbox.org>2000-04-24 18:07:30 +0000
committerJohn Beppu <beppu@lbox.org>2000-04-24 18:07:30 +0000
commitf93a95de6960b1d1977a934aafd3e9a8b8ea1765 (patch)
treed4e4a0cf3135af1926677c8f866b2bbab5a867f3
parente90f4045afbcdcae81c417fffa635b3a5ab9166b (diff)
downloadbusybox-w32-f93a95de6960b1d1977a934aafd3e9a8b8ea1765.tar.gz
busybox-w32-f93a95de6960b1d1977a934aafd3e9a8b8ea1765.tar.bz2
busybox-w32-f93a95de6960b1d1977a934aafd3e9a8b8ea1765.zip
+ grep -v # yay!
-rw-r--r--Changelog4
-rw-r--r--docs/busybox.pod3
-rw-r--r--findutils/grep.c27
-rw-r--r--grep.c27
4 files changed, 36 insertions, 25 deletions
diff --git a/Changelog b/Changelog
index d6f7a489c..823f9eef6 100644
--- a/Changelog
+++ b/Changelog
@@ -1,3 +1,7 @@
10.44
2 * added the -v option (inverted search) to grep,
3 updated docs/busybox.pod accordingly. -beppu
4
10.43 50.43
2 * Major update to the provided documentation. 6 * Major update to the provided documentation.
3 * Busybox now includes a shell! It currently costs 7.5 k (plus an 7 * Busybox now includes a shell! It currently costs 7.5 k (plus an
diff --git a/docs/busybox.pod b/docs/busybox.pod
index da890458c..71444c082 100644
--- a/docs/busybox.pod
+++ b/docs/busybox.pod
@@ -542,6 +542,7 @@ OPTIONS:
542 -i ignore case distinctions 542 -i ignore case distinctions
543 -n print line number with output lines 543 -n print line number with output lines
544 -q be quiet. Returns 0 if result was found, 1 otherwise 544 -q be quiet. Returns 0 if result was found, 1 otherwise
545 -v select non-matching lines
545 546
546This version of grep matches full regular expresions. 547This version of grep matches full regular expresions.
547 548
@@ -1816,4 +1817,4 @@ Enrique Zanardi <ezanardi@ull.es>
1816 1817
1817=cut 1818=cut
1818 1819
1819# $Id: busybox.pod,v 1.21 2000/04/21 21:53:58 erik Exp $ 1820# $Id: busybox.pod,v 1.22 2000/04/24 18:07:30 beppu Exp $
diff --git a/findutils/grep.c b/findutils/grep.c
index abdd44236..06b6980bc 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -47,7 +47,8 @@ static const char grep_usage[] =
47 "\t-h\tsuppress the prefixing filename on output\n" 47 "\t-h\tsuppress the prefixing filename on output\n"
48 "\t-i\tignore case distinctions\n" 48 "\t-i\tignore case distinctions\n"
49 "\t-n\tprint line number with output lines\n" 49 "\t-n\tprint line number with output lines\n"
50 "\t-q\tbe quiet. Returns 0 if result was found, 1 otherwise\n\n" 50 "\t-q\tbe quiet. Returns 0 if result was found, 1 otherwise\n"
51 "\t-v\tselect non-matching lines\n\n"
51#if defined BB_REGEXP 52#if defined BB_REGEXP
52 "This version of grep matches full regular expresions.\n"; 53 "This version of grep matches full regular expresions.\n";
53#else 54#else
@@ -57,11 +58,12 @@ static const char grep_usage[] =
57static int match = FALSE, beQuiet = FALSE; 58static int match = FALSE, beQuiet = FALSE;
58 59
59static void do_grep(FILE * fp, char *needle, char *fileName, int tellName, 60static void do_grep(FILE * fp, char *needle, char *fileName, int tellName,
60 int ignoreCase, int tellLine) 61 int ignoreCase, int tellLine, int invertSearch)
61{ 62{
62 char *cp; 63 char *cp;
63 long line = 0; 64 long line = 0;
64 char haystack[BUF_SIZE]; 65 char haystack[BUF_SIZE];
66 int truth = !invertSearch;
65 67
66 while (fgets(haystack, sizeof(haystack), fp)) { 68 while (fgets(haystack, sizeof(haystack), fp)) {
67 line++; 69 line++;
@@ -70,7 +72,7 @@ static void do_grep(FILE * fp, char *needle, char *fileName, int tellName,
70 if (*cp != '\n') 72 if (*cp != '\n')
71 fprintf(stderr, "%s: Line too long\n", fileName); 73 fprintf(stderr, "%s: Line too long\n", fileName);
72 74
73 if (find_match(haystack, needle, ignoreCase) == TRUE) { 75 if (find_match(haystack, needle, ignoreCase) == truth) {
74 if (tellName == TRUE) 76 if (tellName == TRUE)
75 printf("%s:", fileName); 77 printf("%s:", fileName);
76 78
@@ -92,13 +94,10 @@ extern int grep_main(int argc, char **argv)
92 char *cp; 94 char *cp;
93 char *needle; 95 char *needle;
94 char *fileName; 96 char *fileName;
95 int tellName = TRUE; 97 int tellName = TRUE;
96 int ignoreCase = TRUE; 98 int ignoreCase = FALSE;
97 int tellLine = FALSE; 99 int tellLine = FALSE;
98 100 int invertSearch = FALSE;
99
100 ignoreCase = FALSE;
101 tellLine = FALSE;
102 101
103 argc--; 102 argc--;
104 argv++; 103 argv++;
@@ -128,6 +127,10 @@ extern int grep_main(int argc, char **argv)
128 beQuiet = TRUE; 127 beQuiet = TRUE;
129 break; 128 break;
130 129
130 case 'v':
131 invertSearch = TRUE;
132 break;
133
131 default: 134 default:
132 usage(grep_usage); 135 usage(grep_usage);
133 } 136 }
@@ -137,7 +140,7 @@ extern int grep_main(int argc, char **argv)
137 argc--; 140 argc--;
138 141
139 if (argc == 0) { 142 if (argc == 0) {
140 do_grep(stdin, needle, "stdin", FALSE, ignoreCase, tellLine); 143 do_grep(stdin, needle, "stdin", FALSE, ignoreCase, tellLine, invertSearch);
141 } else { 144 } else {
142 /* Never print the filename for just one file */ 145 /* Never print the filename for just one file */
143 if (argc == 1) 146 if (argc == 1)
@@ -151,7 +154,7 @@ extern int grep_main(int argc, char **argv)
151 continue; 154 continue;
152 } 155 }
153 156
154 do_grep(fp, needle, fileName, tellName, ignoreCase, tellLine); 157 do_grep(fp, needle, fileName, tellName, ignoreCase, tellLine, invertSearch);
155 158
156 if (ferror(fp)) 159 if (ferror(fp))
157 perror(fileName); 160 perror(fileName);
diff --git a/grep.c b/grep.c
index abdd44236..06b6980bc 100644
--- a/grep.c
+++ b/grep.c
@@ -47,7 +47,8 @@ static const char grep_usage[] =
47 "\t-h\tsuppress the prefixing filename on output\n" 47 "\t-h\tsuppress the prefixing filename on output\n"
48 "\t-i\tignore case distinctions\n" 48 "\t-i\tignore case distinctions\n"
49 "\t-n\tprint line number with output lines\n" 49 "\t-n\tprint line number with output lines\n"
50 "\t-q\tbe quiet. Returns 0 if result was found, 1 otherwise\n\n" 50 "\t-q\tbe quiet. Returns 0 if result was found, 1 otherwise\n"
51 "\t-v\tselect non-matching lines\n\n"
51#if defined BB_REGEXP 52#if defined BB_REGEXP
52 "This version of grep matches full regular expresions.\n"; 53 "This version of grep matches full regular expresions.\n";
53#else 54#else
@@ -57,11 +58,12 @@ static const char grep_usage[] =
57static int match = FALSE, beQuiet = FALSE; 58static int match = FALSE, beQuiet = FALSE;
58 59
59static void do_grep(FILE * fp, char *needle, char *fileName, int tellName, 60static void do_grep(FILE * fp, char *needle, char *fileName, int tellName,
60 int ignoreCase, int tellLine) 61 int ignoreCase, int tellLine, int invertSearch)
61{ 62{
62 char *cp; 63 char *cp;
63 long line = 0; 64 long line = 0;
64 char haystack[BUF_SIZE]; 65 char haystack[BUF_SIZE];
66 int truth = !invertSearch;
65 67
66 while (fgets(haystack, sizeof(haystack), fp)) { 68 while (fgets(haystack, sizeof(haystack), fp)) {
67 line++; 69 line++;
@@ -70,7 +72,7 @@ static void do_grep(FILE * fp, char *needle, char *fileName, int tellName,
70 if (*cp != '\n') 72 if (*cp != '\n')
71 fprintf(stderr, "%s: Line too long\n", fileName); 73 fprintf(stderr, "%s: Line too long\n", fileName);
72 74
73 if (find_match(haystack, needle, ignoreCase) == TRUE) { 75 if (find_match(haystack, needle, ignoreCase) == truth) {
74 if (tellName == TRUE) 76 if (tellName == TRUE)
75 printf("%s:", fileName); 77 printf("%s:", fileName);
76 78
@@ -92,13 +94,10 @@ extern int grep_main(int argc, char **argv)
92 char *cp; 94 char *cp;
93 char *needle; 95 char *needle;
94 char *fileName; 96 char *fileName;
95 int tellName = TRUE; 97 int tellName = TRUE;
96 int ignoreCase = TRUE; 98 int ignoreCase = FALSE;
97 int tellLine = FALSE; 99 int tellLine = FALSE;
98 100 int invertSearch = FALSE;
99
100 ignoreCase = FALSE;
101 tellLine = FALSE;
102 101
103 argc--; 102 argc--;
104 argv++; 103 argv++;
@@ -128,6 +127,10 @@ extern int grep_main(int argc, char **argv)
128 beQuiet = TRUE; 127 beQuiet = TRUE;
129 break; 128 break;
130 129
130 case 'v':
131 invertSearch = TRUE;
132 break;
133
131 default: 134 default:
132 usage(grep_usage); 135 usage(grep_usage);
133 } 136 }
@@ -137,7 +140,7 @@ extern int grep_main(int argc, char **argv)
137 argc--; 140 argc--;
138 141
139 if (argc == 0) { 142 if (argc == 0) {
140 do_grep(stdin, needle, "stdin", FALSE, ignoreCase, tellLine); 143 do_grep(stdin, needle, "stdin", FALSE, ignoreCase, tellLine, invertSearch);
141 } else { 144 } else {
142 /* Never print the filename for just one file */ 145 /* Never print the filename for just one file */
143 if (argc == 1) 146 if (argc == 1)
@@ -151,7 +154,7 @@ extern int grep_main(int argc, char **argv)
151 continue; 154 continue;
152 } 155 }
153 156
154 do_grep(fp, needle, fileName, tellName, ignoreCase, tellLine); 157 do_grep(fp, needle, fileName, tellName, ignoreCase, tellLine, invertSearch);
155 158
156 if (ferror(fp)) 159 if (ferror(fp))
157 perror(fileName); 160 perror(fileName);