From ea07807b3f77b391067482505dc418cd3743342d Mon Sep 17 00:00:00 2001 From: Nick Downing Date: Tue, 31 Jan 2017 18:53:53 +1100 Subject: [PATCH] Post-ansification changes for usr.bin/find --- n.sh | 2 +- usr.bin/find/bigram.c | 4 +- usr.bin/find/code.c | 4 +- usr.bin/find/find.c | 131 +++++++++++++++++++++--------------------- 4 files changed, 71 insertions(+), 70 deletions(-) diff --git a/n.sh b/n.sh index f79e455..864ca88 100755 --- a/n.sh +++ b/n.sh @@ -28,6 +28,6 @@ mkdir -p lib/libc/stdio/profiled mkdir -p lib/libc/sys/profiled (cd lib/libc && make.sh clean && make.sh && make.sh install) (cd bin && make.sh clean && make.sh SUBDIR="as csh diff sed sh tp" NSTD= KMEM= && make.sh SUBDIR="as csh diff sed sh tp" NSTD= KMEM= install) -(cd usr.bin && make.sh clean && make.sh SUBDIR= NSTD= KMEM= && make.sh SUBDIR= NSTD= KMEM= install) +(cd usr.bin && make.sh clean && make.sh SUBDIR=find NSTD= KMEM= && make.sh SUBDIR=find NSTD= KMEM= install) #(cd test && make clean && make) diff --git a/usr.bin/find/bigram.c b/usr.bin/find/bigram.c index 7891bbc..7927ecb 100644 --- a/usr.bin/find/bigram.c +++ b/usr.bin/find/bigram.c @@ -27,10 +27,10 @@ char oldpath[MAXPATH] = " "; #endif #endif -int main __P((void)); +void main __P((void)); int prefix_length __P((char *s1, char *s2)); -int main() { +void main() { register int count, j; while ( gets ( path ) != NULL ) { diff --git a/usr.bin/find/code.c b/usr.bin/find/code.c index ff0ffa6..e1eb690 100644 --- a/usr.bin/find/code.c +++ b/usr.bin/find/code.c @@ -47,11 +47,11 @@ char bigrams[257] = { 0 }; #endif #endif -int main __P((int argc, char *argv[])); +void 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[]; { +void main(argc, argv) int argc; char *argv[]; { int count, oldcount, diffcount; int j, code; char bigram[3]; diff --git a/usr.bin/find/find.c b/usr.bin/find/find.c index 3204e70..2fd3a55 100644 --- a/usr.bin/find/find.c +++ b/usr.bin/find/find.c @@ -17,6 +17,12 @@ /*#include gen.h*/ /*#include gen.h*/ +#ifdef __STDC__ +#include +#else +typedef int intptr_t; +#endif + #if defined(DOSCCS) && !defined(lint) static char *sccsid = "@(#)find.c 4.17 (Berkeley) 1/31/86"; #endif @@ -32,11 +38,19 @@ static char *sccsid = "@(#)find.c 4.17 (Berkeley) 1/31/86"; int Randlast; char Pathname[MAXPATHLEN+1]; +#ifndef __P +#ifdef __STDC__ +#define __P(args) args +#else +#define __P(args) () +#endif +#endif + #define MAXNODES 100 struct anode { - int (*F)(); - struct anode *L, *R; + int (*F) __P((struct anode *p)); + intptr_t L, R; } Node[MAXNODES]; int Nn; /* number of nodes */ char *Fname; @@ -58,11 +72,7 @@ struct stat Devstat; /* stats of each argument path's file system */ struct stat Statb; -struct anode *exp(), - *e1(), - *e2(), - *e3(), - *mk(); +/*struct anode *exp(), *e1(), *e2(), *e3(), *mk();*/ /*char *nxtarg();*/ char Home[MAXPATHLEN + 1]; long Blocks; @@ -90,41 +100,33 @@ long Blocks; */ #define AMES 1 -#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)); +struct anode *mk __P((int (*f)(struct anode *p), intptr_t l, intptr_t 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 print __P((register 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 nouser __P((register struct anode *p)); int ino __P((register struct anode *p)); int group __P((register struct anode *p)); -int nogroup __P((struct anode *p)); +int nogroup __P((register 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)); +int ok __P((register struct anode *p)); long mklong __P((short v[])); -int cpio __P((void)); +int cpio __P((register struct anode *p)); int newer __P((struct anode *p)); int ls __P((struct anode *p)); int dummy __P((struct anode *p)); @@ -135,9 +137,9 @@ 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)); +void bwrite __P((register short *rp, register c)); int chgreel __P((int x, int fl)); -int fastfind __P((char pathpart[])); +void fastfind __P((char pathpart[])); char *patprep __P((char *name)); char *getname __P((int uid)); char *getgroup __P((int gid)); @@ -215,7 +217,7 @@ usage: fprintf(stderr, "Usage: find path-list predicate-list\n"); if(Cpio) { strcpy(Pathname, "TRAILER!!!"); Statb.st_size = 0; - cpio(); + cpio((struct anode *)0); printf("%D blocks\n", Blocks*10); } exit(0); @@ -230,7 +232,7 @@ struct anode *exp() { /* parse ALTERNATION (-o) */ p1 = e1() /* get left operand */ ; if(EQ(nxtarg(), "-o")) { Randlast--; - return(mk(or, p1, exp())); + return(mk(or, (intptr_t)p1, (intptr_t)exp())); } else if(Ai <= Argc) --Ai; return(p1); @@ -245,7 +247,7 @@ struct anode *e1() { /* parse CONCATENATION (formerly -a) */ if(EQ(a, "-a")) { And: Randlast--; - return(mk(and, p1, e1())); + return(mk(and, (intptr_t)p1, (intptr_t)e1())); } else if(EQ(a, "(") || EQ(a, "!") || (*a=='-' && !EQ(a, "-o"))) { --Ai; goto And; @@ -261,7 +263,7 @@ struct anode *e2() { /* parse NOT (!) */ } Randlast++; if(EQ(nxtarg(), "!")) - return(mk(not, e3(), (struct anode *)0)); + return(mk(not, (intptr_t)e3(), (intptr_t)0)); else if(Ai <= Argc) --Ai; return(e3()); } @@ -284,60 +286,60 @@ struct anode *e3() { /* parse parens and predicates */ return(p1); } else if(EQ(a, "-print")) { - return(mk(print, (struct anode *)0, (struct anode *)0)); + return(mk(print, (intptr_t)0, (intptr_t)0)); } else if (EQ(a, "-nouser")) { - return (mk(nouser, (struct anode *)0, (struct anode *)0)); + return (mk(nouser, (intptr_t)0, (intptr_t)0)); } else if (EQ(a, "-nogroup")) { - return (mk(nogroup, (struct anode *)0, (struct anode *)0)); + return (mk(nogroup, (intptr_t)0, (intptr_t)0)); } else if (EQ(a, "-ls")) { - return (mk(ls, (struct anode *)0, (struct anode *)0)); + return (mk(ls, (intptr_t)0, (intptr_t)0)); } else if (EQ(a, "-xdev")) { Xdev = 0; - return (mk(dummy, (struct anode *)0, (struct anode *)0)); + return (mk(dummy, (intptr_t)0, (intptr_t)0)); } b = nxtarg(); s = *b; if(s=='+') b++; if(EQ(a, "-name")) - return(mk(glob, (struct anode *)b, (struct anode *)0)); + return(mk(glob, (intptr_t)b, (intptr_t)0)); else if(EQ(a, "-mtime")) - return(mk(mtime, (struct anode *)atoi(b), (struct anode *)s)); + return(mk(mtime, (intptr_t)atoi(b), (intptr_t)s)); else if(EQ(a, "-atime")) - return(mk(atime, (struct anode *)atoi(b), (struct anode *)s)); + return(mk(atime, (intptr_t)atoi(b), (intptr_t)s)); else if(EQ(a, "-user")) { if((i=_getuid(b)) == -1) { if(gmatch(b, "[0-9]*")) - return mk(user, (struct anode *)atoi(b), (struct anode *)s); + return mk(user, (intptr_t)atoi(b), (intptr_t)s); fprintf(stderr, "find: cannot find -user name\n"); exit(1); } - return(mk(user, (struct anode *)i, (struct anode *)s)); + return(mk(user, (intptr_t)i, (intptr_t)s)); } else if(EQ(a, "-inum")) - return(mk(ino, (struct anode *)atoi(b), (struct anode *)s)); + return(mk(ino, (intptr_t)atoi(b), (intptr_t)s)); else if(EQ(a, "-group")) { if((i=_getgid(b)) == -1) { if(gmatch(b, "[0-9]*")) - return mk(group, (struct anode *)atoi(b), (struct anode *)s); + return mk(group, (intptr_t)atoi(b), (intptr_t)s); fprintf(stderr, "find: cannot find -group name\n"); exit(1); } - return(mk(group, (struct anode *)i, (struct anode *)s)); + return(mk(group, (intptr_t)i, (intptr_t)s)); } else if(EQ(a, "-size")) - return(mk(size, (struct anode *)atoi(b), (struct anode *)s)); + return(mk(size, (intptr_t)atoi(b), (intptr_t)s)); else if(EQ(a, "-links")) - return(mk(links, (struct anode *)atoi(b), (struct anode *)s)); + return(mk(links, (intptr_t)atoi(b), (intptr_t)s)); else if(EQ(a, "-perm")) { for(i=0; *b ; ++b) { if(*b=='-') continue; i <<= 3; i = i + (*b - '0'); } - return(mk(perm, (struct anode *)i, (struct anode *)s)); + return(mk(perm, (intptr_t)i, (intptr_t)s)); } else if(EQ(a, "-type")) { i = s=='d' ? S_IFDIR : @@ -347,17 +349,17 @@ struct anode *e3() { /* parse parens and predicates */ s=='l' ? S_IFLNK : s=='s' ? S_IFSOCK : 0; - return(mk(type, (struct anode *)i, (struct anode *)0)); + return(mk(type, (intptr_t)i, (intptr_t)0)); } else if (EQ(a, "-exec")) { i = Ai - 1; while(!EQ(nxtarg(), ";")); - return(mk(exeq, (struct anode *)i, (struct anode *)0)); + return(mk(exeq, (intptr_t)i, (intptr_t)0)); } else if (EQ(a, "-ok")) { i = Ai - 1; while(!EQ(nxtarg(), ";")); - return(mk(ok, (struct anode *)i, (struct anode *)0)); + return(mk(ok, (intptr_t)i, (intptr_t)0)); } else if(EQ(a, "-cpio")) { if((Cpio = creat(b, 0666)) < 0) { @@ -366,7 +368,7 @@ struct anode *e3() { /* parse parens and predicates */ } Buf = (short *)sbrk(512); Wp = Dbuf = (short *)sbrk(5120); - return(mk(cpio, (struct anode *)0, (struct anode *)0)); + return(mk(cpio, (intptr_t)0, (intptr_t)0)); } else if(EQ(a, "-newer")) { if(stat(b, &Statb) < 0) { @@ -374,12 +376,12 @@ struct anode *e3() { /* parse parens and predicates */ exit(1); } Newer = Statb.st_mtime; - return mk(newer, (struct anode *)0, (struct anode *)0); + return mk(newer, (intptr_t)0, (intptr_t)0); } err: fprintf(stderr, "find: bad option < %s >\n", a); exit(1); } -struct anode *mk(f, l, r) int (*f)(); struct anode *l; struct anode *r; { +struct anode *mk(f, l, r) int (*f) __P((struct anode *p)); intptr_t l; intptr_t r; { if (Nn >= MAXNODES) { fprintf(stderr, "find: Too many options\n"); exit(1); @@ -408,18 +410,18 @@ char *nxtarg() { /* get next arg from command line */ /* execution time functions */ int and(p) register struct anode *p; { - return(((*p->L->F)(p->L)) && ((*p->R->F)(p->R))?1:0); + return(((*((struct anode *)p->L)->F)(((struct anode *)p->L))) && ((*((struct anode *)p->R)->F)(((struct anode *)p->R)))?1:0); } int or(p) register struct anode *p; { - return(((*p->L->F)(p->L)) || ((*p->R->F)(p->R))?1:0); + return(((*((struct anode *)p->L)->F)(((struct anode *)p->L))) || ((*((struct anode *)p->R)->F)(((struct anode *)p->R)))?1:0); } int not(p) register struct anode *p; { - return( !((*p->L->F)(p->L))); + return( !((*((struct anode *)p->L)->F)(((struct anode *)p->L)))); } int glob(p) register struct anode *p; { return(gmatch(Fname, (char *)p->L)); } -int print(p) struct anode *p; { +int print(p) register struct anode *p; { puts(Pathname); return(1); } @@ -438,7 +440,7 @@ int user(p) register struct anode *p; { /* p->R is formerly int s */ return(scomp(Statb.st_uid, (int)p->L, (int)p->R)); } -int nouser(p) struct anode *p; { +int nouser(p) register struct anode *p; { char *getname(); return (getname(Statb.st_uid) == NULL); @@ -452,7 +454,7 @@ int group(p) register struct anode *p; { /* p->L is formerly int u */ return((int)p->L == Statb.st_gid); } -int nogroup(p) struct anode *p; { +int nogroup(p) register struct anode *p; { char *getgroup(); return (getgroup(Statb.st_gid) == NULL); @@ -483,7 +485,7 @@ int exeq(p) register struct anode *p; { fflush(stdout); /* to flush possible `-print' */ return(doex((int)p->L)); } -int ok(p) struct anode *p; { +int ok(p) register struct anode *p; { /* p->L is formerly int com */ char c; int yes; yes = 0; @@ -506,7 +508,7 @@ long mklong(v) short v[]; { U.s[0] = v[0], U.s[1] = v[1]; return U.l; } -int cpio() { +int cpio(p) register struct anode *p; { #define MAGIC 070707 struct header { short h_magic, @@ -543,14 +545,14 @@ int cpio() { bwrite((short *)&hdr, (sizeof hdr-256)+hdr.h_namesize); for(i = 0; i < 10; ++i) bwrite(Buf, 512); - return; + return(0); } if(!mklong(hdr.h_filesize)) - return; + return(0); if((ifile = open(Fname, 0)) < 0) { cerror: fprintf(stderr, "find: cannot copy < %s >\n", hdr.h_name); - return; + return(0); } bwrite((short *)&hdr, (sizeof hdr-256)+hdr.h_namesize); for(fsz = mklong(hdr.h_filesize); fsz > 0; fsz -= 512) { @@ -560,7 +562,7 @@ cerror: bwrite(Buf, ct); } close(ifile); - return; + return(0); } int newer(p) struct anode *p; { return Statb.st_mtime > Newer; @@ -603,7 +605,6 @@ int doex(com) int com; { case -1: perror("find: Can't fork"); exit(1); - break; case 0: chdir(Home); @@ -615,7 +616,7 @@ int doex(com) int com; { * note indicating we couldn't do the "exec". */ kill(getpid(), SIGUSR1); - break; + return (0); default: omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT)); @@ -770,7 +771,7 @@ int umatch(s, p) register char *s; register char *p; { return(0); } -int bwrite(rp, c) register short *rp; register c; { +void bwrite(rp, c) register short *rp; register c; { register short *wp = Wp; c = (c+1) >> 1; @@ -850,7 +851,7 @@ again: #define OFFSET 14 #define ESCCODE 30 -int fastfind(pathpart) char pathpart[]; { +void fastfind(pathpart) char pathpart[]; { register char *p, *s; register int c; char *q, *index(), *patprep(); -- 2.34.1