From 7b4ac97727d19f7bd662dc86021cc31e1003c8f9 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Wed, 10 Sep 2003 14:28:34 +0000 Subject: [PATCH] We can strip comments now. --- comparator.xml | 7 +++++-- shredtree.c | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/comparator.xml b/comparator.xml index 82fe0f9..054a26c 100644 --- a/comparator.xml +++ b/comparator.xml @@ -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. -The option removes comments. This is -only effective in conjunction with . +The option removes comments. This is only +effective in conjunction with . 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, The enables some debugging output. It is for developers; if you need to understand it, read the code. diff --git a/shredtree.c b/shredtree.c index f8ca2ee..dbee27f 100644 --- a/shredtree.c +++ b/shredtree.c @@ -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 */ { -- 2.43.0