]> thyrsus.com Git - comparator.git/commitdiff
Added comment stripping.
authorEric S. Raymond <esr@thyrsus.com>
Wed, 10 Sep 2003 09:31:46 +0000 (09:31 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Wed, 10 Sep 2003 09:31:46 +0000 (09:31 +0000)
Makefile
comparator.xml
main.c
shred.h
shredtree.c

index 36d9ce3cf8fff051e4685ed76a23945399f610a5..a69cd9c9ad9de7757bafe1e7a6a52c15a742329b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -34,11 +34,11 @@ scf-standard.html: scf-standard.xml
        xmlto html-nochunks scf-standard.xml
 
 test1: comparator
-       @comparator -w -C -d test test1-a test1-b
+       @comparator -C -d test test1-a test1-b
 test2: comparator
-       @comparator -w -C -d test test2-a test2-b
+       @comparator -C -d test test2-a test2-b
 test3: comparator
-       @comparator -w -C -d test test3-a test3-b
+       @comparator -C -d test test3-a test3-b
 
 install: comparator.1 uninstall
        install -m 755 -o 0 -g 0 -d $(ROOT)/usr/bin/
index f83f7898bf6cb396b850bcc7dfbb000ab365a894..82fe0f9d9ba5a5028d98f963722d341d32eb1e34 100644 (file)
 <cmdsynopsis>
   <command>comparator</command>
   <arg choice='opt'>-c</arg>
+  <arg choice='opt'>-C</arg>
   <arg choice='opt'>-d <replaceable>dir</replaceable></arg>
   <arg choice='opt'>-o <replaceable>file</replaceable></arg>
+  <arg choice='opt'>-r</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/>
@@ -99,6 +100,9 @@ applies C-language-specific normalization; { and } characters are
 removed.  This is recommended for comparing C code; it prevents the
 comparison from being fooled by differences in indent style.</para>
 
+<para>The <option>-r</option> option removes comments.  This is 
+only effective in conjunction with <option>-C</option>.</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 f5c0f3b622da0de797d2439132b90d643f6d17de..e0dd202edbe56c7e7059e43f9fc663259fdd0736 100644 (file)
--- a/main.c
+++ b/main.c
@@ -86,6 +86,8 @@ static void write_scf(const char *tree, FILE *ofp)
     buf[0] = '\0';
     if (remove_whitespace)
        strcat(buf, "remove-whitespace,");
+    if (remove_comments)
+       strcat(buf, "remove-comments,");
     if (remove_braces)
        strcat(buf, "remove-braces,");
     if (buf[0])
@@ -331,10 +333,12 @@ void report_time(char *legend, ...)
 
 static void usage(void)
 {
-    fprintf(stderr,"usage: shredtree [-c] [-d dir ] [-o file] [-s shredsize] [-w] [-x] path...\n");
+    fprintf(stderr,"usage: comparator [-c] [-C] [-d dir ] [-r] [-o file] [-s shredsize] [-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,"  -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);
     fprintf(stderr,"  -w      = remove whitespace.\n");
     fprintf(stderr,"  -x      = debug, display chunks in output.\n");
@@ -352,7 +356,7 @@ main(int argc, char *argv[])
 
     compile_only = file_only = 0;
     dir = outfile = NULL;
-    while ((status = getopt(argc, argv, "cCd:ho:s:wx")) != EOF)
+    while ((status = getopt(argc, argv, "cCd:ho:rs:wx")) != EOF)
     {
        switch (status)
        {
@@ -361,7 +365,7 @@ main(int argc, char *argv[])
            break;
 
        case 'C':
-           remove_braces = 1;
+           remove_whitespace = remove_braces = 1;
            break;
 
        case 'd':
@@ -372,6 +376,9 @@ main(int argc, char *argv[])
            outfile = optarg;
            break;
 
+       case 'r':
+           remove_comments = 1;
+
        case 's':
            shredsize = atoi(optarg);
            break;
@@ -480,9 +487,11 @@ main(int argc, char *argv[])
        dummy_scf.hash_method = "MD5";
        buf[0] == '\0';
        if (remove_whitespace)
-           strcat(buf, "remove-whitespace,");
+           strcat(buf, "remove-whitespace, ");
+       if (remove_comments)
+           strcat(buf, "remove-comments, ");
        if (remove_braces)
-           strcat(buf, "remove-braces,");
+           strcat(buf, "remove-braces, ");
        if (buf[0])
            buf[strlen(buf)-1] = '\0';
        else
diff --git a/shred.h b/shred.h
index 548d5caae553ffa03a6d1bfb0d0d0cb858c824ea..dd52ba781699452a6c88940ef1e74d87d049261f 100644 (file)
--- a/shred.h
+++ b/shred.h
@@ -33,6 +33,7 @@ struct sorthash_t
 /* control bits, meant to be set at startup */
 extern int remove_braces;
 extern int remove_whitespace;
+extern int remove_comments;
 extern int debug;
 extern int shredsize;
 
index a2fd18b69f5fb2f7fcc630264c5289b2d25f92eb..f8ca2ee7ef147972f9ebd63cbed789756fbb013c 100644 (file)
@@ -13,6 +13,7 @@
 /* control bits, meant to be set at startup */
 int remove_braces = 0;
 int remove_whitespace = 0;
+int remove_comments = 0;
 int shredsize = 3;
 
 struct item
@@ -68,6 +69,13 @@ static int eligible(const char *file)
 static int normalize(char *buf)
 /* normalize a buffer in place, return 0 if it should be skipped */
 {
+    if (remove_comments && remove_braces)      /* remove_c_comments */
+    {
+       char *start = strstr(buf, "/*"), *end = strstr(buf, "*/");
+
+       if (start && end && start < end)
+           strcpy(start, end+2);
+    }
     if (remove_whitespace)     /* strip whitespace, ignore blank lines */
     {
        char *tp, *sp;