/*#include <time.h> gen.h*/
/*#include <utmp.h> gen.h*/
+#ifdef __STDC__
+#include <stdint.h>
+#else
+typedef int intptr_t;
+#endif
+
#if defined(DOSCCS) && !defined(lint)
static char *sccsid = "@(#)find.c 4.17 (Berkeley) 1/31/86";
#endif
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;
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;
*/
#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));
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));
if(Cpio) {
strcpy(Pathname, "TRAILER!!!");
Statb.st_size = 0;
- cpio();
+ cpio((struct anode *)0);
printf("%D blocks\n", Blocks*10);
}
exit(0);
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);
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;
}
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());
}
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 :
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) {
}
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) {
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);
/* 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);
}
/* 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);
/* 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);
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;
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,
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) {
bwrite(Buf, ct);
}
close(ifile);
- return;
+ return(0);
}
int newer(p) struct anode *p; {
return Statb.st_mtime > Newer;
case -1:
perror("find: Can't fork");
exit(1);
- break;
case 0:
chdir(Home);
* note indicating we couldn't do the "exec".
*/
kill(getpid(), SIGUSR1);
- break;
+ return (0);
default:
omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT));
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;
#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();