BSD 4_3_Tahoe release
[unix-history] / usr / src / usr.bin / find / find.c
index 2199f6b..1c17130 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef        lint
 #ifndef        lint
-static char *sccsid = "@(#)find.c      4.17 (Berkeley) %G%";
+static char *sccsid = "@(#)find.c      4.20 (Berkeley) 9/28/87";
 #endif
 
 #include <stdio.h>
 #endif
 
 #include <stdio.h>
@@ -35,6 +35,7 @@ int   Wct = 2560;
 long   Newer;
 
 int    Xdev = 1;       /* true if SHOULD cross devices (file systems) */
 long   Newer;
 
 int    Xdev = 1;       /* true if SHOULD cross devices (file systems) */
+int    follow;         /* true if SHOULD descend symlinked directories */
 struct stat Devstat;   /* stats of each argument path's file system */
 
 struct stat Statb;
 struct stat Devstat;   /* stats of each argument path's file system */
 
 struct stat Statb;
@@ -197,7 +198,7 @@ struct anode *e2() { /* parse NOT (!) */
 struct anode *e3() { /* parse parens and predicates */
        int exeq(), ok(), glob(),  mtime(), atime(), user(),
                group(), size(), perm(), links(), print(),
 struct anode *e3() { /* parse parens and predicates */
        int exeq(), ok(), glob(),  mtime(), atime(), user(),
                group(), size(), perm(), links(), print(),
-               type(), ino(), cpio(), newer(),
+               type(), ino(), cpio(), newer(), 
                nouser(), nogroup(), ls(), dummy();
        struct anode *p1;
        int i;
                nouser(), nogroup(), ls(), dummy();
        struct anode *p1;
        int i;
@@ -228,6 +229,10 @@ struct anode *e3() { /* parse parens and predicates */
                Xdev = 0;
                return (mk(dummy, (struct anode *)0, (struct anode *)0));
        }
                Xdev = 0;
                return (mk(dummy, (struct anode *)0, (struct anode *)0));
        }
+       else if (EQ(a, "-follow")) {
+               follow=1;
+               return mk(dummy, (struct anode *)0, (struct anode *)0);
+       }
        b = nxtarg();
        s = *b;
        if(s=='+') b++;
        b = nxtarg();
        s = *b;
        if(s=='+') b++;
@@ -634,7 +639,7 @@ descend(name, fname, exlist)
        int rv = 0;
        char *endofname;
 
        int rv = 0;
        char *endofname;
 
-       if (lstat(fname, &Statb)<0) {
+       if ((follow?stat(fname, &Statb):lstat(fname, &Statb))<0) {
                fprintf(stderr, "find: bad status < %s >\n", name);
                return(0);
        }
                fprintf(stderr, "find: bad status < %s >\n", name);
                return(0);
        }
@@ -643,6 +648,10 @@ descend(name, fname, exlist)
           !Xdev && Devstat.st_dev != Statb.st_dev)
                return(1);
 
           !Xdev && Devstat.st_dev != Statb.st_dev)
                return(1);
 
+       if (Statb.st_nlink == 2 && exlist->F == and &&
+               exlist->L->F == type && ((int) (exlist->L->L)) == S_IFDIR)
+                       return(1);
+
        for (c1 = name; *c1; ++c1);
        if (*(c1-1) == '/')
                --c1;
        for (c1 = name; *c1; ++c1);
        if (*(c1-1) == '/')
                --c1;
@@ -846,9 +855,9 @@ fastfind ( pathpart )
        }
        for ( i = 0; i < 128; i++ ) 
                bigram1[i] = getc ( fp ),  bigram2[i] = getc ( fp );
        }
        for ( i = 0; i < 128; i++ ) 
                bigram1[i] = getc ( fp ),  bigram2[i] = getc ( fp );
-       
-       if ( index ( pathpart, '*' ) || index ( pathpart, '?' ) || index ( pathpart, '[' ) )
-               globflag = YES;
+
+       globflag = index ( pathpart, '*' ) || index ( pathpart, '?' ) ||
+               index ( pathpart, '[' );
        patend = patprep ( pathpart );
 
        c = getc ( fp );
        patend = patprep ( pathpart );
 
        c = getc ( fp );