From 9ddafb2f99208c19df468190188486d608f802a5 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Wed, 10 Sep 2003 17:22:16 +0000 Subject: [PATCH] We can now ignore shell comments. --- comparator.xml | 21 ++++++++++++++------- shredtree.c | 39 ++++++++++++++++++++++++--------------- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/comparator.xml b/comparator.xml index 054a26c..8eb58e9 100644 --- a/comparator.xml +++ b/comparator.xml @@ -29,6 +29,8 @@ filterator -d dir -n + -s minsize + -x @@ -101,10 +103,11 @@ removed. This is recommended for comparing C code; it prevents the comparison from being fooled by differences in indent style. The option removes comments. This is only -effective in conjunction with . All // comments, +effective in conjunction with . In C files, ll // 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, +same line are ignored; also, block /* comments are retained, but the +beginning /* and ending */ are ignored, In other files, all # +comments are removed. The enables some debugging output. It is for developers; if you need to understand it, read the code. @@ -121,14 +124,18 @@ percentage of printable characters near the front of the file is above filterator is a postprocessor for the SCF-B output of comparator that produces an actual code listing. By default, it throws away ranges that appear to -be noise. The noise test is to throw away whitespace, C syntax, +be noise. The noise test for C files is to throw away whitespace, C syntax, #include lines and a few common macros and see if anything is left. -The suppresses noise filtering. The +The noise test for shell files throws away Bourne-shell keywords + +The suppresses noise filtering. The acts as it does for comparator. The option sets the minimum size of overlap to be reported; setting this to a -slightly larger number than the comparator shred -size may be a useful way to filter out spurious matches. +slightly larger number than the comparator +shred size may be a useful way to filter out spurious matches. The + enables some debugging output. It is for +developers; if you need to understand it, read the code. Occasionally the filterator output looks as through the code has failed to properly merge two or more diff --git a/shredtree.c b/shredtree.c index 951d28a..b361eb7 100644 --- a/shredtree.c +++ b/shredtree.c @@ -70,24 +70,33 @@ 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 *ss = strstr(buf, "//"); - - if (ss) - *ss = '\0'; + if (remove_comments) + if (remove_braces) /* remove C comments */ + { + char *ss = strstr(buf, "//"); + + 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'; + } + } 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'; + char *ss = strchr(buf, '#'); + + if (ss) + *ss = '\0'; } - } + if (remove_whitespace) /* strip whitespace, ignore blank lines */ { char *tp, *sp; -- 2.43.0