filesystems: return ENOSYS for REQ_PEEK
[minix3.git] / commands / find / option.c
blobf30f7d8ceaa85d72ef9580000facec1c1d4cd19e
1 /* $NetBSD: option.c,v 1.26 2007/02/06 15:33:22 perry Exp $ */
3 /*-
4 * Copyright (c) 1990, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Cimarron D. Taylor of the University of California, Berkeley.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
35 #include <sys/cdefs.h>
37 #include <sys/types.h>
38 #include <sys/stat.h>
40 #include <err.h>
41 #include <fts.h>
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <string.h>
46 #include "find.h"
48 int typecompare(const void *, const void *);
49 static OPTION *option(char *);
51 /* NB: the following table must be sorted lexically. */
52 static OPTION const options[] = {
53 { "!", N_NOT, c_not, 0 },
54 { "(", N_OPENPAREN, c_openparen, 0 },
55 { ")", N_CLOSEPAREN, c_closeparen, 0 },
56 { "-a", N_AND, c_null, 0 },
57 { "-amin", N_AMIN, c_amin, 1 },
58 { "-and", N_AND, c_null, 0 },
59 { "-anewer", N_ANEWER, c_anewer, 1 },
60 { "-atime", N_ATIME, c_atime, 1 },
61 { "-cmin", N_CMIN, c_cmin, 1 },
62 { "-cnewer", N_CNEWER, c_cnewer, 1 },
63 { "-ctime", N_CTIME, c_ctime, 1 },
64 { "-delete", N_DELETE, c_delete, 0 },
65 { "-depth", N_DEPTH, c_depth, 0 },
66 { "-empty", N_EMPTY, c_empty, 0 },
67 { "-exec", N_EXEC, c_exec, 1 },
68 { "-execdir", N_EXECDIR, c_execdir, 1 },
69 { "-exit", N_EXIT, c_exit, 0 },
70 { "-false", N_FALSE, c_false, 0 },
71 { "-follow", N_FOLLOW, c_follow, 0 },
72 { "-fprint", N_FPRINT, c_fprint, 1 },
73 #if !defined(__minix)
74 { "-flags", N_FLAGS, c_flags, 1 },
75 { "-fstype", N_FSTYPE, c_fstype, 1 },
76 #endif
77 { "-group", N_GROUP, c_group, 1 },
78 { "-iname", N_INAME, c_iname, 1 },
79 { "-inum", N_INUM, c_inum, 1 },
80 { "-iregex", N_IREGEX, c_iregex, 1 },
81 { "-links", N_LINKS, c_links, 1 },
82 { "-ls", N_LS, c_ls, 0 },
83 { "-maxdepth", N_MAXDEPTH, c_maxdepth, 1 },
84 { "-mindepth", N_MINDEPTH, c_mindepth, 1 },
85 { "-mmin", N_MMIN, c_mmin, 1 },
86 { "-mtime", N_MTIME, c_mtime, 1 },
87 { "-name", N_NAME, c_name, 1 },
88 { "-newer", N_NEWER, c_newer, 1 },
89 { "-nogroup", N_NOGROUP, c_nogroup, 0 },
90 { "-nouser", N_NOUSER, c_nouser, 0 },
91 { "-o", N_OR, c_or, 0 },
92 { "-ok", N_OK, c_exec, 1 },
93 { "-or", N_OR, c_or, 0 },
94 { "-path", N_PATH, c_path, 1 },
95 { "-perm", N_PERM, c_perm, 1 },
96 { "-print", N_PRINT, c_print, 0 },
97 { "-print0", N_PRINT0, c_print0, 0 },
98 { "-printx", N_PRINTX, c_printx, 0 },
99 { "-prune", N_PRUNE, c_prune, 0 },
100 { "-regex", N_REGEX, c_regex, 1 },
101 { "-rm", N_DELETE, c_delete, 0 },
102 { "-size", N_SIZE, c_size, 1 },
103 { "-type", N_TYPE, c_type, 1 },
104 { "-user", N_USER, c_user, 1 },
105 { "-xdev", N_XDEV, c_xdev, 0 }
109 * find_create --
110 * create a node corresponding to a command line argument.
112 * TODO:
113 * add create/process function pointers to node, so we can skip
114 * this switch stuff.
116 PLAN *
117 find_create(char ***argvp)
119 OPTION *p;
120 PLAN *new;
121 char **argv;
123 argv = *argvp;
125 if ((p = option(*argv)) == NULL)
126 errx(1, "%s: unknown option", *argv);
127 ++argv;
128 if (p->arg && !*argv)
129 errx(1, "%s: requires additional arguments", *--argv);
131 new = (p->create)(&argv, p->token == N_OK);
133 *argvp = argv;
134 return (new);
137 static OPTION *
138 option(char *name)
140 OPTION tmp;
142 tmp.name = name;
143 return ((OPTION *)bsearch(&tmp, options,
144 sizeof(options)/sizeof(OPTION), sizeof(OPTION), typecompare));
148 typecompare(const void *a, const void *b)
151 return (strcmp(((const OPTION *)a)->name, ((const OPTION *)b)->name));