return to the original find syntax (newsyntax.c -> main.c, delete
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sat, 25 May 1991 06:17:15 +0000 (22:17 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sat, 25 May 1991 06:17:15 +0000 (22:17 -0800)
oldsyntax.c; create extern.h for ANSI prototypes; create true error routine;
make NEW macro a real routine

SCCS-vsn: usr.bin/find/Makefile 5.2
SCCS-vsn: usr.bin/find/find.1 6.23
SCCS-vsn: usr.bin/find/find.c 5.2
SCCS-vsn: usr.bin/find/find.h 5.8
SCCS-vsn: usr.bin/find/function.c 5.16
SCCS-vsn: usr.bin/find/main.c 5.8
SCCS-vsn: usr.bin/find/misc.c 5.8
SCCS-vsn: usr.bin/find/operator.c 5.4
SCCS-vsn: usr.bin/find/option.c 5.7

usr/src/usr.bin/find/Makefile
usr/src/usr.bin/find/find.1
usr/src/usr.bin/find/find.c
usr/src/usr.bin/find/find.h
usr/src/usr.bin/find/function.c
usr/src/usr.bin/find/main.c
usr/src/usr.bin/find/misc.c
usr/src/usr.bin/find/operator.c
usr/src/usr.bin/find/option.c

index bb5d072..ec3ddc7 100644 (file)
@@ -1,8 +1,7 @@
-#      @(#)Makefile    5.1 (Berkeley) %G%
+#      @(#)Makefile    5.2 (Berkeley) %G%
 
 PROG=  find
 
 PROG=  find
-SRCS=  find.c function.c ls.c misc.c newsyntax.c oldsyntax.c operator.c \
-       option.c
+SRCS=  find.c function.c ls.c main.c misc.c operator.c option.c
 DPADD= ${LIBUTIL}
 LDADD= -lutil
 
 DPADD= ${LIBUTIL}
 LDADD= -lutil
 
index 5838959..e92a1b0 100644 (file)
@@ -3,10 +3,9 @@
 .\"
 .\" %sccs.include.redist.man%
 .\"
 .\"
 .\" %sccs.include.redist.man%
 .\"
-.\"     @(#)find.1     6.22 (Berkeley) %G%
+.\"     @(#)find.1     6.23 (Berkeley) %G%
 .\"
 .Vx
 .\"
 .Vx
-.Vx
 .Dd 
 .Dt FIND 1
 .Os
 .Dd 
 .Dt FIND 1
 .Os
 .Sh SYNOPSIS
 .Nm find
 .Op Fl drsXx
 .Sh SYNOPSIS
 .Nm find
 .Op Fl drsXx
-.Op Ar file
-.Ar expression
-.Nm find
-.Op Fl drsXx
 .Op Fl f Ar file
 .Op Fl f Ar file
+.Op Ar file ...
 .Ar expression
 .Sh DESCRIPTION
 .Nm Find
 .Ar expression
 .Sh DESCRIPTION
 .Nm Find
@@ -59,10 +55,8 @@ The
 option specifies a file hierarchy for
 .Nm find
 to traverse.
 option specifies a file hierarchy for
 .Nm find
 to traverse.
-If no
-.Fl f
-option is specified, the first operand after the options is
-expected to be the file hierarchy to be traversed.
+File hierarchies may also be specified as the operands immediately
+following the options.
 .Tp Fl r
 The
 .Fl r
 .Tp Fl r
 The
 .Fl r
@@ -114,7 +108,7 @@ than that of the file from which the descent began.
 .Tp
 .Sh PRIMARIES
 .Tw Ds
 .Tp
 .Sh PRIMARIES
 .Tw Ds
-.Tp Cx Ic atime
+.Tp Cx Ic -atime
 .Cx \&\ \&
 .Ar n
 .Cx
 .Cx \&\ \&
 .Ar n
 .Cx
@@ -123,7 +117,7 @@ True if the difference between the file last access time and the time
 was started, rounded up to the next full 24\-hour period, is
 .Ar n
 24\-hour periods.
 was started, rounded up to the next full 24\-hour period, is
 .Ar n
 24\-hour periods.
-.Tp Cx Ic ctime
+.Tp Cx Ic -ctime
 .Cx \&\ \&
 .Ar n
 .Cx
 .Cx \&\ \&
 .Ar n
 .Cx
@@ -133,7 +127,7 @@ information and the time
 was started, rounded up to the next full 24\-hour period, is
 .Ar n
 24\-hour periods.
 was started, rounded up to the next full 24\-hour period, is
 .Ar n
 24\-hour periods.
-.Tp Cx Ic exec
+.Tp Cx Ic -exec
 .Cx \&\ \&
 .Ar utility
 .Cx \&\ \&
 .Cx \&\ \&
 .Ar utility
 .Cx \&\ \&
@@ -149,7 +143,7 @@ arguments it is replaced by the pathname of the current file.
 Utility will be executed in the directory from which
 .Nm find
 was executed.
 Utility will be executed in the directory from which
 .Nm find
 was executed.
-.Tp Cx Ic fstype
+.Tp Cx Ic -fstype
 .Cx \&\ \&
 .Ar type
 .Cx
 .Cx \&\ \&
 .Ar type
 .Cx
@@ -161,7 +155,7 @@ The type ``local'' is not a specific file system type, but matches
 any file system physically mounted on the system where the
 .Nm find
 is being executed.
 any file system physically mounted on the system where the
 .Nm find
 is being executed.
-.Tp Cx Ic group
+.Tp Cx Ic -group
 .Cx \&\ \&
 .Ar gname
 .Cx
 .Cx \&\ \&
 .Ar gname
 .Cx
@@ -172,20 +166,20 @@ If
 is numeric and there is no such group name, then
 .Ar gname
 is treated as a group id.
 is numeric and there is no such group name, then
 .Ar gname
 is treated as a group id.
-.Tp Cx Ic inum
+.Tp Cx Ic -inum
 .Cx \&\ \&
 .Ar n
 .Cx
 True if the file has inode number
 .Ar n  .
 .Cx \&\ \&
 .Ar n
 .Cx
 True if the file has inode number
 .Ar n  .
-.Tp Cx Ic links
+.Tp Cx Ic -links
 .Cx \&\ \&
 .Ar n
 .Cx
 True if the file has
 .Ar n
 links.
 .Cx \&\ \&
 .Ar n
 .Cx
 True if the file has
 .Ar n
 links.
-.Tp Ic ls
+.Tp Ic -ls
 This primary always evaluates to true.
 The following information for the current file is written to standard output:
 its inode number, size in 512\-byte blocks, file permissions, number of hard
 This primary always evaluates to true.
 The following information for the current file is written to standard output:
 its inode number, size in 512\-byte blocks, file permissions, number of hard
@@ -195,7 +189,7 @@ will be displayed instead of the size in bytes.
 If the file is a symbolic link, the pathname of the linked\-to file will be
 displayed preceded by ``\->''.
 The format is identical to that produced by ``ls \-dgils''.
 If the file is a symbolic link, the pathname of the linked\-to file will be
 displayed preceded by ``\->''.
 The format is identical to that produced by ``ls \-dgils''.
-.Tp Cx Ic mtime
+.Tp Cx Ic -mtime
 .Cx \&\ \&
 .Ar n
 .Cx
 .Cx \&\ \&
 .Ar n
 .Cx
@@ -204,16 +198,16 @@ True if the difference between the file last modification time and the time
 was started, rounded up to the next full 24\-hour period, is
 .Ar n
 24\-hour periods.
 was started, rounded up to the next full 24\-hour period, is
 .Ar n
 24\-hour periods.
-.Tp Cx Ic \&ok
+.Tp Cx Ic \&-ok
 .Cx \&\ \&
 .Ar utility
 .Ws
 .Op argument ... ;
 .Cx
 The
 .Cx \&\ \&
 .Ar utility
 .Ws
 .Op argument ... ;
 .Cx
 The
-.Ic \&ok
+.Ic \&-ok
 primary is identical to the
 primary is identical to the
-.Ic exec
+.Ic -exec
 primary with the exception that
 .Nm find
 requests user affirmation for the execution of the utility by printing
 primary with the exception that
 .Nm find
 requests user affirmation for the execution of the utility by printing
@@ -222,7 +216,7 @@ If the response is other than ``y'' the command is not executed and the
 value of the
 .Ar \&ok
 expression is false.
 value of the
 .Ar \&ok
 expression is false.
-.Tp Cx Ic name
+.Tp Cx Ic -name
 .Cx \&\ \&
 .Ar pattern
 .Cx
 .Cx \&\ \&
 .Ar pattern
 .Cx
@@ -233,17 +227,17 @@ may be used as part of
 .Ar pattern  .
 These characters may be matched explicitly by escaping them with a
 backslash (``\e'').
 .Ar pattern  .
 These characters may be matched explicitly by escaping them with a
 backslash (``\e'').
-.Tp Cx Ic newer
+.Tp Cx Ic -newer
 .Cx \&\ \&
 .Ar file
 .Cx
 True if the current file has a more recent last modification time than
 .Ar file  .
 .Cx \&\ \&
 .Ar file
 .Cx
 True if the current file has a more recent last modification time than
 .Ar file  .
-.Tp Ic nouser
+.Tp Ic -nouser
 True if the file belongs to an unknown user.
 True if the file belongs to an unknown user.
-.Tp Ic nogroup
+.Tp Ic -nogroup
 True if the file belongs to an unknown group.
 True if the file belongs to an unknown group.
-.Tp Cx Ic perm
+.Tp Cx Ic -perm
 .Cx \&\ \&
 .Op Fl
 .Ar mode
 .Cx \&\ \&
 .Op Fl
 .Ar mode
@@ -256,33 +250,34 @@ or an octal number.
 If the mode is symbolic, a starting value of zero is assumed and the
 mode sets or clears permissions without regard to the process' file mode
 creation mask.
 If the mode is symbolic, a starting value of zero is assumed and the
 mode sets or clears permissions without regard to the process' file mode
 creation mask.
-If the mode is octal, only bits 07777 of the file's mode bits participate
+If the mode is octal, only bits 07777 (S_ISUID | S_ISGID | S_ISTXT |
+S_IRWXU | S_IRWXG | S_IRWXO) of the file's mode bits participate
 in the comparison.
 If the mode is preceded by a dash (``\-''), this primary evaluates to true
 if at least all of the bits in the mode are set in the file's mode bits.
 If the mode is not preceded by a dash, this primary evaluates to true if
 the bits in the mode exactly match the file's mode bits.
 Note, the first character of a symbolic mode may not be a dash (``\-'').
 in the comparison.
 If the mode is preceded by a dash (``\-''), this primary evaluates to true
 if at least all of the bits in the mode are set in the file's mode bits.
 If the mode is not preceded by a dash, this primary evaluates to true if
 the bits in the mode exactly match the file's mode bits.
 Note, the first character of a symbolic mode may not be a dash (``\-'').
-.Tp Ic print
+.Tp Ic -print
 This primary always evaluates to true.
 It prints the pathname of the current file to standard output.
 The expression is appended to the user specified expression if neither
 This primary always evaluates to true.
 It prints the pathname of the current file to standard output.
 The expression is appended to the user specified expression if neither
-.Ic exec  ,
-.Ic ls ,
+.Ic -exec ,
+.Ic -ls
 or
 or
-.Ic \&ok
+.Ic \&-ok
 is specified.
 is specified.
-.Tp Ic prune
+.Tp Ic -prune
 This primary always evaluates to true.
 It causes
 .Nm find
 to not descend into the current file.
 Note, the
 This primary always evaluates to true.
 It causes
 .Nm find
 to not descend into the current file.
 Note, the
-.Ic prune
+.Ic -prune
 primary has no effect if the
 primary has no effect if the
-.Op \-d
+.Fl d
 option was specified.
 option was specified.
-.Tp Cx Ic size
+.Tp Cx Ic -size
 .Cx \&\ \&
 .Ar n
 .Op Cm c
 .Cx \&\ \&
 .Ar n
 .Op Cm c
@@ -295,7 +290,7 @@ is followed by a ``c'', then the primary is true if the
 file's size is
 .Ar n
 bytes.
 file's size is
 .Ar n
 bytes.
-.Tp Cx Ic type
+.Tp Cx Ic -type
 .Cx \&\ \&
 .Ar t
 .Cx
 .Cx \&\ \&
 .Ar t
 .Cx
@@ -321,7 +316,7 @@ socket
 .Tp
 .De
 .Pp
 .Tp
 .De
 .Pp
-.Tp Cx Ic user
+.Tp Cx Ic -user
 .Cx \&\ \&
 .Ar uname
 .Cx
 .Cx \&\ \&
 .Ar uname
 .Cx
@@ -336,12 +331,8 @@ is treated as a user id.
 .Pp
 All primaries which take a numeric argument allow the number to be
 preceded by a plus sign (``+'') or a minus sign (``\-'').
 .Pp
 All primaries which take a numeric argument allow the number to be
 preceded by a plus sign (``+'') or a minus sign (``\-'').
-A preceding plus sign means ``more than
-.Ar n  ' ' ,
-a preceding minus sign means ``less than
-.Ar n  ' '
-and neither means ``exactly
-.Ar n  ' ' .
+A preceding plus sign means ``more than n'', a preceding minus sign means
+``less than n'' and neither means ``exactly n'' .
 .Sh OPERATORS
 The primaries may be combined using the following operators.
 The operators are listed in order of decreasing precedence.
 .Sh OPERATORS
 The primaries may be combined using the following operators.
 The operators are listed in order of decreasing precedence.
@@ -399,15 +390,15 @@ to be a separate argument to
 .Pp
 The following examples are shown as given to the shell:
 .Tw findx
 .Pp
 The following examples are shown as given to the shell:
 .Tw findx
-.Tp Li find  /  \e!  name  "*.c"  print
+.Tp Li find  /  \e!  -name  "*.c"  -print
 Print out a list of all the files whose names do not end in ``.c''.
 Print out a list of all the files whose names do not end in ``.c''.
-.Tp Li find  /  newer  ttt  user  wnj  print
+.Tp Li find  /  -newer  ttt  -user  wnj  -print
 Print out a list of all the files owned by user ``wnj'' that are newer
 than the file ``ttt''.
 Print out a list of all the files owned by user ``wnj'' that are newer
 than the file ``ttt''.
-.Tp Li find  /  \e!  \e(  newer  ttt  user  wnj  \e)  print
+.Tp Li find  /  \e!  \e(  -newer  ttt  -user  wnj  \e)  -print
 Print out a list of all the files which are not both newer than ``ttt''
 and owned by ``wnj''.
 Print out a list of all the files which are not both newer than ``ttt''
 and owned by ``wnj''.
-.Tp Li find  /  \e(  newer  ttt  or  user wnj  \e)  print
+.Tp Li "find  /  \e(  -newer  ttt  or  -user wnj  \e)  -print"
 Print out a list of all the files that are either owned by ``wnj'' or
 that are newer than ``ttt''.
 .Tp
 Print out a list of all the files that are either owned by ``wnj'' or
 that are newer than ``ttt''.
 .Tp
@@ -423,64 +414,44 @@ that are newer than ``ttt''.
 .Sh STANDARDS
 The
 .Nm find
 .Sh STANDARDS
 The
 .Nm find
-utility syntax is a replacement for the syntax specified by the POSIX
+utility syntax is a superset of the syntax specified by the POSIX
 1003.2 standard.
 1003.2 standard.
-The standard syntax is also supported; see the COMPATIBILITY section
-below for details.
 .Pp
 The
 .Fl r ,
 .Pp
 The
 .Fl r ,
-.Fl s ,
+.Fl s
 and
 .Fl X
 and
 .Fl X
-options as well as the primaries
-.Ic inum
+options, as well as the primaries
+.Ic -inum
 and
 and
-.Ic ls
+.Ic -ls ,
 are extensions to the POSIX standard.
 are extensions to the POSIX standard.
-.Sh COMPATIBILITY
-The traditional, and standardized, syntax for
-.Nm find
-is as follows.
-All of the primaries are preceded by a dash (``\-''), i.e. the
-primary ``group'' is specified as ``\-group''.
-The
-.Fl d  ,
-.Fl s ,
+.Pp
+Historically, the
+.Fl d ,
+.Fl s
 and
 .Fl x
 and
 .Fl x
-options are implemented using the primaries ``\-depth'', ``\-follow'',
+options were implemented using the primaries ``\-depth'', ``\-follow'',
 and ``\-xdev''.
 and ``\-xdev''.
-These primaries always evaluate to true.
-The operator ``or'' is implemented as ``\-o'', and the operator
-``and'' is implemented as ``\-a''.
-The set of file trees to be traversed are specified as the first operands
-to
-.Nm find  .
-The first operand beginning with a dash (``\-''), exclamation point (``!'')
-or left parenthesis (``('') is assumed to be the beginning of the expression
-and the end of the files to be traversed.
-.Pp
-The
-.Nm find
-syntax was changed for two reasons.
-The first is that the ``\-depth'', ``\-follow'' and ``\-xdev'' primaries
-are really global variables that take effect before the traversal begins.
-This causes some legal expressions to have unexpected results.
+These primaries always evaluated to true.
+As they were really global variables that took effect before the traversal
+began, some legal expressions could have unexpected results.
 An example is the expression ``\-print \-o \-depth''.
 As \-print always evaluates to true, the standard order of evaluation
 implies that \-depth would never be evaluated.
 This is not the case.
 .Pp
 An example is the expression ``\-print \-o \-depth''.
 As \-print always evaluates to true, the standard order of evaluation
 implies that \-depth would never be evaluated.
 This is not the case.
 .Pp
-The second reason is that traversing file trees with names beginning with
-a dash, exclamation point or left parenthesis was impossible.
+The operator ``or'' was implemented as ``\-o'', and the operator ``and''
+was implemented as ``\-a''.
 .Pp
 .Pp
-Historic implementations of the 
+Historic implementations of the
 .Ic exec
 and
 .Ic ok
 primaries did not replace the string ``{}'' in the utility name or the
 .Ic exec
 and
 .Ic ok
 primaries did not replace the string ``{}'' in the utility name or the
-utility arguments unless it appeared without any other characters.
+utility arguments if it had preceding or following non-whitespace characters.
 This version replaces it no matter where in the utility name or arguments
 it appears.
 .Sh BUGS
 This version replaces it no matter where in the utility name or arguments
 it appears.
 .Sh BUGS
@@ -489,3 +460,13 @@ The special characters used by
 are also special characters to many shell programs.
 In particular, the characters ``*'', ``['', ``]'', ``?'', ``('', ``)'',
 ``!'', ``\e'' and ``;'' may have to be escaped from the shell.
 are also special characters to many shell programs.
 In particular, the characters ``*'', ``['', ``]'', ``?'', ``('', ``)'',
 ``!'', ``\e'' and ``;'' may have to be escaped from the shell.
+.Pp
+As there is no delimiter separating options and file names or file
+names and the
+.Ar expression ,
+it is difficult to specify files named ``-xdev'' or ``!''.
+These problems are handled by the
+.Fl f
+option and the
+.Xr getopt 3
+``--'' construct.
index c2dcd9b..9acc150 100644 (file)
@@ -1,5 +1,5 @@
 /*-
 /*-
- * Copyright (c) 1990 The Regents of the University of California.
+ * Copyright (c) 1991 The Regents of the University of California.
  * All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  * All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
@@ -9,76 +9,18 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1990 The Regents of the University of California.\n\
- All rights reserved.\n";
+static char sccsid[] = "@(#)find.c     5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
-#ifndef lint
-static char sccsid[] = "@(#)find.c     5.1 (Berkeley) %G%";
-#endif /* not lint */
-
-#include <sys/param.h>
+#include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/errno.h>
 #include <sys/stat.h>
 #include <sys/errno.h>
-#include <time.h>
 #include <fts.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include "find.h"
 
 #include <fts.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include "find.h"
 
-FTS *tree;                     /* pointer to top of FTS hierarchy */
-time_t now;                    /* time find was run */
-                               /* options for the ftsopen(3) call */
-int ftsoptions = FTS_NOSTAT|FTS_PHYSICAL;
-int isdeprecated;              /* using deprecated syntax */
-int isdepth;                   /* do directories on post-order visit */
-int isoutput;                  /* user specified output operator */
-int isrelative;                        /* can do -exec/ok on relative path */
-int isxargs;                   /* don't permit xargs delimiting chars */
-
-main(argc, argv)
-       int argc;
-       char **argv;
-{
-       PLAN *plan;
-       char **p, **paths;
-       PLAN *find_formplan();
-       time_t time();
-       void newsyntax(), oldsyntax();
-    
-       (void)time(&now);                       /* initialize the time-of-day */
-
-       if (argc < 2)
-               usage();
-
-       paths = argv;
-
-       /*
-        * 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] != '-')
-               for (p = argv + 1; *p; ++p) {
-                       if (!strcmp(*p, "exec") || !strcmp(*p, "ok")) {
-                               while (p[1] && strcmp(*++p, ";"));
-                               continue;
-                       }
-                       if (**p == '-') {
-                               isdeprecated = 1;
-                               oldsyntax(&argv);
-                               break;
-                       }
-               }
-       if (!isdeprecated)
-               newsyntax(argc, &argv);
-    
-       plan = find_formplan(argv);             /* execution plan */
-       find_execute(plan, paths);
-}
-
 /*
  * find_formplan --
  *     process the command line and create a "plan" corresponding to the
 /*
  * find_formplan --
  *     process the command line and create a "plan" corresponding to the
@@ -164,11 +106,14 @@ find_formplan(argv)
        return(plan);
 }
  
        return(plan);
 }
  
+FTS *tree;                     /* pointer to top of FTS hierarchy */
+
 /*
  * find_execute --
  *     take a search plan and an array of search paths and executes the plan
  *     over all FTSENT's returned for the given search paths.
  */
 /*
  * find_execute --
  *     take a search plan and an array of search paths and executes the plan
  *     over all FTSENT's returned for the given search paths.
  */
+void
 find_execute(plan, paths)
        PLAN *plan;             /* search plan */
        char **paths;           /* array of pathnames to traverse */
 find_execute(plan, paths)
        PLAN *plan;             /* search plan */
        char **paths;           /* array of pathnames to traverse */
@@ -176,10 +121,8 @@ find_execute(plan, paths)
        register FTSENT *entry;
        PLAN *p;
     
        register FTSENT *entry;
        PLAN *p;
     
-       if (!(tree = fts_open(paths, ftsoptions, (int (*)())NULL))) {
-               error("ftsopen", errno);
-               exit(1);
-       }
+       if (!(tree = fts_open(paths, ftsoptions, (int (*)())NULL)))
+               err("ftsopen: %s", strerror(errno));
 
        while (entry = fts_read(tree)) {
                switch(entry->fts_info) {
 
        while (entry = fts_read(tree)) {
                switch(entry->fts_info) {
@@ -194,7 +137,7 @@ find_execute(plan, paths)
                case FTS_DNR:
                case FTS_ERR:
                case FTS_NS:
                case FTS_DNR:
                case FTS_ERR:
                case FTS_NS:
-                       error(entry->fts_path, errno);
+                       err("%s: %s", entry->fts_path, strerror(errno));
                        continue;
                case FTS_SL:
                        if (entry->fts_level == FTS_ROOTLEVEL) {
                        continue;
                case FTS_SL:
                        if (entry->fts_level == FTS_ROOTLEVEL) {
index 712e058..d5963c8 100644 (file)
@@ -7,7 +7,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)find.h      5.7 (Berkeley) %G%
+ *     @(#)find.h      5.8 (Berkeley) %G%
  */
 
 /* node type */
  */
 
 /* node type */
@@ -57,9 +57,4 @@ typedef struct _plandata {
 #define        e_len   p_un.ex._e_len
 } PLAN;
 
 #define        e_len   p_un.ex._e_len
 } PLAN;
 
-#define        error(name, number) \
-       (void)fprintf(stderr, "find: %s: %s\n", name, strerror(number));
-
-extern int ftsoptions;
-extern int isdeprecated, isdepth, isoutput, isrelative, isxargs;
-void *emalloc();
+#include "extern.h"
index ae8e932..2eccd08 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)function.c 5.15 (Berkeley) %G%";
+static char sccsid[] = "@(#)function.c 5.16 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -43,13 +43,7 @@ static char sccsid[] = "@(#)function.c       5.15 (Berkeley) %G%";
        return(0); \
 }
 
        return(0); \
 }
 
-#define NEW(t, f) { \
-       new = (PLAN *)emalloc(sizeof(PLAN)); \
-       new->type = t; \
-       new->eval = f; \
-       new->flags = 0; \
-       new->next = NULL; \
-}
+static PLAN *palloc __P((enum ntype, int (*)()));
 
 /*
  * find_parsenum --
 
 /*
  * find_parsenum --
@@ -62,7 +56,6 @@ find_parsenum(plan, option, str, endch)
 {
        long value;
        char *endchar;          /* pointer to character ending conversion */
 {
        long value;
        char *endchar;          /* pointer to character ending conversion */
-       void bad_arg();
     
        /* determine comparison from leading + or - */
        switch(*str) {
     
        /* determine comparison from leading + or - */
        switch(*str) {
@@ -87,7 +80,7 @@ find_parsenum(plan, option, str, endch)
        value = strtol(str, &endchar, 10);
        if (!value && endchar == str ||
            endchar[0] && (!endch || endchar[0] != *endch))
        value = strtol(str, &endchar, 10);
        if (!value && endchar == str ||
            endchar[0] && (!endch || endchar[0] != *endch))
-               bad_arg(option, "illegal numeric value");
+               err("%s: %s", option, "illegal numeric value");
        if (endch)
                *endch = endchar[0];
        return(value);
        if (endch)
                *endch = endchar[0];
        return(value);
@@ -118,8 +111,8 @@ c_atime(arg)
 
        ftsoptions &= ~FTS_NOSTAT;
 
 
        ftsoptions &= ~FTS_NOSTAT;
 
-       NEW(N_ATIME, f_atime);
-       new->t_data = find_parsenum(new, "-atime", arg, (char *)NULL);
+       new = palloc(N_ATIME, f_atime);
+       new->t_data = find_parsenum(new, "-atime", arg, NULL);
        return(new);
 }
 /*
        return(new);
 }
 /*
@@ -146,7 +139,7 @@ c_ctime(arg)
 
        ftsoptions &= ~FTS_NOSTAT;
 
 
        ftsoptions &= ~FTS_NOSTAT;
 
-       NEW(N_CTIME, f_ctime);
+       new = palloc(N_CTIME, f_ctime);
        new->t_data = find_parsenum(new, "-ctime", arg, (char *)NULL);
        return(new);
 }
        new->t_data = find_parsenum(new, "-ctime", arg, (char *)NULL);
        return(new);
 }
@@ -169,12 +162,9 @@ f_always_true(plan, entry)
 PLAN *
 c_depth()
 {
 PLAN *
 c_depth()
 {
-       PLAN *new;
-    
        isdepth = 1;
 
        isdepth = 1;
 
-       NEW(N_DEPTH, f_always_true);
-       return(new);
+       return(palloc(N_DEPTH, f_always_true));
 }
  
 /*
 }
  
 /*
@@ -196,7 +186,6 @@ f_exec(plan, entry)
        register int cnt;
        pid_t pid;
        int status;
        register int cnt;
        pid_t pid;
        int status;
-       void brace_subst();
 
        for (cnt = 0; plan->e_argv[cnt]; ++cnt)
                if (plan->e_len[cnt])
 
        for (cnt = 0; plan->e_argv[cnt]; ++cnt)
                if (plan->e_len[cnt])
@@ -208,13 +197,11 @@ f_exec(plan, entry)
 
        switch(pid = vfork()) {
        case -1:
 
        switch(pid = vfork()) {
        case -1:
-               error("fork", errno);
-               exit(1);
+               err("fork: %s", strerror(errno));
                /* NOTREACHED */
        case 0:
                execvp(plan->e_argv[0], plan->e_argv);
                /* NOTREACHED */
        case 0:
                execvp(plan->e_argv[0], plan->e_argv);
-               error(plan->e_argv[0], errno);
-               exit(1);
+               err("%s: %s", plan->e_argv[0], strerror(errno));
                /* NOTREACHED */
        }
        pid = waitpid(pid, &status, 0);
                /* NOTREACHED */
        }
        pid = waitpid(pid, &status, 0);
@@ -236,18 +223,18 @@ c_exec(argvp, isok)
        PLAN *new;                      /* node returned */
        register int cnt;
        register char **argv, **ap, *p;
        PLAN *new;                      /* node returned */
        register int cnt;
        register char **argv, **ap, *p;
-       void bad_arg();
 
        if (!isrelative)
                ftsoptions |= FTS_NOCHDIR;
        isoutput = 1;
     
 
        if (!isrelative)
                ftsoptions |= FTS_NOCHDIR;
        isoutput = 1;
     
-       NEW(N_EXEC, f_exec);
+       new = palloc(N_EXEC, f_exec);
        new->flags = isok;
 
        for (ap = argv = *argvp;; ++ap) {
                if (!*ap)
        new->flags = isok;
 
        for (ap = argv = *argvp;; ++ap) {
                if (!*ap)
-                       bad_arg(isok ? "-ok" : "-exec", "no terminating \";\"");
+                       err("%s: %s",
+                           isok ? "-ok" : "-exec", "no terminating \";\"");
                if (**ap == ';')
                        break;
        }
                if (**ap == ';')
                        break;
        }
@@ -285,13 +272,10 @@ c_exec(argvp, isok)
 PLAN *
 c_follow()
 {
 PLAN *
 c_follow()
 {
-       PLAN *new;
-    
        ftsoptions &= ~FTS_PHYSICAL;
        ftsoptions |= FTS_LOGICAL;
 
        ftsoptions &= ~FTS_PHYSICAL;
        ftsoptions |= FTS_LOGICAL;
 
-       NEW(N_FOLLOW, f_always_true);
-       return(new);
+       return(palloc(N_FOLLOW, f_always_true));
 }
  
 /*
 }
  
 /*
@@ -331,10 +315,8 @@ f_fstype(plan, entry)
                } else 
                        p = NULL;
 
                } else 
                        p = NULL;
 
-               if (statfs(entry->fts_accpath, &sb)) {
-                       error(entry->fts_accpath, errno);
-                       exit(1);
-               }
+               if (statfs(entry->fts_accpath, &sb))
+                       err("%s: %s", entry->fts_accpath, strerror(errno));
 
                if (p) {
                        p[0] = save[0];
 
                if (p) {
                        p[0] = save[0];
@@ -356,7 +338,7 @@ c_fstype(arg)
     
        ftsoptions &= ~FTS_NOSTAT;
     
     
        ftsoptions &= ~FTS_NOSTAT;
     
-       NEW(N_FSTYPE, f_fstype);
+       new = palloc(N_FSTYPE, f_fstype);
        switch(*arg) {
        case 'l':
                if (!strcmp(arg, "local")) {
        switch(*arg) {
        case 'l':
                if (!strcmp(arg, "local")) {
@@ -389,8 +371,7 @@ c_fstype(arg)
                }
                break;
        }
                }
                break;
        }
-       (void)fprintf(stderr, "find: unknown file type %s.\n", arg);
-       exit(1);
+       err("unknown file type %s", arg);
        /* NOTREACHED */
 }
  
        /* NOTREACHED */
 }
  
@@ -415,7 +396,6 @@ c_group(gname)
        PLAN *new;
        struct group *g;
        gid_t gid;
        PLAN *new;
        struct group *g;
        gid_t gid;
-       void bad_arg();
     
        ftsoptions &= ~FTS_NOSTAT;
 
     
        ftsoptions &= ~FTS_NOSTAT;
 
@@ -423,11 +403,11 @@ c_group(gname)
        if (g == NULL) {
                gid = atoi(gname);
                if (gid == 0 && gname[0] != '0')
        if (g == NULL) {
                gid = atoi(gname);
                if (gid == 0 && gname[0] != '0')
-                       bad_arg("-group", "no such group");
+                       err("%s: %s", "-group", "no such group");
        } else
                gid = g->gr_gid;
     
        } else
                gid = g->gr_gid;
     
-       NEW(N_GROUP, f_group);
+       new = palloc(N_GROUP, f_group);
        new->g_data = gid;
        return(new);
 }
        new->g_data = gid;
        return(new);
 }
@@ -452,7 +432,7 @@ c_inum(arg)
     
        ftsoptions &= ~FTS_NOSTAT;
     
     
        ftsoptions &= ~FTS_NOSTAT;
     
-       NEW(N_INUM, f_inum);
+       new = palloc(N_INUM, f_inum);
        new->i_data = find_parsenum(new, "-inum", arg, (char *)NULL);
        return(new);
 }
        new->i_data = find_parsenum(new, "-inum", arg, (char *)NULL);
        return(new);
 }
@@ -477,7 +457,7 @@ c_links(arg)
     
        ftsoptions &= ~FTS_NOSTAT;
     
     
        ftsoptions &= ~FTS_NOSTAT;
     
-       NEW(N_LINKS, f_links);
+       new = palloc(N_LINKS, f_links);
        new->l_data = (nlink_t)find_parsenum(new, "-links", arg, (char *)NULL);
        return(new);
 }
        new->l_data = (nlink_t)find_parsenum(new, "-links", arg, (char *)NULL);
        return(new);
 }
@@ -501,13 +481,10 @@ f_ls(plan, entry)
 PLAN *
 c_ls()
 {
 PLAN *
 c_ls()
 {
-       PLAN *new;
-    
        ftsoptions &= ~FTS_NOSTAT;
        isoutput = 1;
     
        ftsoptions &= ~FTS_NOSTAT;
        isoutput = 1;
     
-       NEW(N_LS, f_ls);
-       return(new);
+       return(palloc(N_LS, f_ls));
 }
 
 /*
 }
 
 /*
@@ -529,7 +506,7 @@ c_name(pattern)
 {
        PLAN *new;
 
 {
        PLAN *new;
 
-       NEW(N_NAME, f_name);
+       new = palloc(N_NAME, f_name);
        new->c_data = pattern;
        return(new);
 }
        new->c_data = pattern;
        return(new);
 }
@@ -557,11 +534,9 @@ c_newer(filename)
     
        ftsoptions &= ~FTS_NOSTAT;
 
     
        ftsoptions &= ~FTS_NOSTAT;
 
-       if (stat(filename, &sb)) {
-               error(filename, errno);
-               exit(1);
-       }
-       NEW(N_NEWER, f_newer);
+       if (stat(filename, &sb))
+               err("%s: %s", filename, strerror(errno));
+       new = palloc(N_NEWER, f_newer);
        new->t_data = sb.st_mtime;
        return(new);
 }
        new->t_data = sb.st_mtime;
        return(new);
 }
@@ -585,12 +560,9 @@ f_nogroup(plan, entry)
 PLAN *
 c_nogroup()
 {
 PLAN *
 c_nogroup()
 {
-       PLAN *new;
-    
        ftsoptions &= ~FTS_NOSTAT;
 
        ftsoptions &= ~FTS_NOSTAT;
 
-       NEW(N_NOGROUP, f_nogroup);
-       return(new);
+       return(palloc(N_NOGROUP, f_nogroup));
 }
  
 /*
 }
  
 /*
@@ -612,12 +584,9 @@ f_nouser(plan, entry)
 PLAN *
 c_nouser()
 {
 PLAN *
 c_nouser()
 {
-       PLAN *new;
-    
        ftsoptions &= ~FTS_NOSTAT;
 
        ftsoptions &= ~FTS_NOSTAT;
 
-       NEW(N_NOUSER, f_nouser);
-       return(new);
+       return(palloc(N_NOUSER, f_nouser));
 }
  
 /*
 }
  
 /*
@@ -648,11 +617,10 @@ c_perm(perm)
 {
        PLAN *new;
        mode_t *set;
 {
        PLAN *new;
        mode_t *set;
-       void bad_arg();
 
        ftsoptions &= ~FTS_NOSTAT;
 
 
        ftsoptions &= ~FTS_NOSTAT;
 
-       NEW(N_PERM, f_perm);
+       new = palloc(N_PERM, f_perm);
 
        if (*perm == '-') {
                new->flags = 1;
 
        if (*perm == '-') {
                new->flags = 1;
@@ -660,7 +628,7 @@ c_perm(perm)
        }
 
        if ((set = setmode(perm)) == NULL)
        }
 
        if ((set = setmode(perm)) == NULL)
-               bad_arg("-perm", "illegal mode string");
+               err("%s: %s", "-perm", "illegal mode string");
 
        new->m_data = getmode(set, 0);
        return(new);
 
        new->m_data = getmode(set, 0);
        return(new);
@@ -684,12 +652,9 @@ f_print(plan, entry)
 PLAN *
 c_print()
 {
 PLAN *
 c_print()
 {
-       PLAN *new;
-    
        isoutput = 1;
 
        isoutput = 1;
 
-       NEW(N_PRINT, f_print);
-       return(new);
+       return(palloc(N_PRINT, f_print));
 }
  
 /*
 }
  
 /*
@@ -704,20 +669,15 @@ f_prune(plan, entry)
 {
        extern FTS *tree;
 
 {
        extern FTS *tree;
 
-       if (fts_set(tree, entry, FTS_SKIP)) {
-               error(entry->fts_path, errno);
-               exit(1);
-       }
+       if (fts_set(tree, entry, FTS_SKIP))
+               err("%s: %s", entry->fts_path, strerror(errno));
        return(1);
 }
  
 PLAN *
 c_prune()
 {
        return(1);
 }
  
 PLAN *
 c_prune()
 {
-       PLAN *new;
-
-       NEW(N_PRUNE, f_prune);
-       return(new);
+       return(palloc(N_PRUNE, f_prune));
 }
  
 /*
 }
  
 /*
@@ -750,7 +710,7 @@ c_size(arg)
     
        ftsoptions &= ~FTS_NOSTAT;
 
     
        ftsoptions &= ~FTS_NOSTAT;
 
-       NEW(N_SIZE, f_size);
+       new = palloc(N_SIZE, f_size);
        new->o_data = find_parsenum(new, "-size", arg, &endch);
        if (endch == 'c')
                divsize = 0;
        new->o_data = find_parsenum(new, "-size", arg, &endch);
        if (endch == 'c')
                divsize = 0;
@@ -777,7 +737,6 @@ c_type(typestring)
 {
        PLAN *new;
        mode_t  mask;
 {
        PLAN *new;
        mode_t  mask;
-       void bad_arg();
     
        ftsoptions &= ~FTS_NOSTAT;
 
     
        ftsoptions &= ~FTS_NOSTAT;
 
@@ -804,10 +763,10 @@ c_type(typestring)
                mask = S_IFSOCK;
                break;
        default:
                mask = S_IFSOCK;
                break;
        default:
-               bad_arg("-type", "unknown type");
+               err("%s: %s", "-type", "unknown type");
        }
     
        }
     
-       NEW(N_TYPE, f_type);
+       new = palloc(N_TYPE, f_type);
        new->m_data = mask;
        return(new);
 }
        new->m_data = mask;
        return(new);
 }
@@ -833,7 +792,6 @@ c_user(username)
        PLAN *new;
        struct passwd *p;
        uid_t uid;
        PLAN *new;
        struct passwd *p;
        uid_t uid;
-       void bad_arg();
     
        ftsoptions &= ~FTS_NOSTAT;
 
     
        ftsoptions &= ~FTS_NOSTAT;
 
@@ -841,11 +799,11 @@ c_user(username)
        if (p == NULL) {
                uid = atoi(username);
                if (uid == 0 && username[0] != '0')
        if (p == NULL) {
                uid = atoi(username);
                if (uid == 0 && username[0] != '0')
-                       bad_arg("-user", "no such user");
+                       err("%s: %s", "-user", "no such user");
        } else
                uid = p->pw_uid;
 
        } else
                uid = p->pw_uid;
 
-       NEW(N_USER, f_user);
+       new = palloc(N_USER, f_user);
        new->u_data = uid;
        return(new);
 }
        new->u_data = uid;
        return(new);
 }
@@ -859,12 +817,9 @@ c_user(username)
 PLAN *
 c_xdev()
 {
 PLAN *
 c_xdev()
 {
-       PLAN *new;
-    
        ftsoptions |= FTS_XDEV;
 
        ftsoptions |= FTS_XDEV;
 
-       NEW(N_XDEV, f_always_true);
-       return(new);
+       return(palloc(N_XDEV, f_always_true));
 }
 
 /*
 }
 
 /*
@@ -892,19 +847,13 @@ f_expr(plan, entry)
 PLAN *
 c_openparen()
 {
 PLAN *
 c_openparen()
 {
-       PLAN *new;
-
-       NEW(N_OPENPAREN, (int (*)())-1);
-       return(new);
+       return(palloc(N_OPENPAREN, (int (*)())-1));
 }
  
 PLAN *
 c_closeparen()
 {
 }
  
 PLAN *
 c_closeparen()
 {
-       PLAN *new;
-
-       NEW(N_CLOSEPAREN, (int (*)())-1);
-       return(new);
+       return(palloc(N_CLOSEPAREN, (int (*)())-1));
 }
  
 /*
 }
  
 /*
@@ -931,7 +880,7 @@ c_mtime(arg)
 
        ftsoptions &= ~FTS_NOSTAT;
 
 
        ftsoptions &= ~FTS_NOSTAT;
 
-       NEW(N_MTIME, f_mtime);
+       new = palloc(N_MTIME, f_mtime);
        new->t_data = find_parsenum(new, "-mtime", arg, (char *)NULL);
        return(new);
 }
        new->t_data = find_parsenum(new, "-mtime", arg, (char *)NULL);
        return(new);
 }
@@ -956,10 +905,7 @@ f_not(plan, entry)
 PLAN *
 c_not()
 {
 PLAN *
 c_not()
 {
-       PLAN *new;
-
-       NEW(N_NOT, f_not);
-       return(new);
+       return(palloc(N_NOT, f_not));
 }
  
 /*
 }
  
 /*
@@ -988,9 +934,24 @@ f_or(plan, entry)
 
 PLAN *
 c_or()
 
 PLAN *
 c_or()
+{
+       return(palloc(N_OR, f_or));
+}
+
+static PLAN *
+palloc(t, f)
+       enum ntype t;
+       int (*f)();
 {
        PLAN *new;
 
 {
        PLAN *new;
 
-       NEW(N_OR, f_or);
-       return(new);
+       if (new = malloc(sizeof(PLAN))) {
+               new->type = t;
+               new->eval = f;
+               new->flags = 0;
+               new->next = NULL;
+               return(new);
+       }
+       err("%s", strerror(errno));
+       /* NOTREACHED */
 }
 }
index ed49bee..1bc7679 100644 (file)
@@ -6,34 +6,46 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     5.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     5.8 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <sys/stat.h>
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <time.h>
 #include <fts.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include "find.h"
 
 #include <fts.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include "find.h"
 
-void
-newsyntax(argc, argvp)
+time_t now;                    /* time find was run */
+int ftsoptions;                        /* options for the ftsopen(3) call */
+int isdeprecated;              /* using deprecated syntax */
+int isdepth;                   /* do directories on post-order visit */
+int isoutput;                  /* user specified output operator */
+int isrelative;                        /* can do -exec/ok on relative path */
+int isxargs;                   /* don't permit xargs delimiting chars */
+
+static void usage();
+
+main(argc, argv)
        int argc;
        int argc;
-       char ***argvp;
+       char **argv;
 {
 {
-       extern int optind;
-       extern char *optarg;
+       register char **p, **start;
+       PLAN *find_formplan();
        int ch;
        int ch;
-       char **argv, **cur;
 
 
-       cur = argv = *argvp;
+       (void)time(&now);       /* initialize the time-of-day */
+
+       p = start = argv;
+       ftsoptions = FTS_NOSTAT|FTS_PHYSICAL;
        while ((ch = getopt(argc, argv, "df:rsXx")) != EOF)
                switch(ch) {
                case 'd':
                        isdepth = 1;
                        break;
                case 'f':
        while ((ch = getopt(argc, argv, "df:rsXx")) != EOF)
                switch(ch) {
                case 'd':
                        isdepth = 1;
                        break;
                case 'f':
-                       *cur++ = optarg;
+                       *p++ = optarg;
                        break;
                case 'r':
                        isrelative = 1;
                        break;
                case 'r':
                        isrelative = 1;
@@ -51,15 +63,30 @@ newsyntax(argc, argvp)
                        break;
                case '?':
                default:
                        break;
                case '?':
                default:
-                       usage();
+                       break;
                }
 
                }
 
-       *argvp += optind;
-       if (cur == argv) {
-               if (!**argvp)
-                       usage();
-               *cur++ = **argvp;
-               ++*argvp;
+       argc -= optind; 
+       argv += optind;
+
+       /* Find first option to delimit the file list. */
+       while (*argv) {
+               if (option(*argv))
+                       break;
+               *p++ = *argv++;
        }
        }
-       *cur = NULL;
+
+       if (p == start)
+               usage();
+       *p = NULL;
+
+       find_execute(find_formplan(argv), start);
+}
+
+static void
+usage()
+{
+       (void)fprintf(stderr,
+           "usage: find [-drsXx] [-f file] [file ...] expression\n");
+       exit(1);
 }
 }
index b9d8891..038a0be 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)misc.c     5.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)misc.c     5.8 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -36,11 +36,8 @@ brace_subst(orig, store, path, len)
        for (p = *store; ch = *orig; ++orig)
                if (ch == '{' && orig[1] == '}') {
                        while ((p - *store) + plen > len)
        for (p = *store; ch = *orig; ++orig)
                if (ch == '{' && orig[1] == '}') {
                        while ((p - *store) + plen > len)
-                               if (!(*store = realloc(*store, len *= 2))) {
-                                       (void)fprintf(stderr,
-                                           "find: %s.\n", strerror(errno));
-                                       exit(1);
-                               }
+                               if (!(*store = realloc(*store, len *= 2)))
+                                       err("%s", strerror(errno));
                        bcopy(path, p, plen);
                        p += plen;
                        ++orig;
                        bcopy(path, p, plen);
                        p += plen;
                        ++orig;
@@ -83,18 +80,6 @@ queryuser(argv)
         return(first == 'y');
 }
  
         return(first == 'y');
 }
  
-/*
- * bad_arg --
- *     print out a bad argument message.
- */
-void
-bad_arg(option, err)
-       char *option, *err;
-{
-       (void)fprintf(stderr, "find: %s: %s.\n", option, err);
-       exit(1);
-}
 /*
  * emalloc --
  *     malloc with error checking.
 /*
  * emalloc --
  *     malloc with error checking.
@@ -105,19 +90,37 @@ emalloc(len)
 {
        void *p;
 
 {
        void *p;
 
-       if (!(p = malloc(len))) {
-               (void)fprintf(stderr, "find: %s.\n", strerror(errno));
-               exit(1);
-       }
-       return(p);
+       if (p = malloc(len))
+               return(p);
+       err("%s", strerror(errno));
+       /* NOTREACHED */
 }
 
 }
 
-usage()
+#if __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+
+void
+#if __STDC__
+err(const char *fmt, ...)
+#else
+err(fmt, va_alist)
+       char *fmt;
+        va_dcl
+#endif
 {
 {
-       if (isdeprecated)
-               (void)fprintf(stderr, "usage: find path-list expression\n");
-       else
-               (void)fprintf(stderr,
-                   "usage: find [-drsx] -f path ... expression\n");
+       va_list ap;
+#if __STDC__
+       va_start(ap, fmt);
+#else
+       va_start(ap);
+#endif
+       (void)fprintf(stderr, "find: ");
+       (void)vfprintf(stderr, fmt, ap);
+       va_end(ap);
+       (void)fprintf(stderr, "\n");
        exit(1);
        exit(1);
+       /* NOTREACHED */
 }
 }
index 1013b53..fa5d189 100644 (file)
@@ -9,20 +9,18 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)operator.c 5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)operator.c 5.4 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <stdio.h>
 #include "find.h"
     
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <stdio.h>
 #include "find.h"
     
-void bad_arg();
-
 /*
  * yanknode --
  *     destructively removes the top from the plan
  */
 /*
  * yanknode --
  *     destructively removes the top from the plan
  */
-PLAN *
+static PLAN *
 yanknode(planp)    
        PLAN **planp;           /* pointer to top of plan (modified) */
 {
 yanknode(planp)    
        PLAN **planp;           /* pointer to top of plan (modified) */
 {
@@ -41,7 +39,7 @@ yanknode(planp)
  *     paren_squish.  In comments below, an expression is either a
  *     simple node or a N_EXPR node containing a list of simple nodes.
  */
  *     paren_squish.  In comments below, an expression is either a
  *     simple node or a N_EXPR node containing a list of simple nodes.
  */
-PLAN *
+static PLAN *
 yankexpr(planp)    
        PLAN **planp;           /* pointer to top of plan (modified) */
 {
 yankexpr(planp)    
        PLAN **planp;           /* pointer to top of plan (modified) */
 {
@@ -64,7 +62,7 @@ yankexpr(planp)
        if (node->type == N_OPENPAREN)
                for (tail = subplan = NULL;;) {
                        if ((next = yankexpr(planp)) == NULL)
        if (node->type == N_OPENPAREN)
                for (tail = subplan = NULL;;) {
                        if ((next = yankexpr(planp)) == NULL)
-                               bad_arg("(", "missing closing ')'");
+                               err("%s: %s", "(", "missing closing ')'");
                        /*
                         * If we find a closing ')' we store the collected
                         * subplan in our '(' node and convert the node to
                        /*
                         * If we find a closing ')' we store the collected
                         * subplan in our '(' node and convert the node to
@@ -74,7 +72,8 @@ yankexpr(planp)
                         */
                        if (next->type == N_CLOSEPAREN) {
                                if (subplan == NULL)
                         */
                        if (next->type == N_CLOSEPAREN) {
                                if (subplan == NULL)
-                                       bad_arg("()", "empty inner expression");
+                                       err("%s: %s",
+                                           "()", "empty inner expression");
                                node->p_data[0] = subplan;
                                node->type = N_EXPR;
                                node->eval = f_expr;
                                node->p_data[0] = subplan;
                                node->type = N_EXPR;
                                node->eval = f_expr;
@@ -116,7 +115,7 @@ paren_squish(plan)
                 * '(' someplace.
                 */
                if (expr->type == N_CLOSEPAREN)
                 * '(' someplace.
                 */
                if (expr->type == N_CLOSEPAREN)
-                       bad_arg(")", "no beginning '('");
+                       err("%s: %s", ")", "no beginning '('");
 
                /* add the expression to our result plan */
                if (result == NULL)
 
                /* add the expression to our result plan */
                if (result == NULL)
@@ -167,9 +166,9 @@ not_squish(plan)
                                node = yanknode(&plan);
                        }
                        if (node == NULL)
                                node = yanknode(&plan);
                        }
                        if (node == NULL)
-                               bad_arg("!", "no following expression");
+                               err("%s: %s", "!", "no following expression");
                        if (node->type == N_OR)
                        if (node->type == N_OR)
-                               bad_arg("!", "nothing between ! and -o");
+                               err("%s: %s", "!", "nothing between ! and -o");
                        if (notlevel % 2 != 1)
                                next = node;
                        else
                        if (notlevel % 2 != 1)
                                next = node;
                        else
@@ -221,11 +220,11 @@ or_squish(plan)
                 */
                if (next->type == N_OR) {
                        if (result == NULL)
                 */
                if (next->type == N_OR) {
                        if (result == NULL)
-                               bad_arg("-o", "no expression before -o");
+                               err("%s: %s", "-o", "no expression before -o");
                        next->p_data[0] = result;
                        next->p_data[1] = or_squish(plan);
                        if (next->p_data[1] == NULL)
                        next->p_data[0] = result;
                        next->p_data[1] = or_squish(plan);
                        if (next->p_data[1] == NULL)
-                               bad_arg("-o", "no expression after -o");
+                               err("%s: %s", "-o", "no expression after -o");
                        return(next);
                }
 
                        return(next);
                }
 
index 81b97ef..86ec6d1 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)option.c   5.6 (Berkeley) %G%";
+static char sccsid[] = "@(#)option.c   5.7 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -28,50 +28,40 @@ typedef struct _option {
 #define        O_ZERO          0x02    /* pass: nothing */
 #define        O_ARGV          0x04    /* pass: argv, increment argv */
 #define        O_ARGVP         0x08    /* pass: *argv, N_OK || N_EXEC */
 #define        O_ZERO          0x02    /* pass: nothing */
 #define        O_ARGV          0x04    /* pass: argv, increment argv */
 #define        O_ARGVP         0x08    /* pass: *argv, N_OK || N_EXEC */
-#define        O_MASK          0x0f    /* mask of op bits */
-#define        O_OLD           0x10    /* deprecated syntax */
-#define        O_NEW           0x20    /* new syntax */
        int flags;
 } OPTION;
 
        int flags;
 } OPTION;
 
-PLAN   *c_atime(), *c_ctime(), *c_depth(), *c_exec(), *c_follow(),
-       *c_fstype(), *c_group(), *c_inum(), *c_links(), *c_ls(),
-       *c_mtime(), *c_name(), *c_newer(), *c_nogroup(), *c_nouser(),
-       *c_perm(), *c_print(), *c_prune(), *c_size(), *c_type(),
-       *c_user(), *c_xdev(), *c_openparen(), *c_closeparen(), *c_not(),
-       *c_or();
-
 OPTION options[] = {
        "!",            N_NOT,          c_not,          O_ZERO,
        "(",            N_OPENPAREN,    c_openparen,    O_ZERO,
        ")",            N_CLOSEPAREN,   c_closeparen,   O_ZERO,
 OPTION options[] = {
        "!",            N_NOT,          c_not,          O_ZERO,
        "(",            N_OPENPAREN,    c_openparen,    O_ZERO,
        ")",            N_CLOSEPAREN,   c_closeparen,   O_ZERO,
-       "a",            N_AND,          NULL,           O_NONE|O_OLD,
-       "and",          N_AND,          NULL,           O_NONE|O_NEW,
-       "atime",        N_ATIME,        c_atime,        O_ARGV,
-       "ctime",        N_CTIME,        c_ctime,        O_ARGV,
-       "depth",        N_DEPTH,        c_depth,        O_ZERO|O_OLD,
-       "exec",         N_EXEC,         c_exec,         O_ARGVP,
-       "follow",       N_FOLLOW,       c_follow,       O_ZERO|O_OLD,
-       "fstype",       N_FSTYPE,       c_fstype,       O_ARGV,
-       "group",        N_GROUP,        c_group,        O_ARGV,
-       "inum",         N_INUM,         c_inum,         O_ARGV,
-       "links",        N_LINKS,        c_links,        O_ARGV,
-       "ls",           N_LS,           c_ls,           O_ZERO,
-       "mtime",        N_MTIME,        c_mtime,        O_ARGV,
-       "name",         N_NAME,         c_name,         O_ARGV,
-       "newer",        N_NEWER,        c_newer,        O_ARGV,
-       "nogroup",      N_NOGROUP,      c_nogroup,      O_ZERO,
-       "nouser",       N_NOUSER,       c_nouser,       O_ZERO,
-       "o",            N_OR,           c_or,           O_ZERO|O_OLD,
-       "ok",           N_OK,           c_exec,         O_ARGVP,
-       "or",           N_OR,           c_or,           O_ZERO|O_NEW,
-       "perm",         N_PERM,         c_perm,         O_ARGV,
-       "print",        N_PRINT,        c_print,        O_ZERO,
-       "prune",        N_PRUNE,        c_prune,        O_ZERO,
-       "size",         N_SIZE,         c_size,         O_ARGV,
-       "type",         N_TYPE,         c_type,         O_ARGV,
-       "user",         N_USER,         c_user,         O_ARGV,
-       "xdev",         N_XDEV,         c_xdev,         O_ZERO|O_OLD,
+       "-a",           N_AND,          NULL,           O_NONE,
+       "-and",         N_AND,          NULL,           O_NONE,
+       "-atime",       N_ATIME,        c_atime,        O_ARGV,
+       "-ctime",       N_CTIME,        c_ctime,        O_ARGV,
+       "-depth",       N_DEPTH,        c_depth,        O_ZERO,
+       "-exec",        N_EXEC,         c_exec,         O_ARGVP,
+       "-follow",      N_FOLLOW,       c_follow,       O_ZERO,
+       "-fstype",      N_FSTYPE,       c_fstype,       O_ARGV,
+       "-group",       N_GROUP,        c_group,        O_ARGV,
+       "-inum",        N_INUM,         c_inum,         O_ARGV,
+       "-links",       N_LINKS,        c_links,        O_ARGV,
+       "-ls",          N_LS,           c_ls,           O_ZERO,
+       "-mtime",       N_MTIME,        c_mtime,        O_ARGV,
+       "-name",        N_NAME,         c_name,         O_ARGV,
+       "-newer",       N_NEWER,        c_newer,        O_ARGV,
+       "-nogroup",     N_NOGROUP,      c_nogroup,      O_ZERO,
+       "-nouser",      N_NOUSER,       c_nouser,       O_ZERO,
+       "-o",           N_OR,           c_or,           O_ZERO,
+       "-ok",          N_OK,           c_exec,         O_ARGVP,
+       "-or",          N_OR,           c_or,           O_ZERO,
+       "-perm",        N_PERM,         c_perm,         O_ARGV,
+       "-print",       N_PRINT,        c_print,        O_ZERO,
+       "-prune",       N_PRUNE,        c_prune,        O_ZERO,
+       "-size",        N_SIZE,         c_size,         O_ARGV,
+       "-type",        N_TYPE,         c_type,         O_ARGV,
+       "-user",        N_USER,         c_user,         O_ARGV,
+       "-xdev",        N_XDEV,         c_xdev,         O_ZERO,
        { NULL },
 };
 
        { NULL },
 };
 
@@ -88,32 +78,24 @@ find_create(argvp)
        char ***argvp;
 {
        register OPTION *p;
        char ***argvp;
 {
        register OPTION *p;
-       OPTION tmp;
        PLAN *new;
        char **argv;
        PLAN *new;
        char **argv;
-       int typecompare();
+       OPTION *option();
 
        argv = *argvp;
 
        argv = *argvp;
-       tmp.name = *argv++;
 
 
-       /* strip off any leading dash */
-       if (*tmp.name == '-')
-               ++tmp.name;
-
-       p = (OPTION *)bsearch(&tmp, options, sizeof(options)/sizeof(OPTION),
-           sizeof(OPTION), typecompare);
-       if (!p || isdeprecated && p->flags&O_NEW ||
-           !isdeprecated && p->flags&O_OLD) {
-               (void)fprintf(stderr, "find: unknown option %s.\n", *--argv);
+       if ((p = option(*argv)) == NULL) {
+               (void)fprintf(stderr, "find: unknown option %s.\n", *argv);
                exit(1);
        }
                exit(1);
        }
+       ++argv;
        if (p->flags & (O_ARGV|O_ARGVP) && !*argv) {
                (void)fprintf(stderr,
                    "find: %s requires additional arguments.\n", *--argv);
                exit(1);
        }
 
        if (p->flags & (O_ARGV|O_ARGVP) && !*argv) {
                (void)fprintf(stderr,
                    "find: %s requires additional arguments.\n", *--argv);
                exit(1);
        }
 
-       switch(p->flags&O_MASK) {
+       switch(p->flags) {
        case O_NONE:
                new = NULL;
                break;
        case O_NONE:
                new = NULL;
                break;
@@ -131,6 +113,18 @@ find_create(argvp)
        return(new);
 }
 
        return(new);
 }
 
+OPTION *
+option(name)
+       char *name;
+{
+       OPTION tmp;
+       int typecompare();
+
+       tmp.name = name;
+       return((OPTION *)bsearch(&tmp, options,
+           sizeof(options)/sizeof(OPTION), sizeof(OPTION), typecompare));
+}
+       
 typecompare(a, b)
        OPTION *a, *b;
 {
 typecompare(a, b)
        OPTION *a, *b;
 {