postorder find fails because of a missing `break'
[unix-history] / usr / src / usr.bin / find / find.c
index bc25d5b..36f0de6 100644 (file)
@@ -15,25 +15,23 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)find.c     4.26 (Berkeley) %G%";
+static char sccsid[] = "@(#)find.c     4.33 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fts.h>
 #include <stdio.h>
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fts.h>
 #include <stdio.h>
-#include <strings.h>
+#include <string.h>
 #include <errno.h>
 #include "find.h"
 
 FTS *tree;                     /* pointer to top of FTS hierarchy */
 time_t now;                    /* time find was run */
 #include <errno.h>
 #include "find.h"
 
 FTS *tree;                     /* pointer to top of FTS hierarchy */
 time_t now;                    /* time find was run */
-dev_t curdev = (dev_t)-1;      /* device number of current tree */
 int ftsoptions;                        /* options passed to ftsopen() */
 int deprecated;                        /* old or new syntax */
 int depth;                     /* set by -depth option */
 int output_specified;          /* one of -print, -ok or -exec was specified */
 int ftsoptions;                        /* options passed to ftsopen() */
 int deprecated;                        /* old or new syntax */
 int depth;                     /* set by -depth option */
 int output_specified;          /* one of -print, -ok or -exec was specified */
-int xdev;                      /* set by -xdev option */
 
 main(argc, argv)
        int argc;
 
 main(argc, argv)
        int argc;
@@ -50,19 +48,25 @@ main(argc, argv)
                usage();
 
        paths = argv;
                usage();
 
        paths = argv;
-       ftsoptions = FTS_MULTIPLE|FTS_NOSTAT|FTS_PHYSICAL;
+       ftsoptions = FTS_NOSTAT|FTS_PHYSICAL;
 
        /*
 
        /*
-        * if arguments start with an option, it's new syntax; otherwise,
-        * if has a "-option" anywhere it must be old syntax.
+        * if arguments start with an option, treat it like new syntax;
+        * otherwise, if has a "-option" anywhere (which isn't an argument
+        * to another command) treat it as old syntax.
         */
        if (argv[1][0] != '-')
         */
        if (argv[1][0] != '-')
-               for (p = argv + 1; *p; ++p)
+               for (p = argv + 1; *p; ++p) {
+                       if (!strcmp(*p, "exec") || !strcmp(*p, "ok")) {
+                               while (p[1] && strcmp(*++p, ";"));
+                               continue;
+                       }
                        if (**p == '-') {
                                deprecated = 1;
                                oldsyntax(&argv);
                                break;
                        }
                        if (**p == '-') {
                                deprecated = 1;
                                oldsyntax(&argv);
                                break;
                        }
+               }
        if (!deprecated)
                newsyntax(argc, &argv);
     
        if (!deprecated)
                newsyntax(argc, &argv);
     
@@ -100,7 +104,8 @@ find_formplan(argv)
         * plan->next pointer.
         */
        for (plan = NULL; *argv;) {
         * plan->next pointer.
         */
        for (plan = NULL; *argv;) {
-               new = find_create(&argv);
+               if (!(new = find_create(&argv)))
+                       continue;
                if (plan == NULL)
                        tail = plan = new;
                else {
                if (plan == NULL)
                        tail = plan = new;
                else {
@@ -171,18 +176,19 @@ find_execute(plan, paths)
                exit(1);
        }
        while (entry = ftsread(tree)) {
                exit(1);
        }
        while (entry = ftsread(tree)) {
-               switch(entry->info) {
+               switch(entry->fts_info) {
                case FTS_DNR:
                        (void)fprintf(stderr,
                case FTS_DNR:
                        (void)fprintf(stderr,
-                           "find: %s: unable to read.\n", entry->path);
+                           "find: %s: unable to read.\n", entry->fts_path);
                        continue;
                case FTS_DNX:
                        (void)fprintf(stderr,
                        continue;
                case FTS_DNX:
                        (void)fprintf(stderr,
-                           "find: %s: unable to search.\n", entry->path);
+                           "find: %s: unable to search.\n", entry->fts_path);
                        continue;
                case FTS_ERR:
                        (void)fprintf(stderr,
                        continue;
                case FTS_ERR:
                        (void)fprintf(stderr,
-                           "find: %s: %s.\n", entry->path, strerror(errno));
+                           "find: %s: %s.\n", entry->fts_path,
+                           strerror(errno));
                        continue;
                case FTS_D:
                        if (depth)
                        continue;
                case FTS_D:
                        if (depth)
@@ -190,36 +196,27 @@ find_execute(plan, paths)
                        break;
                case FTS_DC:
                        (void)fprintf(stderr,
                        break;
                case FTS_DC:
                        (void)fprintf(stderr,
-                           "find: directory cycle: %s.\n", entry->path);
+                           "find: directory cycle: %s.\n", entry->fts_path);
                        continue;
                case FTS_DP:
                        if (!depth)
                                continue;
                        continue;
                case FTS_DP:
                        if (!depth)
                                continue;
+                       break;
                case FTS_NS:
                        if (!(ftsoptions & FTS_NOSTAT)) {
                                (void)fprintf(stderr,
                case FTS_NS:
                        if (!(ftsoptions & FTS_NOSTAT)) {
                                (void)fprintf(stderr,
-                                   "find: can't stat: %s.\n", entry->path);
+                                   "find: can't stat: %s.\n", entry->fts_path);
                                continue;
                        }
                        break;
                }
 
                                continue;
                        }
                        break;
                }
 
-               /* always keep curdev up to date, -fstype uses it. */
-               if (xdev && curdev != entry->statb.st_dev &&
-                   curdev != -1 && ftsset(tree, entry, FTS_SKIP)) {
-                       (void)fprintf(stderr, "find: %s: %s.\n",
-                           entry->path, strerror(errno));
-                       exit(1);
-               }
-
                /*
                 * call all the functions in the execution plan until one is
                 * false or all have been executed.  This is where we do all
                 * the work specified by the user on the command line.
                 */
                for (p = plan; p && (p->eval)(p, entry); p = p->next);
                /*
                 * call all the functions in the execution plan until one is
                 * false or all have been executed.  This is where we do all
                 * the work specified by the user on the command line.
                 */
                for (p = plan; p && (p->eval)(p, entry); p = p->next);
-
-               curdev = entry->statb.st_dev;
        }
        (void)ftsclose(tree);
 }
        }
        (void)ftsclose(tree);
 }