/* Copyright (c) 1979 Regents of the University of California */
* Diffdir - a (first) directory difference program
* Bill Joy UCB March 16, 1978
* This is a difference program which operates on the entire contents of
* a directory. It reports common files which are different, running
* diff if the files are ASCII files. It also reports files which are
* unique to one of the two directories.
* An option "h" (for header) causes diffdir to print each difference
* on a new page (using an appropriate "pr") and to summarize missing
* files and differences in binary files on a final page.
* Option "s" causes files which are the same to be reported also.
* It would be nice if this were "difftree", and if it knew a few
* more things, e.g to "size" objects which are different or some
* such or at least to not say that "directories are different" calling
* them files, i.e. "Files ex-1.1/temp and ex-1.2/temp are different".
#define vprintf if (vflg) printf
register struct entry
*d1
, *d2
;
while (*cp
) switch (*cp
++) {
panic("Usage: diffdir [ -h ] dir1 dir2");
setupdir(argv
[1], &dir1
);
setupdir(argv
[2], &dir2
);
while (d1
->name
!= 0 || d2
->name
!= 0) {
if (d1
->name
!= 0 && d2
->name
!= 0)
switch (sgn(strcmp(d1
->name
, d2
->name
))) {
printf("Only in %s: %s\n", argv
[1], d1
->name
);
vprintf("In both: %s\n", d1
->name
);
compare(d1
, argv
[1], argv
[2]);
printf("Only in %s: %s\n", argv
[2], d2
->name
);
for (d1
= dir1
; d1
->name
; d1
++)
printf("\fOnly in %s\n", argv
[1]);
printf("\t%s\n", d1
->name
);
for (d2
= dir2
; d2
->name
!= 0; d2
++) {
printf("Only in %s\n", argv
[2]);
printf("\t%s\n", d2
->name
);
for (d1
= dir1
; d1
->name
; d1
++)
if (d1
->flags
& DIFFER
) {
printf("Non-ascii files which differ:\n");
printf("\t%s\n", d1
->name
);
register struct entry
*hp
;
while (read(0, &dirent
, sizeof (struct dirent0
)) == sizeof (struct dirent0
))
hp
= *head
= Calloc(count
, sizeof **head
);
while (read(0, &dirent
, sizeof (struct dirent0
)) == sizeof (struct dirent0
))
hp
->name
= savestr(dirent
.fname
);
qsort(*head
, count
- 1, sizeof **head
, entcmp
);
return (strcmp(ep
->name
, ep2
->name
));
panic("Ran out of memory");
return (strcpy(calloc(strlen(cp
)+1, sizeof (char)), cp
));
fprintf(stderr
, "%s\n", cp
);
char path1
[100], path2
[100];
if (max(strlen(d1
), strlen(d2
)) + strlen(name
) + 2 >= 100)
panic("Path names too long");
strcat(strcat(strcpy(path1
, d1
), "/"), name
);
strcat(strcat(strcpy(path2
, d2
), "/"), name
);
i
= callit("/usr/bin/cmp", "cmp", "-s", path1
, path2
, 0);
printf("Files %s and %s same\n", path1
, path2
);
if (!ascii(path1
) || !ascii(path2
)) {
printf("Files %s and %s differ\n", path1
, path2
);
sprintf(header
, "diff %s %s", path1
, path2
);
prcallit(header
, "/usr/bin/diff", "diff", path1
, path2
, 0);
printf("diff %s %s\n", path1
, path2
);
callit("/usr/bin/diff", "diff", path1
, path2
, 0);
prcallit(header
, path
, av
)
panic("No more processes");
execl("/bin/pr", "pr", "-h", header
, 0);
execl("/usr/bin/pr", "pr", "-h", header
, 0);
panic("No more processes");
while (wait(&status
) != -1)
panic("No more processes");
return (((status
>> 8) & 0377) | (status
& 0377));
if (read(f
, &w
, sizeof w
) != sizeof w
) {
case 0405: /* Overlay executable */
case 0407: /* Executable */
case 0410: /* Pure executable */
case 0411: /* Separate executable */
case 0177545: /* Archive */
case 0177555: /* Old archive */
if (strcmp(cp
, ".") == 0 || strcmp(cp
, "..") == 0)
return (1); /* For now */