]> thyrsus.com Git - comparator.git/commitdiff
We have a -C option now.
authorEric S. Raymond <esr@thyrsus.com>
Wed, 10 Sep 2003 06:56:51 +0000 (06:56 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Wed, 10 Sep 2003 06:56:51 +0000 (06:56 +0000)
Makefile
comparator.xml
main.c
shred.h
shredtree.c

index 294b544205d086f2974b2cdd47ed3d7d4ba6f3cc..cb2e155afd71133aedfb097ff32febcae6ba9e01 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ VERS=1.1
 CODE    = shredtree.c shred.h report.c main.c md5.c md5.h filterator
 DOCS    = README comparator.xml scf-standard.xml COPYING
 EXTRAS  = shredtree.py shredcompare.py
-TEST    = test1 test2 test3 test4
+TEST    = test1
 SOURCES = $(CODE) $(DOCS) $(EXTRAS) $(TEST) comparator.spec Makefile
 CFLAGS=-g
 
@@ -33,10 +33,12 @@ comparator.html: comparator.xml
 scf-standard.html: scf-standard.xml
        xmlto html-nochunks scf-standard.xml
 
-test-a: comparator
-       @comparator test1 test2
-test-b: comparator
-       @comparator test3 test4
+test1: comparator
+       @comparator -w -C -d test test1-a test1-b
+test2: comparator
+       @comparator -w -C -d test test2-a test2-b
+test3: comparator
+       @comparator -w -C -d test test3-a test3-b
 
 install: comparator.1 uninstall
        install -m 755 -o 0 -g 0 -d $(ROOT)/usr/bin/
index 3593281efc3a49b670f5a9284344b00a8f9c701c..ad0c52cb5d9e19e4c88177f8ec375285479919f6 100644 (file)
@@ -21,6 +21,7 @@
   <arg choice='opt'>-o <replaceable>file</replaceable></arg>
   <arg choice='opt'>-s <replaceable>shredsize</replaceable></arg>
   <arg choice='opt'>-w</arg>
+  <arg choice='opt'>-C</arg>
   <arg choice='opt'>-x</arg>
   <arg choice='plain' rep='repeat'>path</arg>
   <sbr/>
@@ -91,9 +92,12 @@ and small similarities.</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).  This is
-recommended for comparing C code; among other things it means the
-comparison won't be fooled by differences in indent style.</para>
+numbers in the output report will nevertheless be correct).</para>
+
+<para>The <option>-C</option> applies C-language-specific
+normalization; { and } characters are removed.  This is recommended
+for comparing C code; it prevents the comparison won't be fooled by
+differences in indent style.</para>
 
 <para>The <option>-x</option> enables some debugging output.  It
 is for developers; if you need to understand it, read the code.</para>
diff --git a/main.c b/main.c
index 4dbdf8d2eca7783173defd79dab22aa858bf72f4..752df1a50af1de9e355955f05a49dc3c67cef60b 100644 (file)
--- a/main.c
+++ b/main.c
@@ -342,7 +342,7 @@ main(int argc, char *argv[])
 
     compile_only = file_only = 0;
     dir = outfile = NULL;
-    while ((status = getopt(argc, argv, "cd:ho:s:wx")) != EOF)
+    while ((status = getopt(argc, argv, "cCd:ho:s:wx")) != EOF)
     {
        switch (status)
        {
@@ -350,6 +350,10 @@ main(int argc, char *argv[])
            compile_only = 1;
            break;
 
+       case 'C':
+           c_normalization = 1;
+           break;
+
        case 'd':
            dir = optarg;
            break;
@@ -524,12 +528,12 @@ main(int argc, char *argv[])
        sort_hashes(sort_buffer, sort_count);
        report_time("Sort done");
 
-#ifdef DEBUG
        if (debug)
        {
            puts("Chunk list before reduction.");
-           dump_array(obarray, hashcount, NULL);
+           dump_array(sort_buffer, sort_count, NULL);
        }
+#ifdef DEBUG
 #endif /* DEBUG */
 
        emit_report(sort_buffer, sort_count);
diff --git a/shred.h b/shred.h
index 894af0387b19e00e4e791d694facf60b0a7dc24b..dd811b9b614243c34a7ebc6cdba5a0b7361d31b3 100644 (file)
--- a/shred.h
+++ b/shred.h
@@ -31,7 +31,7 @@ struct sorthash_t
 };
 
 /* control bits, meant to be set at startup */
-extern int c_only;
+extern int c_normalization;
 extern int rws;
 extern int debug;
 extern int shredsize;
index 6a5ab929e3dcd30294150bcdc0bebf02b04bc1e4..871df66da074c2e595109222e2e7f0a5fefe2dd0 100644 (file)
@@ -11,7 +11,7 @@
 #include "shred.h"
 
 /* control bits, meant to be set at startup */
-int c_only = 0;
+int c_normalization = 0;
 int rws = 0;
 int shredsize = 3;
 
@@ -77,6 +77,15 @@ static int normalize(char *buf)
                *tp++ = *sp;
        *tp = '\0';
     }
+    if (c_normalization)       /* strip whitespace, ignore blank lines */
+    {
+       char *tp, *sp;
+
+       for (tp = sp = buf; *sp; sp++)
+           if (*sp != '{' && *sp != '}')
+               *tp++ = *sp;
+       *tp = '\0';
+    }
 
     return(buf[0]);
 }