diff options
Diffstat (limited to 'findutils')
-rw-r--r-- | findutils/find.c | 23 | ||||
-rw-r--r-- | findutils/grep.c | 46 |
2 files changed, 22 insertions, 47 deletions
diff --git a/findutils/find.c b/findutils/find.c index 1db332297..c154cf4e7 100644 --- a/findutils/find.c +++ b/findutils/find.c | |||
@@ -21,14 +21,15 @@ | |||
21 | * | 21 | * |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include "internal.h" | ||
25 | #include "regexp.h" | ||
24 | #include <stdio.h> | 26 | #include <stdio.h> |
25 | #include <unistd.h> | 27 | #include <unistd.h> |
26 | #include <dirent.h> | 28 | #include <dirent.h> |
27 | #include "internal.h" | ||
28 | 29 | ||
29 | 30 | ||
30 | static char* pattern=NULL; | 31 | static char* pattern=NULL; |
31 | static char* directory=NULL; | 32 | static char* directory="."; |
32 | static int dereferenceFlag=FALSE; | 33 | static int dereferenceFlag=FALSE; |
33 | 34 | ||
34 | static const char find_usage[] = "find [path...] [expression]\n" | 35 | static const char find_usage[] = "find [path...] [expression]\n" |
@@ -41,7 +42,7 @@ static int fileAction(const char *fileName, struct stat* statbuf) | |||
41 | { | 42 | { |
42 | if (pattern==NULL) | 43 | if (pattern==NULL) |
43 | fprintf(stdout, "%s\n", fileName); | 44 | fprintf(stdout, "%s\n", fileName); |
44 | else if (match(fileName, pattern) == TRUE) | 45 | else if (find_match(fileName, pattern, TRUE) == TRUE) |
45 | fprintf(stdout, "%s\n", fileName); | 46 | fprintf(stdout, "%s\n", fileName); |
46 | return( TRUE); | 47 | return( TRUE); |
47 | } | 48 | } |
@@ -53,7 +54,7 @@ static int dirAction(const char *fileName, struct stat* statbuf) | |||
53 | 54 | ||
54 | if (pattern==NULL) | 55 | if (pattern==NULL) |
55 | fprintf(stdout, "%s\n", fileName); | 56 | fprintf(stdout, "%s\n", fileName); |
56 | else if (match(fileName, pattern) == TRUE) | 57 | else if (find_match(fileName, pattern, TRUE) == TRUE) |
57 | fprintf(stdout, "%s\n", fileName); | 58 | fprintf(stdout, "%s\n", fileName); |
58 | 59 | ||
59 | dir = opendir( fileName); | 60 | dir = opendir( fileName); |
@@ -71,22 +72,18 @@ static int dirAction(const char *fileName, struct stat* statbuf) | |||
71 | 72 | ||
72 | int find_main(int argc, char **argv) | 73 | int find_main(int argc, char **argv) |
73 | { | 74 | { |
74 | if (argc <= 1) { | ||
75 | dirAction( ".", NULL); | ||
76 | } | ||
77 | |||
78 | /* peel off the "find" */ | 75 | /* peel off the "find" */ |
79 | argc--; | 76 | argc--; |
80 | argv++; | 77 | argv++; |
81 | 78 | ||
82 | if (**argv != '-') { | 79 | if ( argc > 0 && **argv != '-') { |
83 | directory=*argv; | 80 | directory=*argv; |
84 | argc--; | 81 | argc--; |
85 | argv++; | 82 | argv++; |
86 | } | 83 | } |
87 | 84 | ||
88 | /* Parse any options */ | 85 | /* Parse any options */ |
89 | while (**argv == '-') { | 86 | while (argc > 0 && **argv == '-') { |
90 | int stopit=FALSE; | 87 | int stopit=FALSE; |
91 | while (*++(*argv) && stopit==FALSE) switch (**argv) { | 88 | while (*++(*argv) && stopit==FALSE) switch (**argv) { |
92 | case 'f': | 89 | case 'f': |
@@ -120,6 +117,10 @@ int find_main(int argc, char **argv) | |||
120 | break; | 117 | break; |
121 | } | 118 | } |
122 | 119 | ||
123 | dirAction( directory, NULL); | 120 | if (recursiveAction(directory, TRUE, FALSE, FALSE, |
121 | fileAction, fileAction) == FALSE) { | ||
122 | exit( FALSE); | ||
123 | } | ||
124 | |||
124 | exit(TRUE); | 125 | exit(TRUE); |
125 | } | 126 | } |
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 | ||