version 1.32, 2007/06/09 05:16:21 |
version 1.33, 2009/06/06 15:37:28 |
|
|
static int dircompare(const void *, const void *); |
static int dircompare(const void *, const void *); |
static int excluded(const char *); |
static int excluded(const char *); |
static struct dirent **slurpdir(char *, char **, int); |
static struct dirent **slurpdir(char *, char **, int); |
static void diffit(struct dirent *, char *, size_t, char *, size_t); |
static void diffit(struct dirent *, char *, size_t, char *, size_t, int); |
|
|
#define d_status d_type /* we need to store status for -l */ |
#define d_status d_type /* we need to store status for -l */ |
|
|
|
|
* Diff directory traversal. Will be called recursively if -r was specified. |
* Diff directory traversal. Will be called recursively if -r was specified. |
*/ |
*/ |
void |
void |
diffdir(char *p1, char *p2) |
diffdir(char *p1, char *p2, int flags) |
{ |
{ |
struct dirent **dirp1, **dirp2, **dp1, **dp2; |
struct dirent **dirp1, **dirp2, **dp1, **dp2; |
struct dirent *dent1, *dent2; |
struct dirent *dent1, *dent2; |
|
|
strcmp(dent1->d_name, dent2->d_name); |
strcmp(dent1->d_name, dent2->d_name); |
if (pos == 0) { |
if (pos == 0) { |
/* file exists in both dirs, diff it */ |
/* file exists in both dirs, diff it */ |
diffit(dent1, path1, dirlen1, path2, dirlen2); |
diffit(dent1, path1, dirlen1, path2, dirlen2, flags); |
dp1++; |
dp1++; |
dp2++; |
dp2++; |
} else if (pos < 0) { |
} else if (pos < 0) { |
/* file only in first dir, only diff if -N */ |
/* file only in first dir, only diff if -N */ |
if (Nflag) |
if (Nflag) |
diffit(dent1, path1, dirlen1, path2, dirlen2); |
diffit(dent1, path1, dirlen1, path2, dirlen2, |
|
flags); |
else if (lflag) |
else if (lflag) |
dent1->d_status |= D_ONLY; |
dent1->d_status |= D_ONLY; |
else |
else |
|
|
} else { |
} else { |
/* file only in second dir, only diff if -N or -P */ |
/* file only in second dir, only diff if -N or -P */ |
if (Nflag || Pflag) |
if (Nflag || Pflag) |
diffit(dent2, path1, dirlen1, path2, dirlen2); |
diffit(dent2, path1, dirlen1, path2, dirlen2, |
|
flags); |
else if (lflag) |
else if (lflag) |
dent2->d_status |= D_ONLY; |
dent2->d_status |= D_ONLY; |
else |
else |
|
|
* Do the actual diff by calling either diffreg() or diffdir(). |
* Do the actual diff by calling either diffreg() or diffdir(). |
*/ |
*/ |
static void |
static void |
diffit(struct dirent *dp, char *path1, size_t plen1, char *path2, size_t plen2) |
diffit(struct dirent *dp, char *path1, size_t plen1, char *path2, size_t plen2, |
|
int flags) |
{ |
{ |
int flags = D_HEADER; |
flags |= D_HEADER; |
|
|
strlcpy(path1 + plen1, dp->d_name, MAXPATHLEN - plen1); |
strlcpy(path1 + plen1, dp->d_name, MAXPATHLEN - plen1); |
if (stat(path1, &stb1) != 0) { |
if (stat(path1, &stb1) != 0) { |
if (!(Nflag || Pflag) || errno != ENOENT) { |
if (!(Nflag || Pflag) || errno != ENOENT) { |
|
|
|
|
if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) { |
if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) { |
if (rflag) |
if (rflag) |
diffdir(path1, path2); |
diffdir(path1, path2, flags); |
else if (lflag) |
else if (lflag) |
dp->d_status |= D_COMMON; |
dp->d_status |= D_COMMON; |
else |
else |