diff options
author | Eric Andersen <andersen@codepoet.org> | 1999-10-22 04:30:20 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 1999-10-22 04:30:20 +0000 |
commit | aa0765e11bdeba5c5abf745369a8430c8311d60c (patch) | |
tree | 3593c1a2ff03bfa79982fa12b55c9489f969e057 /findutils/grep.c | |
parent | c49960189a04b73e033016bd0f43fbb950f800e1 (diff) | |
download | busybox-w32-aa0765e11bdeba5c5abf745369a8430c8311d60c.tar.gz busybox-w32-aa0765e11bdeba5c5abf745369a8430c8311d60c.tar.bz2 busybox-w32-aa0765e11bdeba5c5abf745369a8430c8311d60c.zip |
Added regexp support, fixed Changelog.
Diffstat (limited to 'findutils/grep.c')
-rw-r--r-- | findutils/grep.c | 46 |
1 files changed, 10 insertions, 36 deletions
diff --git a/findutils/grep.c b/findutils/grep.c index a495c62ae..44ca02834 100644 --- a/findutils/grep.c +++ b/findutils/grep.c | |||
@@ -22,6 +22,7 @@ | |||
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include "internal.h" | 24 | #include "internal.h" |
25 | #include "regexp.h" | ||
25 | #include <stdio.h> | 26 | #include <stdio.h> |
26 | #include <dirent.h> | 27 | #include <dirent.h> |
27 | #include <errno.h> | 28 | #include <errno.h> |
@@ -30,44 +31,17 @@ | |||
30 | #include <time.h> | 31 | #include <time.h> |
31 | #include <ctype.h> | 32 | #include <ctype.h> |
32 | 33 | ||
33 | |||
34 | static const char grep_usage[] = | 34 | static const char grep_usage[] = |
35 | "grep [-ihn]... PATTERN [FILE]...\n" | 35 | "grep [-ihn]... PATTERN [FILE]...\n" |
36 | "Search for PATTERN in each FILE or standard input.\n\n" | 36 | "Search for PATTERN in each FILE or standard input.\n\n" |
37 | "\t-h\tsuppress the prefixing filename on output\n" | 37 | "\t-h\tsuppress the prefixing filename on output\n" |
38 | "\t-i\tignore case distinctions\n" | 38 | "\t-i\tignore case distinctions\n" |
39 | "\t-n\tprint line number with output lines\n\n" | 39 | "\t-n\tprint line number with output lines\n\n" |
40 | #if defined BB_REGEXP | ||
41 | "This version of grep matches full regexps.\n"; | ||
42 | #else | ||
40 | "This version of grep matches strings (not full regexps).\n"; | 43 | "This version of grep matches strings (not full regexps).\n"; |
41 | 44 | #endif | |
42 | |||
43 | /* | ||
44 | * See if the specified needle is found in the specified haystack. | ||
45 | */ | ||
46 | static int search (const char *haystack, const char *needle, int ignoreCase) | ||
47 | { | ||
48 | |||
49 | if (ignoreCase == FALSE) { | ||
50 | haystack = strstr (haystack, needle); | ||
51 | if (haystack == NULL) | ||
52 | return FALSE; | ||
53 | return TRUE; | ||
54 | } else { | ||
55 | int i; | ||
56 | char needle1[BUF_SIZE]; | ||
57 | char haystack1[BUF_SIZE]; | ||
58 | |||
59 | strncpy( haystack1, haystack, sizeof(haystack1)); | ||
60 | strncpy( needle1, needle, sizeof(needle1)); | ||
61 | for( i=0; i<sizeof(haystack1) && haystack1[i]; i++) | ||
62 | haystack1[i]=tolower( haystack1[i]); | ||
63 | for( i=0; i<sizeof(needle1) && needle1[i]; i++) | ||
64 | needle1[i]=tolower( needle1[i]); | ||
65 | haystack = strstr (haystack1, needle1); | ||
66 | if (haystack == NULL) | ||
67 | return FALSE; | ||
68 | return TRUE; | ||
69 | } | ||
70 | } | ||
71 | 45 | ||
72 | 46 | ||
73 | extern int grep_main (int argc, char **argv) | 47 | extern int grep_main (int argc, char **argv) |
@@ -80,7 +54,7 @@ extern int grep_main (int argc, char **argv) | |||
80 | int ignoreCase=FALSE; | 54 | int ignoreCase=FALSE; |
81 | int tellLine=FALSE; | 55 | int tellLine=FALSE; |
82 | long line; | 56 | long line; |
83 | char buf[BUF_SIZE]; | 57 | char haystack[BUF_SIZE]; |
84 | 58 | ||
85 | ignoreCase = FALSE; | 59 | ignoreCase = FALSE; |
86 | tellLine = FALSE; | 60 | tellLine = FALSE; |
@@ -128,21 +102,21 @@ extern int grep_main (int argc, char **argv) | |||
128 | 102 | ||
129 | line = 0; | 103 | line = 0; |
130 | 104 | ||
131 | while (fgets (buf, sizeof (buf), fp)) { | 105 | while (fgets (haystack, sizeof (haystack), fp)) { |
132 | line++; | 106 | line++; |
133 | cp = &buf[strlen (buf) - 1]; | 107 | cp = &haystack[strlen (haystack) - 1]; |
134 | 108 | ||
135 | if (*cp != '\n') | 109 | if (*cp != '\n') |
136 | fprintf (stderr, "%s: Line too long\n", name); | 110 | fprintf (stderr, "%s: Line too long\n", name); |
137 | 111 | ||
138 | if (search (buf, needle, ignoreCase)==TRUE) { | 112 | if (find_match(haystack, needle, ignoreCase) == TRUE) { |
139 | if (tellName==TRUE) | 113 | if (tellName==TRUE) |
140 | printf ("%s: ", name); | 114 | printf ("%s: ", name); |
141 | 115 | ||
142 | if (tellLine==TRUE) | 116 | if (tellLine==TRUE) |
143 | printf ("%ld: ", line); | 117 | printf ("%ld: ", line); |
144 | 118 | ||
145 | fputs (buf, stdout); | 119 | fputs (haystack, stdout); |
146 | } | 120 | } |
147 | } | 121 | } |
148 | 122 | ||