diff options
author | Eric Andersen <andersen@codepoet.org> | 1999-10-06 20:25:32 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 1999-10-06 20:25:32 +0000 |
commit | 17d49efd8ce6507152d78a70574193bb1b313af6 (patch) | |
tree | 64e24302dc2575867d8a78897500e5a5b2a48398 /findutils/find.c | |
parent | 9d3aba7b37b275350a9fe0887871da9ba73dcbd7 (diff) | |
download | busybox-w32-17d49efd8ce6507152d78a70574193bb1b313af6.tar.gz busybox-w32-17d49efd8ce6507152d78a70574193bb1b313af6.tar.bz2 busybox-w32-17d49efd8ce6507152d78a70574193bb1b313af6.zip |
More stuff.
Diffstat (limited to 'findutils/find.c')
-rw-r--r-- | findutils/find.c | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/findutils/find.c b/findutils/find.c index b3ac1ff5a..a42f9e979 100644 --- a/findutils/find.c +++ b/findutils/find.c | |||
@@ -1,3 +1,133 @@ | |||
1 | /* | ||
2 | * Mini find implementation for busybox | ||
3 | * | ||
4 | * Copyright (C) 1998 by Erik Andersen <andersee@debian.org> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | * | ||
20 | */ | ||
21 | |||
22 | #include <stdio.h> | ||
23 | #include <unistd.h> | ||
24 | #include <dirent.h> | ||
25 | #include "internal.h" | ||
26 | |||
27 | |||
28 | static char* pattern=NULL; | ||
29 | static char* directory=NULL; | ||
30 | int dereferenceFlag=FALSE; | ||
31 | |||
32 | static const char find_usage[] = "find [path...] [expression]\n" | ||
33 | "default path is the current directory; default expression is -print\n" | ||
34 | "expression may consist of:\n"; | ||
35 | |||
36 | |||
37 | |||
38 | static int fileAction(const char *fileName) | ||
39 | { | ||
40 | if (pattern==NULL) | ||
41 | fprintf(stdout, "%s\n", fileName); | ||
42 | else if (match(fileName, pattern) == TRUE) | ||
43 | fprintf(stdout, "%s\n", fileName); | ||
44 | return( TRUE); | ||
45 | } | ||
46 | |||
47 | static int dirAction(const char *fileName) | ||
48 | { | ||
49 | DIR *dir; | ||
50 | struct dirent *entry; | ||
51 | |||
52 | if (pattern==NULL) | ||
53 | fprintf(stdout, "%s\n", fileName); | ||
54 | else if (match(fileName, pattern) == TRUE) | ||
55 | fprintf(stdout, "%s\n", fileName); | ||
56 | |||
57 | dir = opendir( fileName); | ||
58 | if (!dir) { | ||
59 | perror("Can't open directory"); | ||
60 | exit(FALSE); | ||
61 | } | ||
62 | while ((entry = readdir(dir)) != NULL) { | ||
63 | char dirName[NAME_MAX]; | ||
64 | sprintf(dirName, "%s/%s", fileName, entry->d_name); | ||
65 | recursiveAction( dirName, TRUE, dereferenceFlag, fileAction, dirAction); | ||
66 | } | ||
67 | return( TRUE); | ||
68 | } | ||
69 | |||
70 | int find_main(int argc, char **argv) | ||
71 | { | ||
72 | if (argc <= 1) { | ||
73 | dirAction( "."); | ||
74 | } | ||
75 | |||
76 | /* peel off the "find" */ | ||
77 | argc--; | ||
78 | argv++; | ||
79 | |||
80 | if (**argv != '-') { | ||
81 | directory=*argv; | ||
82 | argc--; | ||
83 | argv++; | ||
84 | } | ||
85 | |||
86 | /* Parse any options */ | ||
87 | while (**argv == '-') { | ||
88 | int stopit=FALSE; | ||
89 | while (*++(*argv) && stopit==FALSE) switch (**argv) { | ||
90 | case 'f': | ||
91 | if (strcmp(*argv, "follow")==0) { | ||
92 | argc--; | ||
93 | argv++; | ||
94 | dereferenceFlag=TRUE; | ||
95 | } | ||
96 | break; | ||
97 | case 'n': | ||
98 | if (strcmp(*argv, "name")==0) { | ||
99 | if (argc-- > 1) { | ||
100 | pattern=*(++argv); | ||
101 | stopit=-TRUE; | ||
102 | } else { | ||
103 | fprintf(stderr, "Usage: %s\n", find_usage); | ||
104 | exit( FALSE); | ||
105 | } | ||
106 | } | ||
107 | break; | ||
108 | case '-': | ||
109 | /* Ignore all long options */ | ||
110 | break; | ||
111 | default: | ||
112 | fprintf(stderr, "Usage: %s\n", find_usage); | ||
113 | exit( FALSE); | ||
114 | } | ||
115 | if (argc-- > 1) | ||
116 | argv++; | ||
117 | if (**argv != '-') | ||
118 | break; | ||
119 | else | ||
120 | break; | ||
121 | } | ||
122 | |||
123 | dirAction( directory); | ||
124 | exit(TRUE); | ||
125 | } | ||
126 | |||
127 | |||
128 | |||
129 | #ifdef foobar | ||
130 | |||
1 | #include "internal.h" | 131 | #include "internal.h" |
2 | #include <errno.h> | 132 | #include <errno.h> |
3 | #include <stdio.h> | 133 | #include <stdio.h> |
@@ -21,3 +151,6 @@ find_fn(const struct FileInfo * i) | |||
21 | 151 | ||
22 | return(0); | 152 | return(0); |
23 | } | 153 | } |
154 | |||
155 | |||
156 | #endif | ||