2 * Mini find implementation for busybox
5 * Copyright (C) 1999 by Lineo, inc.
6 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 static char* pattern=NULL;
31 static char* directory=NULL;
32 static int dereferenceFlag=FALSE;
34 static const char find_usage[] = "find [path...] [expression]\n"
35 "default path is the current directory; default expression is -print\n"
36 "expression may consist of:\n";
40 static int fileAction(const char *fileName, struct stat* statbuf)
43 fprintf(stdout, "%s\n", fileName);
44 else if (match(fileName, pattern) == TRUE)
45 fprintf(stdout, "%s\n", fileName);
49 static int dirAction(const char *fileName, struct stat* statbuf)
55 fprintf(stdout, "%s\n", fileName);
56 else if (match(fileName, pattern) == TRUE)
57 fprintf(stdout, "%s\n", fileName);
59 dir = opendir( fileName);
61 perror("Can't open directory");
64 while ((entry = readdir(dir)) != NULL) {
65 char dirName[NAME_MAX];
66 sprintf(dirName, "%s/%s", fileName, entry->d_name);
67 recursiveAction( dirName, TRUE, dereferenceFlag, FALSE, fileAction, dirAction);
72 int find_main(int argc, char **argv)
75 dirAction( ".", NULL);
78 /* peel off the "find" */
88 /* Parse any options */
89 while (**argv == '-') {
91 while (*++(*argv) && stopit==FALSE) switch (**argv) {
93 if (strcmp(*argv, "follow")==0) {
100 if (strcmp(*argv, "name")==0) {
110 /* Ignore all long options */
123 dirAction( directory, NULL);