Ansified usr.bin/find
authorNick Downing <downing.nick@gmail.com>
Tue, 31 Jan 2017 07:40:42 +0000 (18:40 +1100)
committerNick Downing <downing.nick@gmail.com>
Tue, 31 Jan 2017 07:40:42 +0000 (18:40 +1100)
usr.bin/find/bigram.c
usr.bin/find/code.c
usr.bin/find/find.c

index 3e71413..7891bbc 100644 (file)
@@ -1,6 +1,9 @@
-#ifndef lint
+#include <stdio.h>
+#include <strings.h>
+
+#if defined(DOSCCS) && !defined(lint)
 static char sccsid[] = "@(#)bigram.c   4.2     (Berkeley)      7/21/83";
-#endif not lint
+#endif
 
 /*
  *  bigram < text > bigrams
@@ -9,15 +12,25 @@ static char sccsid[] = "@(#)bigram.c 4.2     (Berkeley)      7/21/83";
  * Use 'code' to encode a file using this output.
  */
 
-#include <stdio.h>
+/*#include <stdio.h>*/
 
 #define MAXPATH        1024            /* maximum pathname length */
 
 char path[MAXPATH];
 char oldpath[MAXPATH] = " ";   
 
-main ( )
-{
+#ifndef __P
+#ifdef __STDC__
+#define __P(args) args
+#else
+#define __P(args) ()
+#endif
+#endif
+
+int main __P((void));
+int prefix_length __P((char *s1, char *s2));
+
+int main() {
        register int count, j;
 
        while ( gets ( path ) != NULL ) {
@@ -37,9 +50,7 @@ main ( )
        }
 }
 
-prefix_length ( s1, s2 )       /* return length of longest common prefix */
-       char *s1, *s2;          /* ... of strings s1 and s2 */
-{
+int prefix_length(s1, s2)      /* return length of longest common prefix */ char *s1; char *s2;                /* ... of strings s1 and s2 */ {
        register char *start;
 
        for ( start = s1; *s1 == *s2; s1++, s2++ )      
index 317cfda..ff0ffa6 100644 (file)
@@ -1,6 +1,9 @@
-#ifndef lint
+#include <stdio.h>
+#include <strings.h>
+
+#if defined(DOSCCS) && !defined(lint)
 static char sccsid[] = "@(#)code.c     4.2     (Berkeley)      7/21/83";
-#endif not lint
+#endif
 
 /*
  * PURPOSE:    sorted list compressor (works with a modified 'find'
@@ -27,7 +30,7 @@ static char sccsid[] = "@(#)code.c    4.2     (Berkeley)      7/21/83";
  *             NASA Ames Research Center, 10/82
  */
 
-#include <stdio.h>
+/*#include <stdio.h>*/
 
 #define MAXPATH 1024           /* maximum pathname length */
 #define        RESET   30              /* switch code */
@@ -36,9 +39,19 @@ char path[MAXPATH];
 char oldpath[MAXPATH] = " ";   
 char bigrams[257] = { 0 };
 
-main ( argc, argv )
-       int argc; char *argv[];
-{
+#ifndef __P
+#ifdef __STDC__
+#define __P(args) args
+#else
+#define __P(args) ()
+#endif
+#endif
+
+int main __P((int argc, char *argv[]));
+int strindex __P((char *string, char *pattern));
+int prefix_length __P((char *s1, char *s2));
+
+int main(argc, argv) int argc; char *argv[]; {
        int count, oldcount, diffcount;
        int j, code;
        char bigram[3];
@@ -92,9 +105,7 @@ main ( argc, argv )
        }
 }
 
-strindex ( string, pattern )   /* return location of pattern in string or -1 */
-       char *string, *pattern;
-{
+int strindex(string, pattern)  /* return location of pattern in string or -1 */ char *string; char *pattern; {
        register char *s, *p, *q;
 
        for ( s = string; *s != NULL; s++ ) 
@@ -108,9 +119,7 @@ strindex ( string, pattern )        /* return location of pattern in string or -1 */
        return ( -1 );
 }
 
-prefix_length ( s1, s2 )       /* return length of longest common prefix */
-       char *s1, *s2;          /* ... of strings s1 and s2 */
-{
+int prefix_length(s1, s2)      /* return length of longest common prefix */ char *s1; char *s2;                /* ... of strings s1 and s2 */ {
        register char *start;
 
        for ( start = s1; *s1 == *s2; s1++, s2++ )      
index aced151..3204e70 100644 (file)
@@ -1,11 +1,30 @@
-#ifndef        lint
+#include <gen.h>
+/*#include <grp.h> gen.h*/
+/*#include <pwd.h> gen.h*/
+#include <stdio.h>
+/*#include <strings.h> gen.h*/
+/*#include <sys/dir.h> gen.h*/
+/*#include <sys/errno.h> gen.h*/
+/*#include <sys/exec.h> gen.h*/
+#include <sys/file.h>
+/*#include <sys/param.h> gen.h*/
+/*#include <sys/proc.h> gen.h*/
+/*#include <sys/signal.h> gen.h*/
+#include <sys/stat.h>
+/*#include <sys/time.h> gen.h*/
+/*#include <sys/types.h> gen.h*/
+#include <sys/wait.h>
+/*#include <time.h> gen.h*/
+/*#include <utmp.h> gen.h*/
+
+#if defined(DOSCCS) && !defined(lint)
 static char *sccsid = "@(#)find.c      4.17 (Berkeley) 1/31/86";
 #endif
 
-#include <stdio.h>
-#include <sys/param.h>
-#include <sys/dir.h>
-#include <sys/stat.h>
+/*#include <stdio.h>*/
+/*#include <sys/param.h>*/
+/*#include <sys/dir.h>*/
+/*#include <sys/stat.h>*/
 
 #define A_DAY  86400L /* a day full of seconds */
 #define EQ(x, y)       (strcmp(x, y)==0)
@@ -44,11 +63,11 @@ struct      anode   *exp(),
                *e2(),
                *e3(),
                *mk();
-char   *nxtarg();
+/*char *nxtarg();*/
 char   Home[MAXPATHLEN + 1];
 long   Blocks;
-char *rindex();
-char *sbrk();
+/*char *rindex();*/
+/*char *sbrk();*/
 
 /*
  * SEE ALSO:   updatedb, bigram.c, code.c
@@ -71,10 +90,62 @@ char *sbrk();
  */
 #define        AMES    1
 
-main(argc, argv)
-       int argc;
-       char *argv[];
-{
+#ifndef __P
+#ifdef __STDC__
+#define __P(args) args
+#else
+#define __P(args) ()
+#endif
+#endif
+
+int main __P((int argc, char *argv[]));
+struct anode *exp __P((void));
+struct anode *e1 __P((void));
+struct anode *e2 __P((void));
+struct anode *e3 __P((void));
+struct anode *mk __P((int (*f)(void), struct anode *l, struct anode *r));
+char *nxtarg __P((void));
+int and __P((register struct anode *p));
+int or __P((register struct anode *p));
+int not __P((register struct anode *p));
+int glob __P((register struct anode *p));
+int print __P((struct anode *p));
+int mtime __P((register struct anode *p));
+int atime __P((register struct anode *p));
+int user __P((register struct anode *p));
+int nouser __P((struct anode *p));
+int ino __P((register struct anode *p));
+int group __P((register struct anode *p));
+int nogroup __P((struct anode *p));
+int links __P((register struct anode *p));
+int size __P((register struct anode *p));
+int perm __P((register struct anode *p));
+int type __P((register struct anode *p));
+int exeq __P((register struct anode *p));
+int ok __P((struct anode *p));
+long mklong __P((short v[]));
+int cpio __P((void));
+int newer __P((struct anode *p));
+int ls __P((struct anode *p));
+int dummy __P((struct anode *p));
+int scomp __P((register a, register b, int s));
+int doex __P((int com));
+int getunum __P((char *f, char *s));
+int descend __P((char *name, char *fname, struct anode *exlist));
+int gmatch __P((register char *s, register char *p));
+int amatch __P((register char *s, register char *p));
+int umatch __P((register char *s, register char *p));
+int bwrite __P((register short *rp, register c));
+int chgreel __P((int x, int fl));
+int fastfind __P((char pathpart[]));
+char *patprep __P((char *name));
+char *getname __P((int uid));
+char *getgroup __P((int gid));
+int _getuid __P((char *username));
+int _getgid __P((char *groupname));
+int list __P((char *file, register struct stat *stp));
+
+int main(argc, argv) int argc; char *argv[]; {
        struct anode *exlist;
        int paths;
        register char *cp, *sp = 0;
@@ -238,7 +309,7 @@ struct anode *e3() { /* parse parens and predicates */
        else if(EQ(a, "-atime"))
                return(mk(atime, (struct anode *)atoi(b), (struct anode *)s));
        else if(EQ(a, "-user")) {
-               if((i=getuid(b)) == -1) {
+               if((i=_getuid(b)) == -1) {
                        if(gmatch(b, "[0-9]*"))
                                return mk(user, (struct anode *)atoi(b), (struct anode *)s);
                        fprintf(stderr, "find: cannot find -user name\n");
@@ -249,7 +320,7 @@ struct anode *e3() { /* parse parens and predicates */
        else if(EQ(a, "-inum"))
                return(mk(ino, (struct anode *)atoi(b), (struct anode *)s));
        else if(EQ(a, "-group")) {
-               if((i=getgid(b)) == -1) {
+               if((i=_getgid(b)) == -1) {
                        if(gmatch(b, "[0-9]*"))
                                return mk(group, (struct anode *)atoi(b), (struct anode *)s);
                        fprintf(stderr, "find: cannot find -group name\n");
@@ -308,10 +379,7 @@ struct anode *e3() { /* parse parens and predicates */
 err:   fprintf(stderr, "find: bad option < %s >\n", a);
        exit(1);
 }
-struct anode *mk(f, l, r)
-int (*f)();
-struct anode *l, *r;
-{
+struct anode *mk(f, l, r) int (*f)(); struct anode *l; struct anode *r; {
        if (Nn >= MAXNODES) {
                fprintf(stderr, "find: Too many options\n");
                exit(1);
@@ -339,119 +407,83 @@ char *nxtarg() { /* get next arg from command line */
 }
 
 /* execution time functions */
-and(p)
-register struct anode *p;
-{
+int and(p) register struct anode *p; {
        return(((*p->L->F)(p->L)) && ((*p->R->F)(p->R))?1:0);
 }
-or(p)
-register struct anode *p;
-{
+int or(p) register struct anode *p; {
         return(((*p->L->F)(p->L)) || ((*p->R->F)(p->R))?1:0);
 }
-not(p)
-register struct anode *p;
-{
+int not(p) register struct anode *p; {
        return( !((*p->L->F)(p->L)));
 }
-glob(p)
-register struct anode *p;
-{
+int glob(p) register struct anode *p; {
        return(gmatch(Fname, (char *)p->L));
 }
-print(p)
-struct anode *p;
-{
+int print(p) struct anode *p; {
        puts(Pathname);
        return(1);
 }
-mtime(p)
-register struct anode *p;
-{
+int mtime(p) register struct anode *p; {
        /* p->L is formerly int t */
        /* p->R is formerly int s */
        return(scomp((int)((Now - Statb.st_mtime) / A_DAY), (int)p->L, (int)p->R));
 }
-atime(p)
-register struct anode *p; 
-{
+int atime(p) register struct anode *p; {
        /* p->L is formerly int t */
        /* p->R is formerly int s */
        return(scomp((int)((Now - Statb.st_atime) / A_DAY), (int)p->L, (int)p->R));
 }
-user(p)
-register struct anode *p; 
-{
+int user(p) register struct anode *p; {
        /* p->L is formerly int u */
        /* p->R is formerly int s */
        return(scomp(Statb.st_uid, (int)p->L, (int)p->R));
 }
-nouser(p)
-struct anode *p;
-{
+int nouser(p) struct anode *p; {
        char *getname();
 
        return (getname(Statb.st_uid) == NULL);
 }
-ino(p)
-register struct anode *p;
-{
+int ino(p) register struct anode *p; {
        /* p->L is formerly int u */
        /* p->R is formerly int s */
        return(scomp((int)Statb.st_ino, (int)p->L, (int)p->R));
 }
-group(p)
-register struct anode *p; 
-{
+int group(p) register struct anode *p; {
        /* p->L is formerly int u */
        return((int)p->L == Statb.st_gid);
 }
-nogroup(p)
-struct anode *p;
-{
+int nogroup(p) struct anode *p; {
        char *getgroup();
 
        return (getgroup(Statb.st_gid) == NULL);
 }
-links(p)
-register struct anode *p; 
-{
+int links(p) register struct anode *p; {
        /* p->L is formerly int link */
        /* p->R is formerly int s */
        return(scomp(Statb.st_nlink, (int)p->L, (int)p->R));
 }
-size(p)
-register struct anode *p; 
-{
+int size(p) register struct anode *p; {
        /* p->L is formerly int sz */
        /* p->R is formerly int s */
        return(scomp((int)((Statb.st_size+511)>>9), (int)p->L, (int)p->R));
 }
-perm(p)
-register struct anode *p; 
-{
+int perm(p) register struct anode *p; {
        /* p->L is formerly int per */
        /* p->R is formerly int s */
        register i;
        i = ((int)p->R=='-') ? (int)p->L : 07777; /* '-' means only arg bits */
        return((Statb.st_mode & i & 07777) == (int)p->L);
 }
-type(p)
-register struct anode *p;
-{
+int type(p) register struct anode *p; {
        /* p->L is formerly int per */
        return((Statb.st_mode&S_IFMT)==(int)p->L);
 }
-exeq(p)
-register struct anode *p;
-{
+int exeq(p) register struct anode *p; {
        /* p->L is formerly int com */
        fflush(stdout); /* to flush possible `-print' */
        return(doex((int)p->L));
 }
-ok(p)
-struct anode *p;
-{
+int ok(p) struct anode *p; {
        /* p->L is formerly int com */
        char c;  int yes;
        yes = 0;
@@ -466,9 +498,7 @@ struct anode *p;
 
 #define MKSHORT(v, lv) {U.l=1L;if(U.c[0]) U.l=lv, v[0]=U.s[1], v[1]=U.s[0]; else U.l=lv, v[0]=U.s[0], v[1]=U.s[1];}
 union { long l; short s[2]; char c[4]; } U;
-long mklong(v)
-short v[];
-{
+long mklong(v) short v[]; {
        U.l = 1;
        if(U.c[0] /* VAX */)
                U.s[0] = v[1], U.s[1] = v[0];
@@ -476,8 +506,7 @@ short v[];
                U.s[0] = v[0], U.s[1] = v[1];
        return U.l;
 }
-cpio()
-{
+int cpio() {
 #define MAGIC 070707
        struct header {
                short   h_magic,
@@ -533,29 +562,20 @@ cerror:
        close(ifile);
        return;
 }
-newer(p)
-struct anode *p;
-{
+int newer(p) struct anode *p; {
        return Statb.st_mtime > Newer;
 }
-ls(p)
-struct anode *p;
-{
+int ls(p) struct anode *p; {
        list(Pathname, &Statb);
        return (1);
 }
-dummy(p)
-struct anode *p;
-{
+int dummy(p) struct anode *p; {
        /* dummy */
        return (1);
 }
 
 /* support functions */
-scomp(a, b, s) /* funny signed compare */
-register a, b;
-register char s;
-{
+int scomp(a, b, s) /* funny signed compare */ register a; register b; int s; {
        if(s == '+')
                return(a > b);
        if(s == '-')
@@ -563,8 +583,7 @@ register char s;
        return(a == b);
 }
 
-doex(com)
-{
+int doex(com) int com; {
        register np;
        register char *na;
        static char *nargv[50];
@@ -609,7 +628,7 @@ doex(com)
        }
 }
 
-getunum(f, s) char *f, *s; { /* find user/group name and return number */
+int getunum(f, s) char *f; char *s; { /* find user/group name and return number */
        register i;
        register char *sp;
        register c;
@@ -641,10 +660,7 @@ getunum(f, s) char *f, *s; { /* find user/group name and return number */
        return(i);
 }
 
-descend(name, fname, exlist)
-       struct anode *exlist;
-       char *name, *fname;
-{
+int descend(name, fname, exlist) char *name; char *fname; struct anode *exlist; {
        DIR     *dir = NULL;
        register struct direct  *dp;
        register char *c1;
@@ -701,16 +717,12 @@ ret:
        return(rv);
 }
 
-gmatch(s, p) /* string match as in glob */
-register char *s, *p;
-{
+int gmatch(s, p) /* string match as in glob */ register char *s; register char *p; {
        if (*s=='.' && *p!='.') return(0);
        return amatch(s, p);
 }
 
-amatch(s, p)
-register char *s, *p;
-{
+int amatch(s, p) register char *s; register char *p; {
        register cc;
        int scc, k;
        int c, lc;
@@ -751,19 +763,14 @@ register char *s, *p;
        return(0);
 }
 
-umatch(s, p)
-register char *s, *p;
-{
+int umatch(s, p) register char *s; register char *p; {
        if(*p==0) return(1);
        while(*s)
                if (amatch(s++, p)) return(1);
        return(0);
 }
 
-bwrite(rp, c)
-register short *rp;
-register c;
-{
+int bwrite(rp, c) register short *rp; register c; {
        register short *wp = Wp;
 
        c = (c+1) >> 1;
@@ -783,8 +790,7 @@ again:
        }
        Wp = wp;
 }
-chgreel(x, fl)
-{
+int chgreel(x, fl) int x; int fl; {
        register f;
        char str[22];
        FILE *devtty;
@@ -844,9 +850,7 @@ again:
 #define        OFFSET  14
 #define        ESCCODE 30
 
-fastfind ( pathpart )  
-       char pathpart[];
-{
+int fastfind(pathpart) char pathpart[]; {
        register char *p, *s;
        register int c; 
        char *q, *index(), *patprep();
@@ -904,10 +908,7 @@ fastfind ( pathpart )
 */
 static char globfree[100];
 
-char *
-patprep ( name )
-       char *name;
-{
+char *patprep(name) char *name; {
        register char *p, *endmark;
        register char *subp = globfree;
 
@@ -949,9 +950,9 @@ patprep ( name )
 
 /* rest should be done with nameserver or database */
 
-#include <pwd.h>
-#include <grp.h>
-#include <utmp.h>
+/*#include <pwd.h>*/
+/*#include <grp.h>*/
+/*#include <utmp.h>*/
 
 struct utmp utmp;
 #define        NMAX    (sizeof (utmp.ut_name))
@@ -975,9 +976,7 @@ int outrangegid = -1;
  * (or some such) to allow fast access based on a name key.
  * If this isn't true, duplicate the code for getgroup().
  */
-char *
-getname(uid)
-{
+char *getname(uid) int uid; {
        register struct passwd *pw;
        struct passwd *getpwent();
        register int cp;
@@ -1000,9 +999,7 @@ getname(uid)
        return (nc[cp].name);
 }
 
-char *
-getgroup(gid)
-{
+char *getgroup(gid) int gid; {
        register struct group *gr;
        static init;
        struct group *getgrent();
@@ -1048,10 +1045,7 @@ rescan:
        goto rescan;
 }
 
-int
-getuid(username)
-       char *username;
-{
+int _getuid(username) char *username; {
        register struct passwd *pw;
        struct passwd *getpwnam();
 #ifndef        NO_PW_STAYOPEN
@@ -1067,10 +1061,7 @@ getuid(username)
                return (-1);
 }
 
-int
-getgid(groupname)
-       char *groupname;
-{
+int _getgid(groupname) char *groupname; {
        register struct group *gr;
        struct group *getgrnam();
 
@@ -1085,10 +1076,7 @@ getgid(groupname)
 #define permission(who, type)  ((type) >> permoffset(who))
 #define kbytes(bytes)          (((bytes) + 1023) / 1024)
 
-list(file, stp)
-       char *file;
-       register struct stat *stp;
-{
+int list(file, stp) char *file; register struct stat *stp; {
        char pmode[32], uname[32], gname[32], fsize[32], ftime[32];
        char *getname(), *getgroup(), *ctime();
        static long special[] = { S_ISUID, 's', S_ISGID, 's', S_ISVTX, 't' };