]> thyrsus.com Git - comparator.git/commitdiff
We can strip comments now.
authorEric S. Raymond <esr@thyrsus.com>
Wed, 10 Sep 2003 14:28:34 +0000 (14:28 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Wed, 10 Sep 2003 14:28:34 +0000 (14:28 +0000)
comparator.xml
shredtree.c

index 82fe0f9d9ba5a5028d98f963722d341d32eb1e34..054a26c1ce9f52a06b49905f72cf885be738cb40 100644 (file)
@@ -100,8 +100,11 @@ 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>-r</option> option removes comments.  This is only
+effective in conjunction with <option>-C</option>. All // comments,
+but only "winged" /* comments with the start and end of comment on the
+same line are ignored.  Block /* comments are retained, but the
+beginning /* and ending */ are ignored, </para>
 
 <para>The <option>-x</option> enables some debugging output.  It
 is for developers; if you need to understand it, read the code.</para>
index f8ca2ee7ef147972f9ebd63cbed789756fbb013c..dbee27fc51a8ab9d74e9889c1babb1242e12998d 100644 (file)
@@ -71,10 +71,21 @@ static int normalize(char *buf)
 {
     if (remove_comments && remove_braces)      /* remove_c_comments */
     {
-       char *start = strstr(buf, "/*"), *end = strstr(buf, "*/");
+       char    *ss = strstr(buf, "//");
 
-       if (start && end && start < end)
-           strcpy(start, end+2);
+       if (ss)
+           *ss = '\0';
+       else
+       {
+           char *start = strstr(buf, "/*"), *end = strstr(buf, "*/");
+
+           if (start && end && start < end)
+               strcpy(start, end+2);
+           else if (start && !end)
+               *start = '\0';
+           else if (end && !start)
+               *end = '\0';
+       }
     }
     if (remove_whitespace)     /* strip whitespace, ignore blank lines */
     {