From ace9f95a8c5c93be667f9ce8aa22c6079902e407 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 16 Sep 2003 15:22:46 +0000 Subject: [PATCH] Added -m option. --- comparator.xml | 18 +++++++++++++++--- filterator | 6 +++--- main.c | 11 ++++++++--- report.c | 16 ++++++++++++++++ shred.h | 2 +- 5 files changed, 43 insertions(+), 10 deletions(-) diff --git a/comparator.xml b/comparator.xml index fc26f68..0c4ec42 100644 --- a/comparator.xml +++ b/comparator.xml @@ -19,6 +19,7 @@ -c -C -d dir + -m size -o file -r -s shredsize @@ -29,8 +30,8 @@ filterator -d dir + -m minsize -n - -s minsize -x @@ -88,7 +89,10 @@ line. The name of the resulting file is the argument name with The directs output to a specified file. This may be used with to override the normal .scf convention, or simply as an alternative -to ouput redirection when generating a final report. +to ouput redirection when generating a final report. One advantage +of is that the program won't create the output +file until it is ready to write; thus, unlike shell redirects, it +won't leave an empty file lying aeound if it aborts early. The option changes current directory to the specified tree before walking down each argument path to generate @@ -101,6 +105,14 @@ shred sizes are more sensitive to small code duplications, but produce correspondingly noisier output. Larger ones will suppress both noise and small similarities. +The option sets the minimum-sized span +of lines that will be output. By default this is zero; setting it +to a value higher than the shred size will eliminate a lot of junk +from the report. These are two separate parameters because shred size +controls how likely common segments are to not get recognized because +of unshared things near them, while minimum span size defines the +smallest features we want to see in the output report. + 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). @@ -141,7 +153,7 @@ The noise test for shell files throws away Bourne-shell keywords The suppresses noise filtering. The acts as it does for -comparator. The option +comparator. The option sets the minimum size of overlap to be reported. Setting this to a slightly larger number than the comparator shred size is a useful way to filter out spurious matches; thus, while diff --git a/filterator b/filterator index aa8750a..3f40d3d 100755 --- a/filterator +++ b/filterator @@ -218,7 +218,7 @@ if __name__ == '__main__': try: (optlist, args) = getopt.getopt(sys.argv[1:], 'd:ns:Sx') except getopt.GetoptError: - sys.stderr.write("usage: filterator [-d dir] [-n] [-s size] [-x]\n") + sys.stderr.write("usage: filterator [-d dir] [-m size] [-n] [-x]\n") sys.exit(2) stats = nofilter = debug = 0 minsize = 5 @@ -226,10 +226,10 @@ if __name__ == '__main__': for (opt, val) in optlist: if opt == '-d': os.chdir(val) + elif opt == '-m': + minsize = int(val) elif opt == '-n': nofilter = 1 - elif opt == '-s': - minsize = int(val) elif opt == '-S': stats = 1 elif opt == '-x': diff --git a/main.c b/main.c index 43fcac8..ba359c8 100644 --- a/main.c +++ b/main.c @@ -10,7 +10,7 @@ #include #include "shred.h" -int verbose = 0, debug = 0; +int verbose, debug, minsize; struct scf_t { @@ -392,10 +392,11 @@ static FILE *redirect(const char *outfile) static void usage(void) { - fprintf(stderr,"usage: comparator [-c] [-C] [-d dir ] [-r] [-o file] [-s shredsize] [-v] [-w] [-x] path...\n"); + fprintf(stderr,"usage: comparator [-c] [-C] [-d dir ] [-m minsize] [-r] [-o file] [-s shredsize] [-v] [-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," -m size = set minimum size of span to be output.\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); @@ -418,7 +419,7 @@ main(int argc, char *argv[]) compile_only = file_only = 0; dir = outfile = NULL; - while ((status = getopt(argc, argv, "cCd:ho:rs:vwx")) != EOF) + while ((status = getopt(argc, argv, "cCd:hm:o:rs:vwx")) != EOF) { switch (status) { @@ -434,6 +435,10 @@ main(int argc, char *argv[]) dir = optarg; break; + case 'm': + minsize = atoi(optarg); + break; + case 'o': outfile = optarg; break; diff --git a/report.c b/report.c index e7adbdf..ab14e21 100644 --- a/report.c +++ b/report.c @@ -365,6 +365,22 @@ void emit_report(struct sorthash_t *obarray, int hashcount) { int i; + if (minsize) + { + int maxsize = 0; + + for (i=0; i < match->nmatches; i++) + { + struct sorthash_t *rp = match->matches+i; + int matchsize = rp->hash.end - rp->hash.start + 1; + + if (matchsize >= maxsize) + maxsize = matchsize; + } + if (maxsize < minsize) + continue; + } + for (i=0; i < match->nmatches; i++) { struct sorthash_t *rp = match->matches+i; diff --git a/shred.h b/shred.h index 527f6ce..ecd9a33 100644 --- a/shred.h +++ b/shred.h @@ -50,7 +50,7 @@ extern int remove_braces; extern int remove_whitespace; extern int remove_comments; extern int verbose, debug; -extern int shredsize; +extern int shredsize, minsize; /* main.c functions */ extern void report_time(char *legend, ...); -- 2.43.0