- if (argc <= 1) {
- dirAction( ".", NULL);
- }
-
- /* peel off the "find" */
- argc--;
- argv++;
-
- if (**argv != '-') {
- directory=*argv;
- argc--;
- argv++;
- }
-
- /* Parse any options */
- while (**argv == '-') {
- int stopit=FALSE;
- while (*++(*argv) && stopit==FALSE) switch (**argv) {
- case 'f':
- if (strcmp(*argv, "follow")==0) {
- argc--;
- argv++;
- dereferenceFlag=TRUE;
- }
- break;
- case 'n':
- if (strcmp(*argv, "name")==0) {
- if (argc-- > 1) {
- pattern=*(++argv);
- stopit=-TRUE;
- } else {
- fprintf(stderr, "Usage: %s\n", find_usage);
- exit( FALSE);
- }
+ int dereference = FALSE;
+ int i, firstopt, status = EXIT_SUCCESS;
+
+ for (firstopt = 1; firstopt < argc; firstopt++) {
+ if (argv[firstopt][0] == '-')
+ break;
+ }
+
+ /* Parse any options */
+ for (i = firstopt; i < argc; i++) {
+ if (strcmp(argv[i], "-follow") == 0)
+ dereference = TRUE;
+ else if (strcmp(argv[i], "-print") == 0) {
+ ;
+ }
+ else if (strcmp(argv[i], "-name") == 0) {
+ if (++i == argc)
+ error_msg_and_die("option `-name' requires an argument");
+ pattern = argv[i];
+#ifdef BB_FEATURE_FIND_TYPE
+ } else if (strcmp(argv[i], "-type") == 0) {
+ if (++i == argc)
+ error_msg_and_die("option `-type' requires an argument");
+ type_mask = find_type(argv[i]);
+#endif
+#ifdef BB_FEATURE_FIND_PERM
+ } else if (strcmp(argv[i], "-perm") == 0) {
+ char *end;
+ if (++i == argc)
+ error_msg_and_die("option `-perm' requires an argument");
+ perm_mask = strtol(argv[i], &end, 8);
+ if (end[0] != '\0')
+ error_msg_and_die("invalid argument `%s' to `-perm'", argv[i]);
+ if (perm_mask > 07777)
+ error_msg_and_die("invalid argument `%s' to `-perm'", argv[i]);
+ if ((perm_char = argv[i][0]) == '-')
+ perm_mask = -perm_mask;
+#endif
+#ifdef BB_FEATURE_FIND_MTIME
+ } else if (strcmp(argv[i], "-mtime") == 0) {
+ char *end;
+ if (++i == argc)
+ error_msg_and_die("option `-mtime' requires an argument");
+ mtime_days = strtol(argv[i], &end, 10);
+ if (end[0] != '\0')
+ error_msg_and_die("invalid argument `%s' to `-mtime'", argv[i]);
+ if ((mtime_char = argv[i][0]) == '-')
+ mtime_days = -mtime_days;
+#endif
+ } else
+ show_usage();
+ }
+
+ if (firstopt == 1) {
+ if (recursive_action(".", TRUE, dereference, FALSE, fileAction,
+ fileAction, NULL) == FALSE)
+ status = EXIT_FAILURE;
+ } else {
+ for (i = 1; i < firstopt; i++) {
+ if (recursive_action(argv[i], TRUE, dereference, FALSE, fileAction,
+ fileAction, NULL) == FALSE)
+ status = EXIT_FAILURE;