option.c (76250) | option.c (91400) |
---|---|
1/*- 2 * Copyright (c) 1990, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Cimarron D. Taylor of the University of California, Berkeley. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 25 unchanged lines hidden (view full) --- 34 * SUCH DAMAGE. 35 */ 36 37#ifndef lint 38/* 39static char sccsid[] = "@(#)option.c 8.2 (Berkeley) 4/16/94"; 40*/ 41static const char rcsid[] = | 1/*- 2 * Copyright (c) 1990, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Cimarron D. Taylor of the University of California, Berkeley. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 25 unchanged lines hidden (view full) --- 34 * SUCH DAMAGE. 35 */ 36 37#ifndef lint 38/* 39static char sccsid[] = "@(#)option.c 8.2 (Berkeley) 4/16/94"; 40*/ 41static const char rcsid[] = |
42 "$FreeBSD: head/usr.bin/find/option.c 76250 2001-05-03 18:05:35Z phk $"; | 42 "$FreeBSD: head/usr.bin/find/option.c 91400 2002-02-27 17:57:00Z dwmalone $"; |
43#endif /* not lint */ 44 45#include <sys/types.h> 46#include <sys/stat.h> 47 48#include <err.h> 49#include <fts.h> 50#include <regex.h> 51#include <stdio.h> 52#include <stdlib.h> 53#include <string.h> 54 55#include "find.h" 56 | 43#endif /* not lint */ 44 45#include <sys/types.h> 46#include <sys/stat.h> 47 48#include <err.h> 49#include <fts.h> 50#include <regex.h> 51#include <stdio.h> 52#include <stdlib.h> 53#include <string.h> 54 55#include "find.h" 56 |
57int typecompare __P((const void *, const void *)); 58 |
|
57/* NB: the following table must be sorted lexically. */ 58static OPTION const options[] = { 59 { "!", c_simple, f_not, 0 }, 60 { "(", c_simple, f_openparen, 0 }, 61 { ")", c_simple, f_closeparen, 0 }, 62 { "-a", c_and, NULL, 0 }, 63 { "-amin", c_Xmin, f_Xmin, F_TIME_A }, 64 { "-and", c_and, NULL, 0 }, --- 67 unchanged lines hidden (view full) --- 132 * TODO: 133 * add create/process function pointers to node, so we can skip 134 * this switch stuff. 135 */ 136PLAN * 137find_create(argvp) 138 char ***argvp; 139{ | 59/* NB: the following table must be sorted lexically. */ 60static OPTION const options[] = { 61 { "!", c_simple, f_not, 0 }, 62 { "(", c_simple, f_openparen, 0 }, 63 { ")", c_simple, f_closeparen, 0 }, 64 { "-a", c_and, NULL, 0 }, 65 { "-amin", c_Xmin, f_Xmin, F_TIME_A }, 66 { "-and", c_and, NULL, 0 }, --- 67 unchanged lines hidden (view full) --- 134 * TODO: 135 * add create/process function pointers to node, so we can skip 136 * this switch stuff. 137 */ 138PLAN * 139find_create(argvp) 140 char ***argvp; 141{ |
140 register OPTION *p; | 142 OPTION *p; |
141 PLAN *new; 142 char **argv; 143 144 argv = *argvp; 145 | 143 PLAN *new; 144 char **argv; 145 146 argv = *argvp; 147 |
146 if ((p = option(*argv)) == NULL) | 148 if ((p = lookup_option(*argv)) == NULL) |
147 errx(1, "%s: unknown option", *argv); 148 ++argv; 149 150 new = (p->create)(p, &argv); 151 *argvp = argv; 152 return (new); 153} 154 155OPTION * | 149 errx(1, "%s: unknown option", *argv); 150 ++argv; 151 152 new = (p->create)(p, &argv); 153 *argvp = argv; 154 return (new); 155} 156 157OPTION * |
156option(name) 157 char *name; | 158lookup_option(name) 159 const char *name; |
158{ 159 OPTION tmp; | 160{ 161 OPTION tmp; |
160 int typecompare __P((const void *, const void *)); | |
161 162 tmp.name = name; 163 return ((OPTION *)bsearch(&tmp, options, 164 sizeof(options)/sizeof(OPTION), sizeof(OPTION), typecompare)); 165} 166 167int 168typecompare(a, b) 169 const void *a, *b; 170{ | 162 163 tmp.name = name; 164 return ((OPTION *)bsearch(&tmp, options, 165 sizeof(options)/sizeof(OPTION), sizeof(OPTION), typecompare)); 166} 167 168int 169typecompare(a, b) 170 const void *a, *b; 171{ |
171 return (strcmp(((OPTION *)a)->name, ((OPTION *)b)->name)); | 172 return (strcmp(((const OPTION *)a)->name, ((const OPTION *)b)->name)); |
172} | 173} |