nice new tool to show version of feisty meow
[feisty_meow.git] / scripts / text / differ.pl
1 #!/usr/bin/perl
2
3 ###############################################################################
4 #                                                                             #
5 #  Name   : differ (with recursion support)                                   #
6 #  Author : Chris Koeritz                                                     #
7 #  Rights : Copyright (C) 1996-$now by Author                                 #
8 #                                                                             #
9 #  Purpose:                                                                   #
10 #                                                                             #
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.                                            #
14 #                                                                             #
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 ###############################################################################
22
23 require "diff_lib.pl";
24 require "filename_helper.pl";
25
26 &install_interrupt_catcher;
27
28 # check that we received at least one parameter.
29 if ($#ARGV < 0) {
30   &print_instructions;
31   exit 1;
32 }
33
34 # get the two directories from the command line.
35 local($destination) = $ARGV[0];
36 local($source) = ".";
37 if ($#ARGV > 0) {
38   # use both the locations they provided.
39   $source = $ARGV[0];
40   $destination = $ARGV[1];
41 }
42
43 # make the names a little more manipulable.
44 $source = &sanitize_name($source);
45 # print "source is now: $source\n";
46 $destination = &sanitize_name($destination);
47 # print "dest is now: $destination\n";
48
49 # call the routine that does all the work.
50 &recurse_dirs($source, $destination);
51
52 exit 0;
53
54 ############################################################################
55
56 sub print_instructions
57 {
58   print "
59 differ:\n
60 This program requires at least one directory name as a parameter.  This is
61 the location to use as the target directory.  The second parameter, if
62 provided, is the location to use as the source directory.  The recursive
63 differ script will traverse the source hierarchy and attempt to compare
64 the contents of the directories in that hierarchy against the destination
65 hierarchy.  This will fail where the hierarchies have different directory
66 structures.  But where the directories exist in both hierarchies, their
67 contents are compared against each other and documented in the output.
68 ";
69 }
70
71 ############################################################################
72
73 sub recurse_dirs
74 {
75   local($src, $dest) = @_;
76
77   if ($src =~ /\/CVS$/) { return; }  # skip comparing repositories.
78 #hmmm: why is only CVS spelled out here?  what about the others?
79
80   if (! -d $src) {
81     print "$src is not a directory.\n";
82     return;
83   } elsif (-l $src) {
84     return;
85   }
86   
87 #  print "recurse_dirs: source is $src and destination is $dest.\n";
88
89   opendir(SRC_DIR, $src);
90   local(@source_list) = readdir(SRC_DIR);
91   closedir(SRC_DIR);
92   opendir(DEST_DIR, $dest);
93   local(@dest_list) = readdir(DEST_DIR);
94   closedir(DEST_DIR);
95
96 ##  if (&same_file($src, $dest)) {
97 ##    # these appear to be the same directory.  we shouldn't recurse in.
98 ##print "found same dirs!  $src and $dest\n";
99 ##  }
100
101   # now actually call the differ.  this is a prefix traveral of the tree.
102   if (-l $src) {
103     return;
104   } elsif (-d $dest) {
105     # remember that the destination is actually the first parameter for
106     # diff_dirs, although the source is first for differ...
107 #    print "diffing src=$src against dest=$dest\n";
108     &diff_dirs($dest, $src);
109   } else {
110     print "$break_line\n";
111     print "Source directory has \"$src\", but target does not.\n";
112   }
113
114   # iterate through the directory.
115   local($name);
116   foreach $name (@source_list) {
117     local($compare_name) = $dest . "/" . $name;
118 #    print "name is $name and to compare is $compare_name.\n";
119     local($new_name) = $src . "/" . $name;
120 #hmmm: need an is important dirname check for this.
121     if ( (-d $new_name) && ($name ne ".") && ($name ne "..")
122         && ($name ne ".svn") 
123         && ($name ne ".git") 
124         && ($name ne "bin") 
125         && ($name ne "bin-eclipse") 
126         && ($name ne "bin.eclipse") 
127         && ($name ne "genned-src") 
128         && ($name ne "genned-obj") 
129         && ($name ne "codegen") 
130         && ($name ne "unit-test-reports") 
131         && ($name ne "CVS") ) {
132 #      print "recursing on: source $name and destination $compare_name.\n";
133       &recurse_dirs($new_name, $compare_name);
134     }
135   }
136 }
137