From 341d43547484f1c3a8f3fea7fbf5ab9db9fa4f7d Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Wed, 10 Sep 2003 06:56:51 +0000 Subject: [PATCH] We have a -C option now. --- Makefile | 12 +++++++----- comparator.xml | 10 +++++++--- main.c | 10 +++++++--- shred.h | 2 +- shredtree.c | 11 ++++++++++- 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 294b544..cb2e155 100644 --- 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/ diff --git a/comparator.xml b/comparator.xml index 3593281..ad0c52c 100644 --- a/comparator.xml +++ b/comparator.xml @@ -21,6 +21,7 @@ -o file -s shredsize -w + -C -x path @@ -91,9 +92,12 @@ and small similarities. The 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. +numbers in the output report will nevertheless be correct). + +The 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. The enables some debugging output. It is for developers; if you need to understand it, read the code. diff --git a/main.c b/main.c index 4dbdf8d..752df1a 100644 --- 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 894af03..dd811b9 100644 --- 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; diff --git a/shredtree.c b/shredtree.c index 6a5ab92..871df66 100644 --- a/shredtree.c +++ b/shredtree.c @@ -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]); } -- 2.43.0