Home[strlen(Home) - 1] = '\0';
Argc = argc; Argv = argv;
if(argc<3) {
-usage: pr("Usage: find path-list predicate-list\n");
+usage: fprintf(stderr, "Usage: find path-list predicate-list\n");
exit(1);
}
for(Ai = paths = 1; Ai < (argc-1); ++Ai, ++paths)
if(paths == 1) /* no path-list */
goto usage;
if(!(exlist = exp())) { /* parse and compile the arguments */
- pr("find: parsing error\n");
+ fprintf(stderr, "find: parsing error\n");
exit(1);
}
if(Ai<argc) {
- pr("find: missing conjunction\n");
+ fprintf(stderr, "find: missing conjunction\n");
exit(1);
}
for(Pi = 1; Pi < paths; ++Pi) {
sp = cp + 1;
*cp = '\0';
if(chdir(*Pathname? Pathname: "/") == -1) {
- pr("find: bad starting directory\n");
+ fprintf(stderr, "find: bad starting directory\n");
exit(2);
}
*cp = '/';
strcpy(Pathname, "TRAILER!!!");
Statb.st_size = 0;
cpio();
+ printf("%D blocks\n", Blocks*10);
}
exit(0);
}
int not();
if(Randlast) {
- pr("find: operand follows operand\n");
+ fprintf(stderr, "find: operand follows operand\n");
exit(1);
}
Randlast++;
return(e3());
}
struct anode *e3() { /* parse parens and predicates */
- int exeq(), ok(), glob(), mtime(), atime(), ctime(), user(),
+ int exeq(), ok(), glob(), mtime(), atime(), user(),
group(), size(), perm(), links(), print(),
type(), ino(), cpio(), newer();
struct anode *p1;
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, "-ctime"))
- return(mk(ctime, (struct anode *)atoi(b), (struct anode *)s));
else if(EQ(a, "-user")) {
if((i=getunum("/etc/passwd", b)) == -1) {
- if(gmatch(b, "[0-9][0-9][0-9]*")
- || gmatch(b, "[0-9][0-9]")
- || gmatch(b, "[0-9]"))
+ if(gmatch(b, "[0-9][0-9]*"))
return mk(user, (struct anode *)atoi(b), (struct anode *)s);
- pr("find: cannot find -user name\n");
+ fprintf(stderr, "find: cannot find -user name\n");
exit(1);
}
return(mk(user, (struct anode *)i, (struct anode *)s));
return(mk(ino, (struct anode *)atoi(b), (struct anode *)s));
else if(EQ(a, "-group")) {
if((i=getunum("/etc/group", b)) == -1) {
- if(gmatch(b, "[0-9][0-9][0-9]*")
- || gmatch(b, "[0-9][0-9]")
- || gmatch(b, "[0-9]"))
+ if(gmatch(b, "[0-9][0-9]*"))
return mk(group, (struct anode *)atoi(b), (struct anode *)s);
- pr("find: cannot find -group name\n");
+ fprintf(stderr, "find: cannot find -group name\n");
exit(1);
}
return(mk(group, (struct anode *)i, (struct anode *)s));
}
else if(EQ(a, "-cpio")) {
if((Cpio = creat(b, 0666)) < 0) {
- pr("find: cannot create "), pr(s), pr("\n");
+ fprintf(stderr, "find: cannot create < %s >\n", s);
exit(1);
}
Buf = (short *)sbrk(512);
}
else if(EQ(a, "-newer")) {
if(stat(b, &Statb) < 0) {
- pr("find: cannot access "), pr(b), pr("\n");
+ fprintf(stderr, "find: cannot access < %s >\n", b);
exit(1);
}
Newer = Statb.st_mtime;
return mk(newer, (struct anode *)0, (struct anode *)0);
}
-err: pr("find: bad option "), pr(a), pr("\n");
+err: fprintf(stderr, "find: bad option < %s >\n", a);
exit(1);
}
struct anode *mk(f, l, r)
static strikes = 0;
if(strikes==3) {
- pr("find: incomplete statement\n");
+ fprintf(stderr, "find: incomplete statement\n");
exit(1);
}
if(Ai>=Argc) {
{
return(scomp((int)((Now - Statb.st_atime) / A_DAY), p->t, p->s));
}
-ctime(p)
-register struct { int f, t, s; } *p;
-{
- return(scomp((int)((Now - Statb.st_ctime) / A_DAY), p->t, p->s));
-}
user(p)
register struct { int f, u, s; } *p;
{
ok(p)
struct { int f, com; } *p;
{
- int c; int yes;
+ char c; int yes;
yes = 0;
fflush(stdout); /* to flush possible `-print' */
- pr("< "), pr(Argv[p->com]), pr(" ... "), pr(Pathname), pr(" >? ");
+ fprintf(stderr, "< %s ... %s > ? ", Argv[p->com], Pathname);
fflush(stderr);
if((c=getchar())=='y') yes = 1;
- while(c!='\n')
- if(c==EOF)
- exit(2);
- else
- c = getchar();
+ while(c!='\n') c = getchar();
if(yes) return(doex(p->com));
return(0);
}
bwrite(Buf, 512);
return;
}
- if(!mklong(hdr.h_filesize)) {
- bwrite((short *)&hdr, (sizeof hdr-256)+hdr.h_namesize);
+ if(!mklong(hdr.h_filesize))
return;
- }
if((ifile = open(Fname, 0)) < 0) {
cerror:
- pr("find: cannot copy "), pr(hdr.h_name), pr("\n");
+ fprintf(stderr, "find: cannot copy < %s >\n", hdr.h_name);
return;
}
bwrite((short *)&hdr, (sizeof hdr-256)+hdr.h_namesize);
char *endofname;
if(stat(fname, &Statb)<0) {
- pr("find: bad status-- "), pr(name), pr("\n");
+ fprintf(stderr, "find: bad status < %s >\n", name);
return(0);
}
(*exlist->F)(exlist);
dsize = 512<(dirsize-offset)? 512: (dirsize-offset);
if(!dir) {
if((dir=open(".", 0))<0) {
- pr("find: cannot open "), pr(name), pr("\n");
+ fprintf(stderr, "find: cannot open < %s >\n",
+ name);
rv = 0;
goto ret;
}
if(offset) lseek(dir, (long)offset, 0);
if(read(dir, (char *)dentry, dsize)<0) {
- pr("find: cannot read "), pr(name), pr("\n");
+ fprintf(stderr, "find: cannot read < %s >\n",
+ name);
rv = 0;
goto ret;
}
}
} else
if(read(dir, (char *)dentry, dsize)<0) {
- pr("find: cannot read "), pr(name), pr("\n");
+ fprintf(stderr, "find: cannot read < %s >\n",
+ name);
rv = 0;
goto ret;
}
*endofname = '\0';
chdir(Home);
if(chdir(Pathname) == -1) {
- pr("find: bad directory tree\n");
+ fprintf(stderr, "find: bad directory tree\n");
exit(1);
}
}
close(dir);
if(chdir("..") == -1) {
*endofname = '\0';
- pr("find: bad directory "), pr(name), pr("\n");
+ fprintf(stderr, "find: bad directory <%s>\n", name);
rv = 1;
}
return(rv);
char str[22];
FILE *devtty;
struct stat statb;
+ extern errno;
- pr("find: can't "), pr(x? "write output": "read input"), pr("\n");
+ fprintf(stderr, "find: errno: %d, ", errno);
+ fprintf(stderr, "find: can't %s\n", x? "write output": "read input");
fstat(fl, &statb);
if((statb.st_mode&S_IFMT) != S_IFCHR)
exit(1);
again:
- pr("If you want to go on, type device/file name when ready\n");
+ fprintf(stderr, "If you want to go on, type device/file name %s\n",
+ "when ready");
devtty = fopen("/dev/tty", "r");
fgets(str, 20, devtty);
str[strlen(str) - 1] = '\0';
exit(1);
close(fl);
if((f = open(str, x? 1: 0)) < 0) {
- pr("That didn't work");
+ fprintf(stderr, "That didn't work");
fclose(devtty);
goto again;
}
return f;
}
-pr(s)
-char *s;
-{
- fputs(s, stderr);
-}