2 * Mini find implementation for busybox
4 * Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
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.
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.
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
28 static char* pattern=NULL;
29 static char* directory=NULL;
30 static int dereferenceFlag=FALSE;
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";
38 static int fileAction(const char *fileName)
41 fprintf(stdout, "%s\n", fileName);
42 else if (match(fileName, pattern) == TRUE)
43 fprintf(stdout, "%s\n", fileName);
47 static int dirAction(const char *fileName)
53 fprintf(stdout, "%s\n", fileName);
54 else if (match(fileName, pattern) == TRUE)
55 fprintf(stdout, "%s\n", fileName);
57 dir = opendir( fileName);
59 perror("Can't open directory");
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);
70 int find_main(int argc, char **argv)
76 /* peel off the "find" */
86 /* Parse any options */
87 while (**argv == '-') {
89 while (*++(*argv) && stopit==FALSE) switch (**argv) {
91 if (strcmp(*argv, "follow")==0) {
98 if (strcmp(*argv, "name")==0) {
103 fprintf(stderr, "Usage: %s\n", find_usage);
109 /* Ignore all long options */
112 fprintf(stderr, "Usage: %s\n", find_usage);
123 dirAction( directory);
131 #include "internal.h"
135 const char find_usage[] = "find dir [pattern]\n"
140 find_main(struct FileInfo * i, int argc, char * * argv)
143 i->processDirectoriesAfterTheirContents=1;
144 return monadic_main(i, argc, argv);
148 find_fn(const struct FileInfo * i)
150 printf("%s\n",i->source);