static char *sccsid
= "@(#)diffdir.c 4.9 (Berkeley) %G%";
* diff - directory comparison
#define ONLY 1 /* Only in this directory */
#define SAME 2 /* Both places and same */
#define DIFFER 4 /* Both places and different */
#define DIRECT 8 /* Directory */
char title
[2*BUFSIZ
], *etitle
;
register struct dir
*d1
, *d2
;
fprintf(stderr
, "diff: can't specify -I with directories\n");
if (opt
== D_EDIT
&& (sflag
|| lflag
))
"diff: warning: shouldn't give -s or -l with -e\n");
for (i
= 1; diffargv
[i
+2]; i
++) {
if (!strcmp(diffargv
[i
], "-"))
continue; /* was -S, dont look silly */
strcat(title
, diffargv
[i
]);
for (etitle
= title
; *etitle
; etitle
++)
setfile(&file1
, &efile1
, file1
);
setfile(&file2
, &efile2
, file2
);
while (d1
->d_entry
!= 0 || d2
->d_entry
!= 0) {
if (d1
->d_entry
&& useless(d1
->d_entry
)) {
if (d2
->d_entry
&& useless(d2
->d_entry
)) {
else if (d2
->d_entry
== 0)
cmp
= strcmp(d1
->d_entry
, d2
->d_entry
);
else if (opt
== 0 || opt
== 2)
else if (opt
== 0 || opt
== 2)
scanpr(dir1
, ONLY
, "Only in %.*s", file1
, efile1
, 0, 0);
scanpr(dir2
, ONLY
, "Only in %.*s", file2
, efile2
, 0, 0);
scanpr(dir1
, SAME
, "Common identical files in %.*s and %.*s",
file1
, efile1
, file2
, efile2
);
scanpr(dir1
, DIFFER
, "Binary files which differ in %.*s and %.*s",
file1
, efile1
, file2
, efile2
);
scanpr(dir1
, DIRECT
, "Common subdirectories of %.*s and %.*s",
file1
, efile1
, file2
, efile2
);
for (d1
= dir1
; d1
->d_entry
; d1
++) {
if ((d1
->d_flags
& DIRECT
) == 0)
strcpy(efile1
, d1
->d_entry
);
strcpy(efile2
, d1
->d_entry
);
fprintf(stderr
, "diff: ran out of memory\n");
for (cp
= *fpp
; *cp
; cp
++)
scanpr(dp
, test
, title
, file1
, efile1
, file2
, efile2
)
char *title
, *file1
, *efile1
, *file2
, *efile2
;
for (; dp
->d_entry
; dp
++) {
if ((dp
->d_flags
& test
) == 0)
efile1
- file1
- 1, file1
,
efile2
- file2
- 1, file2
);
printf("\t%s\n", dp
->d_entry
);
char *file
= which
== 1 ? file1
: file2
;
char *efile
= which
== 1 ? efile1
: efile2
;
printf("Only in %.*s: %s\n", efile
- file
- 1, file
, dp
->d_entry
);
register struct dir
*dp
= 0, *ep
;
register struct direct
*rp
;
fprintf(stderr
, "diff: ");
dp
= (struct dir
*)malloc(sizeof (struct dir
));
fprintf(stderr
, "diff: ran out of memory\n");
while (rp
= readdir(dirp
)) {
ep
->d_reclen
= rp
->d_reclen
;
ep
->d_namlen
= rp
->d_namlen
;
ep
->d_entry
= malloc(ep
->d_namlen
+ 1);
fprintf(stderr
, "diff: out of memory\n");
strcpy(ep
->d_entry
, rp
->d_name
);
dp
= (struct dir
*)realloc((char *)dp
,
(nitems
+ 1) * sizeof (struct dir
));
fprintf(stderr
, "diff: ran out of memory\n");
dp
[nitems
].d_entry
= 0; /* delimiter */
qsort(dp
, nitems
, sizeof (struct dir
), entcmp
);
return (strcmp(d1
->d_entry
, d2
->d_entry
));
char buf1
[BUFSIZ
], buf2
[BUFSIZ
];
strcpy(efile1
, dp
->d_entry
);
strcpy(efile2
, dp
->d_entry
);
fstat(f1
, &stb1
); fstat(f2
, &stb2
);
fmt1
= stb1
.st_mode
& S_IFMT
;
fmt2
= stb2
.st_mode
& S_IFMT
;
if (fmt1
!= S_IFREG
|| fmt2
!= S_IFREG
) {
if (fmt1
!= S_IFDIR
&& stb1
.st_rdev
== stb2
.st_rdev
)
if (lflag
|| opt
== D_EDIT
)
printf("Common subdirectories: %s and %s\n",
if (stb1
.st_size
!= stb2
.st_size
)
i
= read(f1
, buf1
, BUFSIZ
);
j
= read(f2
, buf2
, BUFSIZ
);
if (i
< 0 || j
< 0 || i
!= j
)
printf("Files %s and %s are identical\n", file1
, file2
);
if (!ascii(f1
) || !ascii(f2
)) {
else if (opt
== D_NORMAL
|| opt
== D_CONTEXT
)
printf("Binary files %s and %s differ\n",
printf("ed - %s << '-*-END-*-'\n", dp
->d_entry
);
printf("%s%s %s\n", title
, file1
, file2
);
printf("w\nq\n-*-END-*-\n");
char *prargs
[] = { "pr", "-h", 0, "-f", 0, 0 };
int pid
, status
, status2
, pv
[2];
sprintf(etitle
, "%s %s", file1
, file2
);
fprintf(stderr
, "No more processes");
fprintf(stderr
, "diff: No more processes\n");
while (wait(&status
) != pid
)
while (wait(&status2
) != -1)
cnt
= read(f
, buf
, BUFSIZ
);
if (cnt
>= sizeof (struct exec
)) {
hdr
= *(struct exec
*)buf
;
return (1); /* directory "." */
if (cp
[1] == '.' && cp
[2] == '\0')
return (1); /* directory ".." */
if (start
&& strcmp(start
, cp
) > 0)