aboutsummaryrefslogtreecommitdiff
path: root/findutils/find.c
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>2000-02-08 19:58:47 +0000
committerErik Andersen <andersen@codepoet.org>2000-02-08 19:58:47 +0000
commite49d5ecbbe51718fa925b6890a735e5937cc2aa2 (patch)
treec90bda10731ad9333ce3b404f993354c9fc104b8 /findutils/find.c
parentc0bf817bbc5c7867fbe8fb76d5c39f8ee802692f (diff)
downloadbusybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.tar.gz
busybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.tar.bz2
busybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.zip
Some formatting updates (ran the code through indent)
-Erik
Diffstat (limited to 'findutils/find.c')
-rw-r--r--findutils/find.c142
1 files changed, 73 insertions, 69 deletions
diff --git a/findutils/find.c b/findutils/find.c
index 50872b7f1..6346d454f 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* 2/*
2 * Mini find implementation for busybox 3 * Mini find implementation for busybox
3 * 4 *
@@ -28,92 +29,95 @@
28#include <dirent.h> 29#include <dirent.h>
29 30
30 31
31static char* pattern=NULL; 32static char *pattern = NULL;
32static char* directory="."; 33static char *directory = ".";
33static int dereferenceFlag=FALSE; 34static int dereferenceFlag = FALSE;
34 35
35static const char find_usage[] = "find [PATH...] [EXPRESSION]\n\n" 36static const char find_usage[] = "find [PATH...] [EXPRESSION]\n\n"
36"Search for files in a directory hierarchy. The default PATH is\n" 37 "Search for files in a directory hierarchy. The default PATH is\n"
37"the current directory; default EXPRESSION is '-print'\n\n" 38 "the current directory; default EXPRESSION is '-print'\n\n"
38"\nEXPRESSION may consist of:\n" 39 "\nEXPRESSION may consist of:\n"
39"\t-follow\n\t\tDereference symbolic links.\n" 40 "\t-follow\n\t\tDereference symbolic links.\n"
40"\t-name PATTERN\n\t\tFile name (with leading directories removed) matches PATTERN.\n" 41 "\t-name PATTERN\n\t\tFile name (with leading directories removed) matches PATTERN.\n"
41"\t-print\n\t\tprint the full file name followed by a newline to stdout.\n\n" 42 "\t-print\n\t\tprint the full file name followed by a newline to stdout.\n\n"
42#if defined BB_REGEXP 43#if defined BB_REGEXP
43"This version of find matches full regular expresions.\n"; 44 "This version of find matches full regular expresions.\n";
44#else 45#else
45"This version of find matches strings (not regular expresions).\n"; 46 "This version of find matches strings (not regular expresions).\n";
46#endif 47#endif
47 48
48 49
49 50
50static int fileAction(const char *fileName, struct stat* statbuf) 51static int fileAction(const char *fileName, struct stat *statbuf)
51{ 52{
52 if (pattern==NULL) 53 if (pattern == NULL)
53 fprintf(stdout, "%s\n", fileName); 54 fprintf(stdout, "%s\n", fileName);
54 else { 55 else {
55 char* tmp = strrchr( fileName, '/'); 56 char *tmp = strrchr(fileName, '/');
56 if (tmp == NULL) 57
57 tmp = (char*)fileName; 58 if (tmp == NULL)
58 else 59 tmp = (char *) fileName;
59 tmp++; 60 else
60 if (check_wildcard_match(tmp, pattern) == TRUE) 61 tmp++;
61 fprintf(stdout, "%s\n", fileName); 62 if (check_wildcard_match(tmp, pattern) == TRUE)
62 } 63 fprintf(stdout, "%s\n", fileName);
63 return( TRUE); 64 }
65 return (TRUE);
64} 66}
65 67
66int find_main(int argc, char **argv) 68int find_main(int argc, char **argv)
67{ 69{
68 /* peel off the "find" */ 70 /* peel off the "find" */
69 argc--;
70 argv++;
71
72 if ( argc > 0 && **argv != '-') {
73 directory = *argv;
74 argc--; 71 argc--;
75 argv++; 72 argv++;
76 }
77 73
78 /* Parse any options */ 74 if (argc > 0 && **argv != '-') {
79 while (argc > 0 && **argv == '-') { 75 directory = *argv;
80 int stopit=FALSE; 76 argc--;
81 while (*++(*argv) && stopit==FALSE) switch (**argv) { 77 argv++;
82 case 'f':
83 if (strcmp(*argv, "follow")==0) {
84 argc--;
85 argv++;
86 dereferenceFlag=TRUE;
87 }
88 break;
89 case 'n':
90 if (strcmp(*argv, "name")==0) {
91 if (argc-- > 1) {
92 pattern = *(++argv);
93 stopit = TRUE;
94 } else {
95 usage (find_usage);
96 }
97 }
98 break;
99 case '-':
100 /* Ignore all long options */
101 break;
102 default:
103 usage (find_usage);
104 } 78 }
105 if (argc-- > 1)
106 argv++;
107 if (**argv != '-')
108 break;
109 else
110 break;
111 }
112 79
113 if (recursiveAction(directory, TRUE, FALSE, FALSE, 80 /* Parse any options */
114 fileAction, fileAction) == FALSE) { 81 while (argc > 0 && **argv == '-') {
115 exit( FALSE); 82 int stopit = FALSE;
116 } 83
84 while (*++(*argv) && stopit == FALSE)
85 switch (**argv) {
86 case 'f':
87 if (strcmp(*argv, "follow") == 0) {
88 argc--;
89 argv++;
90 dereferenceFlag = TRUE;
91 }
92 break;
93 case 'n':
94 if (strcmp(*argv, "name") == 0) {
95 if (argc-- > 1) {
96 pattern = *(++argv);
97 stopit = TRUE;
98 } else {
99 usage(find_usage);
100 }
101 }
102 break;
103 case '-':
104 /* Ignore all long options */
105 break;
106 default:
107 usage(find_usage);
108 }
109 if (argc-- > 1)
110 argv++;
111 if (**argv != '-')
112 break;
113 else
114 break;
115 }
116
117 if (recursiveAction(directory, TRUE, FALSE, FALSE,
118 fileAction, fileAction) == FALSE) {
119 exit(FALSE);
120 }
117 121
118 exit(TRUE); 122 exit(TRUE);
119} 123}