projects
/
unix-history
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
tags
|
clone url
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Bell 32V development
[unix-history]
/
usr
/
src
/
cmd
/
find.c
diff --git
a/usr/src/cmd/find.c
b/usr/src/cmd/find.c
index
d0aea47
..
1a9acb1
100644
(file)
--- a/
usr/src/cmd/find.c
+++ b/
usr/src/cmd/find.c
@@
-54,7
+54,7
@@
main(argc, argv) char *argv[];
Home[strlen(Home) - 1] = '\0';
Argc = argc; Argv = argv;
if(argc<3) {
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)
exit(1);
}
for(Ai = paths = 1; Ai < (argc-1); ++Ai, ++paths)
@@
-63,11
+63,11
@@
usage: pr("Usage: find path-list predicate-list\n");
if(paths == 1) /* no path-list */
goto usage;
if(!(exlist = exp())) { /* parse and compile the arguments */
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) {
exit(1);
}
if(Ai<argc) {
-
pr(
"find: missing conjunction\n");
+
fprintf(stderr,
"find: missing conjunction\n");
exit(1);
}
for(Pi = 1; Pi < paths; ++Pi) {
exit(1);
}
for(Pi = 1; Pi < paths; ++Pi) {
@@
-78,7
+78,7
@@
usage: pr("Usage: find path-list predicate-list\n");
sp = cp + 1;
*cp = '\0';
if(chdir(*Pathname? Pathname: "/") == -1) {
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 = '/';
exit(2);
}
*cp = '/';
@@
-90,6
+90,7
@@
usage: pr("Usage: find path-list predicate-list\n");
strcpy(Pathname, "TRAILER!!!");
Statb.st_size = 0;
cpio();
strcpy(Pathname, "TRAILER!!!");
Statb.st_size = 0;
cpio();
+ printf("%D blocks\n", Blocks*10);
}
exit(0);
}
}
exit(0);
}
@@
-129,7
+130,7
@@
struct anode *e2() { /* parse NOT (!) */
int not();
if(Randlast) {
int not();
if(Randlast) {
-
pr(
"find: operand follows operand\n");
+
fprintf(stderr,
"find: operand follows operand\n");
exit(1);
}
Randlast++;
exit(1);
}
Randlast++;
@@
-139,7
+140,7
@@
struct anode *e2() { /* parse NOT (!) */
return(e3());
}
struct anode *e3() { /* parse parens and predicates */
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;
group(), size(), perm(), links(), print(),
type(), ino(), cpio(), newer();
struct anode *p1;
@@
-166,15
+167,11
@@
struct anode *e3() { /* parse parens and predicates */
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));
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) {
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);
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));
exit(1);
}
return(mk(user, (struct anode *)i, (struct anode *)s));
@@
-183,11
+180,9
@@
struct anode *e3() { /* parse parens and predicates */
return(mk(ino, (struct anode *)atoi(b), (struct anode *)s));
else if(EQ(a, "-group")) {
if((i=getunum("/etc/group", b)) == -1) {
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);
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));
exit(1);
}
return(mk(group, (struct anode *)i, (struct anode *)s));
@@
-223,7
+218,7
@@
struct anode *e3() { /* parse parens and predicates */
}
else if(EQ(a, "-cpio")) {
if((Cpio = creat(b, 0666)) < 0) {
}
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);
exit(1);
}
Buf = (short *)sbrk(512);
@@
-232,13
+227,13
@@
struct anode *e3() { /* parse parens and predicates */
}
else if(EQ(a, "-newer")) {
if(stat(b, &Statb) < 0) {
}
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);
}
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)
exit(1);
}
struct anode *mk(f, l, r)
@@
-255,7
+250,7
@@
char *nxtarg() { /* get next arg from command line */
static strikes = 0;
if(strikes==3) {
static strikes = 0;
if(strikes==3) {
-
pr(
"find: incomplete statement\n");
+
fprintf(stderr,
"find: incomplete statement\n");
exit(1);
}
if(Ai>=Argc) {
exit(1);
}
if(Ai>=Argc) {
@@
-302,11
+297,6
@@
register struct { int f, t, s; } *p;
{
return(scomp((int)((Now - Statb.st_atime) / A_DAY), p->t, p->s));
}
{
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;
{
user(p)
register struct { int f, u, s; } *p;
{
@@
-353,17
+343,13
@@
register struct { int f, com; } *p;
ok(p)
struct { int f, com; } *p;
{
ok(p)
struct { int f, com; } *p;
{
-
int
c; int yes;
+
char
c; int yes;
yes = 0;
fflush(stdout); /* to flush possible `-print' */
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;
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);
}
if(yes) return(doex(p->com));
return(0);
}
@@
-420,13
+406,11
@@
cpio()
bwrite(Buf, 512);
return;
}
bwrite(Buf, 512);
return;
}
- if(!mklong(hdr.h_filesize)) {
- bwrite((short *)&hdr, (sizeof hdr-256)+hdr.h_namesize);
+ if(!mklong(hdr.h_filesize))
return;
return;
- }
if((ifile = open(Fname, 0)) < 0) {
cerror:
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);
return;
}
bwrite((short *)&hdr, (sizeof hdr-256)+hdr.h_namesize);
@@
-529,7
+513,7
@@
char *name, *fname;
char *endofname;
if(stat(fname, &Statb)<0) {
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);
return(0);
}
(*exlist->F)(exlist);
@@
-548,13
+532,15
@@
char *name, *fname;
dsize = 512<(dirsize-offset)? 512: (dirsize-offset);
if(!dir) {
if((dir=open(".", 0))<0) {
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) {
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;
}
rv = 0;
goto ret;
}
@@
-564,7
+550,8
@@
char *name, *fname;
}
} else
if(read(dir, (char *)dentry, dsize)<0) {
}
} 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;
}
rv = 0;
goto ret;
}
@@
-591,7
+578,7
@@
char *name, *fname;
*endofname = '\0';
chdir(Home);
if(chdir(Pathname) == -1) {
*endofname = '\0';
chdir(Home);
if(chdir(Pathname) == -1) {
-
pr(
"find: bad directory tree\n");
+
fprintf(stderr,
"find: bad directory tree\n");
exit(1);
}
}
exit(1);
}
}
@@
-603,7
+590,7
@@
ret:
close(dir);
if(chdir("..") == -1) {
*endofname = '\0';
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);
rv = 1;
}
return(rv);
@@
-696,13
+683,16
@@
chgreel(x, fl)
char str[22];
FILE *devtty;
struct stat statb;
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:
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';
devtty = fopen("/dev/tty", "r");
fgets(str, 20, devtty);
str[strlen(str) - 1] = '\0';
@@
-710,14
+700,9
@@
again:
exit(1);
close(fl);
if((f = open(str, x? 1: 0)) < 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;
}
fclose(devtty);
goto again;
}
return f;
}
-pr(s)
-char *s;
-{
- fputs(s, stderr);
-}