]> git.saurik.com Git - apple/shell_cmds.git/blobdiff - find/option.c
shell_cmds-216.60.1.tar.gz
[apple/shell_cmds.git] / find / option.c
index 7e73a5fdc5032e56f11ae613704b0e5f1236bae9..5771da4e25953e2b0b36706fb7213f2fbb5a19b4 100644 (file)
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
  * 4. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
 /*
 static char sccsid[] = "@(#)option.c   8.2 (Berkeley) 4/16/94";
 */
-static const char rcsid[] =
-  "$FreeBSD: src/usr.bin/find/option.c,v 1.9.2.4 2001/05/06 09:53:22 phk Exp $";
 #endif /* not lint */
 
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/usr.bin/find/option.c,v 1.32 2011/05/27 22:14:49 jilles Exp $");
+
 #include <sys/types.h>
 #include <sys/stat.h>
 
@@ -54,12 +51,19 @@ static const char rcsid[] =
 
 #include "find.h"
 
+static int typecompare(const void *, const void *);
+
 /* NB: the following table must be sorted lexically. */
+/* Options listed with C++ comments are in gnu find, but not our find */
 static OPTION const options[] = {
        { "!",          c_simple,       f_not,          0 },
        { "(",          c_simple,       f_openparen,    0 },
        { ")",          c_simple,       f_closeparen,   0 },
+       { "-Bmin",      c_Xmin,         f_Xmin,         F_TIME_B },
+       { "-Bnewer",    c_newer,        f_newer,        F_TIME_B },
+       { "-Btime",     c_Xtime,        f_Xtime,        F_TIME_B },
        { "-a",         c_and,          NULL,           0 },
+       { "-acl",       c_acl,          f_acl,          0 },
        { "-amin",      c_Xmin,         f_Xmin,         F_TIME_A },
        { "-and",       c_and,          NULL,           0 },
        { "-anewer",    c_newer,        f_newer,        F_TIME_A },
@@ -67,47 +71,65 @@ static OPTION const options[] = {
        { "-cmin",      c_Xmin,         f_Xmin,         F_TIME_C },
        { "-cnewer",    c_newer,        f_newer,        F_TIME_C },
        { "-ctime",     c_Xtime,        f_Xtime,        F_TIME_C },
+       { "-d",         c_depth,        f_depth,        0 },
+// -daystart
        { "-delete",    c_delete,       f_delete,       0 },
-       { "-depth",     c_depth,        f_always_true,  0 },
+       { "-depth",     c_depth,        f_depth,        0 },
        { "-empty",     c_empty,        f_empty,        0 },
        { "-exec",      c_exec,         f_exec,         0 },
        { "-execdir",   c_exec,         f_exec,         F_EXECDIR },
+       { "-false",     c_simple,       f_false,        0 },
        { "-flags",     c_flags,        f_flags,        0 },
+// -fls
        { "-follow",    c_follow,       f_always_true,  0 },
-/*
- * NetBSD doesn't provide a getvfsbyname(), so this option
- * is not available if using a NetBSD kernel.
- */
-#if !defined(__NetBSD__)
+// -fprint
+// -fprint0
+// -fprintf
        { "-fstype",    c_fstype,       f_fstype,       0 },
-#endif
+       { "-gid",       c_group,        f_group,        0 },
        { "-group",     c_group,        f_group,        0 },
+       { "-ignore_readdir_race",c_simple, f_always_true,0 },
+       { "-ilname",    c_name,         f_name,         F_LINK | F_IGNCASE },
        { "-iname",     c_name,         f_name,         F_IGNCASE },
        { "-inum",      c_inum,         f_inum,         0 },
        { "-ipath",     c_name,         f_path,         F_IGNCASE },
        { "-iregex",    c_regex,        f_regex,        F_IGNCASE },
+       { "-iwholename",c_name,         f_path,         F_IGNCASE },
        { "-links",     c_links,        f_links,        0 },
+       { "-lname",     c_name,         f_name,         F_LINK },
        { "-ls",        c_ls,           f_ls,           0 },
        { "-maxdepth",  c_mXXdepth,     f_always_true,  F_MAXDEPTH },
        { "-mindepth",  c_mXXdepth,     f_always_true,  0 },
        { "-mmin",      c_Xmin,         f_Xmin,         0 },
        { "-mnewer",    c_newer,        f_newer,        0 },
+       { "-mount",     c_xdev,         f_always_true,  0 },
        { "-mtime",     c_Xtime,        f_Xtime,        0 },
        { "-name",      c_name,         f_name,         0 },
        { "-newer",     c_newer,        f_newer,        0 },
+       { "-newerBB",   c_newer,        f_newer,        F_TIME_B | F_TIME2_B },
+       { "-newerBa",   c_newer,        f_newer,        F_TIME_B | F_TIME2_A },
+       { "-newerBc",   c_newer,        f_newer,        F_TIME_B | F_TIME2_C },
+       { "-newerBm",   c_newer,        f_newer,        F_TIME_B },
+       { "-newerBt",   c_newer,        f_newer,        F_TIME_B | F_TIME2_T },
+       { "-neweraB",   c_newer,        f_newer,        F_TIME_A | F_TIME2_B },
        { "-neweraa",   c_newer,        f_newer,        F_TIME_A | F_TIME2_A },
        { "-newerac",   c_newer,        f_newer,        F_TIME_A | F_TIME2_C },
        { "-neweram",   c_newer,        f_newer,        F_TIME_A },
        { "-newerat",   c_newer,        f_newer,        F_TIME_A | F_TIME2_T },
+       { "-newercB",   c_newer,        f_newer,        F_TIME_C | F_TIME2_B },
        { "-newerca",   c_newer,        f_newer,        F_TIME_C | F_TIME2_A },
        { "-newercc",   c_newer,        f_newer,        F_TIME_C | F_TIME2_C },
        { "-newercm",   c_newer,        f_newer,        F_TIME_C },
        { "-newerct",   c_newer,        f_newer,        F_TIME_C | F_TIME2_T },
+       { "-newermB",   c_newer,        f_newer,        F_TIME2_B },
        { "-newerma",   c_newer,        f_newer,        F_TIME2_A },
        { "-newermc",   c_newer,        f_newer,        F_TIME2_C },
        { "-newermm",   c_newer,        f_newer,        0 },
        { "-newermt",   c_newer,        f_newer,        F_TIME2_T },
        { "-nogroup",   c_nogroup,      f_nogroup,      0 },
+       { "-noignore_readdir_race",c_simple, f_always_true,0 },
+       { "-noleaf",    c_simple,       f_always_true,  0 },
+       { "-not",       c_simple,       f_not,          0 },
        { "-nouser",    c_nouser,       f_nouser,       0 },
        { "-o",         c_simple,       f_or,           0 },
        { "-ok",        c_exec,         f_exec,         F_NEEDOK },
@@ -117,12 +139,23 @@ static OPTION const options[] = {
        { "-perm",      c_perm,         f_perm,         0 },
        { "-print",     c_print,        f_print,        0 },
        { "-print0",    c_print,        f_print0,       0 },
+// -printf
        { "-prune",     c_simple,       f_prune,        0 },
+       { "-quit",      c_simple,       f_quit,         0 },
        { "-regex",     c_regex,        f_regex,        0 },
+       { "-samefile",  c_samefile,     f_inum,         0 },
        { "-size",      c_size,         f_size,         0 },
+       { "-true",      c_simple,       f_always_true,  0 },
        { "-type",      c_type,         f_type,         0 },
+       { "-uid",       c_user,         f_user,         0 },
        { "-user",      c_user,         f_user,         0 },
+       { "-wholename", c_name,         f_path,         0 },
+#ifdef __APPLE__
+       { "-xattr",     c_simple,       f_xattr,        0 },
+       { "-xattrname", c_name,         f_xattrname,    0 },
+#endif /* __APPLE__ */
        { "-xdev",      c_xdev,         f_always_true,  0 },
+// -xtype
 };
 
 /*
@@ -134,17 +167,16 @@ static OPTION const options[] = {
  *     this switch stuff.
  */
 PLAN *
-find_create(argvp)
-       char ***argvp;
+find_create(char ***argvp)
 {
-       register OPTION *p;
+       OPTION *p;
        PLAN *new;
        char **argv;
 
        argv = *argvp;
 
-       if ((p = option(*argv)) == NULL)
-               errx(1, "%s: unknown option", *argv);
+       if ((p = lookup_option(*argv)) == NULL)
+               errx(1, "%s: unknown primary or operator", *argv);
        ++argv;
 
        new = (p->create)(p, &argv);
@@ -153,20 +185,17 @@ find_create(argvp)
 }
 
 OPTION *
-option(name)
-       char *name;
+lookup_option(const char *name)
 {
        OPTION tmp;
-       int typecompare __P((const void *, const void *));
 
        tmp.name = name;
        return ((OPTION *)bsearch(&tmp, options,
            sizeof(options)/sizeof(OPTION), sizeof(OPTION), typecompare));
 }
 
-int
-typecompare(a, b)
-       const void *a, *b;
+static int
+typecompare(const void *a, const void *b)
 {
-       return (strcmp(((OPTION *)a)->name, ((OPTION *)b)->name));
+       return (strcmp(((const OPTION *)a)->name, ((const OPTION *)b)->name));
 }