]> thyrsus.com Git - comparator.git/commitdiff
Added -m option.
authorEric S. Raymond <esr@thyrsus.com>
Tue, 16 Sep 2003 15:22:46 +0000 (15:22 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Tue, 16 Sep 2003 15:22:46 +0000 (15:22 +0000)
comparator.xml
filterator
main.c
report.c
shred.h

index fc26f682192684b4b998f261bd188d73348e48c8..0c4ec42c6163cd189ec005682dd2fc987116e009 100644 (file)
@@ -19,6 +19,7 @@
   <arg choice='opt'>-c</arg>
   <arg choice='opt'>-C</arg>
   <arg choice='opt'>-d <replaceable>dir</replaceable></arg>
+  <arg choice='opt'>-m <replaceable>size</replaceable></arg>
   <arg choice='opt'>-o <replaceable>file</replaceable></arg>
   <arg choice='opt'>-r</arg>
   <arg choice='opt'>-s <replaceable>shredsize</replaceable></arg>
@@ -29,8 +30,8 @@
   <sbr/>
   <command>filterator</command>
   <arg choice='opt'>-d <replaceable>dir</replaceable></arg>
+  <arg choice='opt'>-m <replaceable>minsize</replaceable></arg>
   <arg choice='opt'>-n</arg>
-  <arg choice='opt'>-s <replaceable>minsize</replaceable></arg>
   <arg choice='opt'>-x</arg>
 </cmdsynopsis>
 
@@ -88,7 +89,10 @@ line.  The name of the resulting file is the argument name with
 <para>The <option>-o</option> directs output to a specified file. This
 may be used with <option>-c</option> to override the normal
 <filename>.scf</filename> convention, or simply as an alternative
-to ouput redirection when generating a final report.</para>
+to ouput redirection when generating a final report.  One advantage
+of <option>-o</option> is that the program won't create the output
+file until it is ready to write; thus, unlike shell redirects, it
+won't leave an empty file lying aeound if it aborts early.</para>
 
 <para>The <option>-d</option> option changes current directory to the
 specified tree before walking down each argument path to generate
@@ -101,6 +105,14 @@ shred sizes are more sensitive to small code duplications, but produce
 correspondingly noisier output.  Larger ones will suppress both noise
 and small similarities.</para>
 
+<para>The <option>-m</option> option sets the minimum-sized span
+of lines that will be output.  By default this is zero; setting it
+to a value higher than the shred size will eliminate a lot of junk
+from the report.  These are two separate parameters because shred size
+controls how likely common segments are to not get recognized because
+of unshared things near them, while minimum span size defines the
+smallest features we want to see in the output report.</para>
+
 <para>The <option>-w</option> causes all whitespace in the file
 (including blank lines) to be ignored for comparison purposes (line
 numbers in the output report will nevertheless be correct).</para>
@@ -141,7 +153,7 @@ The noise test for shell files throws away Bourne-shell keywords</para>
 
 <para>The <option>-n</option> suppresses noise filtering.  The
 <option>-d</option> acts as it does for
-<application>comparator</application>.  The <option>-s</option> option
+<application>comparator</application>.  The <option>-m</option> option
 sets the minimum size of overlap to be reported. Setting this to a
 slightly larger number than the <application>comparator</application>
 shred size is a useful way to filter out spurious matches; thus, while
index aa8750a3d2f343c82fa87c17ca4d41c61e1a2b73..3f40d3dd69b6039f98b29226380a4069a241b652 100755 (executable)
@@ -218,7 +218,7 @@ if __name__ == '__main__':
     try:
         (optlist, args) = getopt.getopt(sys.argv[1:], 'd:ns:Sx')
     except getopt.GetoptError:
-        sys.stderr.write("usage: filterator [-d dir] [-n] [-s size] [-x]\n")
+        sys.stderr.write("usage: filterator [-d dir] [-m size] [-n] [-x]\n")
         sys.exit(2)
     stats = nofilter = debug = 0
     minsize = 5
@@ -226,10 +226,10 @@ if __name__ == '__main__':
     for (opt, val) in optlist:
         if opt == '-d':
             os.chdir(val)
+        elif opt == '-m':
+            minsize = int(val)
         elif opt == '-n':
             nofilter = 1
-        elif opt == '-s':
-            minsize = int(val)
         elif opt == '-S':
             stats = 1
         elif opt == '-x':
diff --git a/main.c b/main.c
index 43fcac86b0ecd334b44e4598e54ba51cf643afd1..ba359c8e492f8394762ff1c08c63dbccd85ae335 100644 (file)
--- a/main.c
+++ b/main.c
@@ -10,7 +10,7 @@
 #include <time.h>
 #include "shred.h"
 
-int verbose = 0, debug = 0;
+int verbose, debug, minsize;
 
 struct scf_t
 {
@@ -392,10 +392,11 @@ static FILE *redirect(const char *outfile)
 
 static void usage(void)
 {
-    fprintf(stderr,"usage: comparator [-c] [-C] [-d dir ] [-r] [-o file] [-s shredsize] [-v] [-w] [-x] path...\n");
+    fprintf(stderr,"usage: comparator [-c] [-C] [-d dir ] [-m minsize] [-r] [-o file] [-s shredsize] [-v] [-w] [-x] path...\n");
     fprintf(stderr,"  -c      = generate SCF files\n");
     fprintf(stderr,"  -C      = apply C normalizations\n");
     fprintf(stderr,"  -d dir  = change directory before digesting.\n");
+    fprintf(stderr,"  -m size = set minimum size of span to be output.\n");
     fprintf(stderr,"  -o file = write to the specified file.\n");
     fprintf(stderr,"  -r      = renove comments\n");
     fprintf(stderr,"  -s size = set shred size (default %d)\n", shredsize);
@@ -418,7 +419,7 @@ main(int argc, char *argv[])
 
     compile_only = file_only = 0;
     dir = outfile = NULL;
-    while ((status = getopt(argc, argv, "cCd:ho:rs:vwx")) != EOF)
+    while ((status = getopt(argc, argv, "cCd:hm:o:rs:vwx")) != EOF)
     {
        switch (status)
        {
@@ -434,6 +435,10 @@ main(int argc, char *argv[])
            dir = optarg;
            break;
 
+       case 'm':
+           minsize = atoi(optarg);
+           break;
+
        case 'o':
            outfile = optarg;
            break;
index e7adbdfef4f161ef9bb56d78018a3535195e701d..ab14e21550fbd8827cd42c57958be2fe13bfcf08 100644 (file)
--- a/report.c
+++ b/report.c
@@ -365,6 +365,22 @@ void emit_report(struct sorthash_t *obarray, int hashcount)
     {
        int     i;
 
+       if (minsize)
+       {
+           int maxsize = 0;
+
+           for (i=0; i < match->nmatches; i++)
+           {
+               struct sorthash_t       *rp = match->matches+i;
+               int matchsize = rp->hash.end - rp->hash.start + 1;
+
+               if (matchsize >= maxsize)
+                   maxsize = matchsize;
+           }
+           if (maxsize < minsize)
+               continue;
+       }
+
        for (i=0; i < match->nmatches; i++)
        {
            struct sorthash_t   *rp = match->matches+i;
diff --git a/shred.h b/shred.h
index 527f6cea40041a06c628ade498494a088d1979ee..ecd9a33d946c9d138a2dc21d87bb18d3e3d63a85 100644 (file)
--- a/shred.h
+++ b/shred.h
@@ -50,7 +50,7 @@ extern int remove_braces;
 extern int remove_whitespace;
 extern int remove_comments;
 extern int verbose, debug;
-extern int shredsize;
+extern int shredsize, minsize;
 
 /* main.c functions */
 extern void report_time(char *legend, ...);