- a = nxtarg();
- if(EQ(a, "(")) {
- Randlast--;
- p1 = exp();
- a = nxtarg();
- if(!EQ(a, ")")) goto err;
- return(p1);
- }
- else if(EQ(a, "-print")) {
- return(mk(print, (struct anode *)0, (struct anode *)0));
- }
- else if (EQ(a, "-nouser")) {
- return (mk(nouser, (struct anode *)0, (struct anode *)0));
- }
- else if (EQ(a, "-nogroup")) {
- return (mk(nogroup, (struct anode *)0, (struct anode *)0));
- }
- else if (EQ(a, "-ls")) {
- return (mk(ls, (struct anode *)0, (struct anode *)0));
- }
- else if (EQ(a, "-xdev")) {
- 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++;
- if(EQ(a, "-name"))
- return(mk(glob, (struct anode *)b, (struct anode *)0));
- else if(EQ(a, "-mtime"))
- return(mk(mtime, (struct anode *)atoi(b), (struct anode *)s));
- 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(gmatch(b, "[0-9]*"))
- return mk(user, (struct anode *)atoi(b), (struct anode *)s);
- fprintf(stderr, "find: cannot find -user name\n");
- exit(1);
- }
- return(mk(user, (struct anode *)i, (struct anode *)s));
- }
- 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(gmatch(b, "[0-9]*"))
- return mk(group, (struct anode *)atoi(b), (struct anode *)s);
- fprintf(stderr, "find: cannot find -group name\n");
- exit(1);
- }
- return(mk(group, (struct anode *)i, (struct anode *)s));
- } else if(EQ(a, "-size"))
- return(mk(size, (struct anode *)atoi(b), (struct anode *)s));
- else if(EQ(a, "-links"))
- return(mk(links, (struct anode *)atoi(b), (struct anode *)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));
- }
- else if(EQ(a, "-type")) {
- i = s=='d' ? S_IFDIR :
- s=='b' ? S_IFBLK :
- s=='c' ? S_IFCHR :
- s=='f' ? S_IFREG :
- s=='l' ? S_IFLNK :
- s=='s' ? S_IFSOCK :
- 0;
- return(mk(type, (struct anode *)i, (struct anode *)0));
- }
- else if (EQ(a, "-exec")) {
- i = Ai - 1;
- while(!EQ(nxtarg(), ";"));
- return(mk(exeq, (struct anode *)i, (struct anode *)0));
- }
- else if (EQ(a, "-ok")) {
- i = Ai - 1;
- while(!EQ(nxtarg(), ";"));
- return(mk(ok, (struct anode *)i, (struct anode *)0));
- }
- else if(EQ(a, "-cpio")) {
- if((Cpio = creat(b, 0666)) < 0) {
- fprintf(stderr, "find: cannot create < %s >\n", s);
- exit(1);
- }
- Buf = (short *)sbrk(512);
- Wp = Dbuf = (short *)sbrk(5120);
- return(mk(cpio, (struct anode *)0, (struct anode *)0));
- }
- else if(EQ(a, "-newer")) {
- if(stat(b, &Statb) < 0) {
- fprintf(stderr, "find: cannot access < %s >\n", b);
- exit(1);
- }
- Newer = Statb.st_mtime;
- return mk(newer, (struct anode *)0, (struct anode *)0);
- }
-err: fprintf(stderr, "find: bad option < %s >\n", a);
- exit(1);
-}
-struct anode *mk(f, l, r)
-int (*f)();
-struct anode *l, *r;
-{
- if (Nn >= MAXNODES) {
- fprintf(stderr, "find: Too many options\n");
- exit(1);
- }