3 ###############################################################################
5 # Name : differ (with recursion support) #
6 # Author : Chris Koeritz #
7 # Rights : Copyright (C) 1996-$now by Author #
11 # Compares files in a directory hierarchy to files in another hierarchy. #
12 # Any files with the same name will be compared and files that exist in one #
13 # but not the other are reported. #
15 ###############################################################################
16 # This program is free software; you can redistribute it and/or modify it #
17 # under the terms of the GNU General Public License as published by the Free #
18 # Software Foundation; either version 2 of the License or (at your option) #
19 # any later version. See: "http://www.gruntose.com/Info/GNU/GPL.html" for a #
20 # version of the License. Please send any updates to "fred@gruntose.com". #
21 ###############################################################################
23 require "diff_lib.pl";
24 require "filename_helper.pl";
26 &install_interrupt_catcher;
28 # check that we received at least one parameter.
34 # get the two directories from the command line.
35 local($destination) = $ARGV[0];
38 # get the location they provided.
42 # make the names a little more manipulable.
43 $source = &sanitize_name($source);
44 # print "source is now: $source\n";
45 $destination = &sanitize_name($destination);
46 # print "dest is now: $destination\n";
48 # call the routine that does all the work.
49 &recurse_dirs($source, $destination);
53 ############################################################################
55 sub print_instructions
59 This program requires at least one directory name as a parameter. This is
60 the location to use as the target directory. The second parameter, if
61 provided, is the location to use as the source directory. The recursive
62 differ script will traverse the source hierarchy and attempt to compare
63 the contents of the directories in that hierarchy against the destination
64 hierarchy. This will fail where the hierarchies have different directory
65 structures. But where the directories exist in both hierarchies, their
66 contents are compared against each other and documented in the output.
70 ############################################################################
74 local($src, $dest) = @_;
76 if ($src =~ /\/CVS$/) { return; } # skip comparing repositories.
77 #hmmm: why is only CVS spelled out here? what about the others?
80 print "$src is not a directory.\n";
86 # print "recurse_dirs: source is $src and destination is $dest.\n";
88 opendir(SRC_DIR, $src);
89 local(@source_list) = readdir(SRC_DIR);
91 opendir(DEST_DIR, $dest);
92 local(@dest_list) = readdir(DEST_DIR);
95 ## if (&same_file($src, $dest)) {
96 ## # these appear to be the same directory. we shouldn't recurse in.
97 ##print "found same dirs! $src and $dest\n";
100 # now actually call the differ. this is a prefix traveral of the tree.
104 # remember that the destination is actually the first parameter for
105 # diff_dirs, although the source is first for differ...
106 # print "diffing src=$src against dest=$dest\n";
107 &diff_dirs($dest, $src);
109 print "$break_line\n";
110 print "Source directory has \"$src\", but target does not.\n";
113 # iterate through the directory.
115 foreach $name (@source_list) {
116 local($compare_name) = $dest . "/" . $name;
117 # print "name is $name and to compare is $compare_name.\n";
118 local($new_name) = $src . "/" . $name;
119 if ( (-d $new_name) && ($name ne ".") && ($name ne "..")
122 && ($name ne "CVS") ) {
123 # print "recursing on: source $name and destination $compare_name.\n";
124 &recurse_dirs($new_name, $compare_name);