From: Eric S. Raymond Date: Fri, 12 Sep 2003 22:16:41 +0000 (+0000) Subject: Capture trailing braces on C functions. X-Git-Tag: 1.5~7 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=9841e68ffd836b814104eee190c64a27d32e1a7b;p=comparator.git Capture trailing braces on C functions. --- diff --git a/main.c b/main.c index 40e3785..a627e82 100644 --- a/main.c +++ b/main.c @@ -73,6 +73,13 @@ void corehook(struct hash_t hash, const char *file) sort_count++; } +void extend_current_chunk(void) +/* bump the end-line number on the last chunk, if there is one */ +{ + if (sort_count > 0) + sort_buffer[sort_count-1].hash.end++; +} + static void write_scf(const char *tree, FILE *ofp) /* generate shred file for given tree */ { diff --git a/shred.h b/shred.h index 98da0ba..425644c 100644 --- a/shred.h +++ b/shred.h @@ -36,6 +36,7 @@ extern int shredsize; /* main.c functions */ extern void report_time(char *legend, ...); extern void corehook(struct hash_t hash, const char *file); +extern void extend_current_chunk(void); extern void dump_array(const char *legend, struct sorthash_t *obarray, int hashcount); diff --git a/shredtree.c b/shredtree.c index 8a4de6d..08537ac 100644 --- a/shredtree.c +++ b/shredtree.c @@ -177,9 +177,30 @@ int shredfile(const char *file, accepted = linecount = 0; while(fgets(buf, sizeof(buf), fp) != NULL) { + int braceline = 0; + linecount++; + if (remove_braces) + { + char *cp; + + for (cp = buf; *cp && isspace(*cp); cp++) + continue; + braceline = (*cp == '}'); + } if (!normalize(buf)) + { + /* + * What this is for is to include trailing C } lines in chunk + * listings even though we're ignoring them for comparison + * purposes (in order not to be fooled by variance in indent + * styles). This is a kluge, but it means we will capture + * entire C functions that differ only by brace placement. + */ + if (remove_braces && braceline) + extend_current_chunk(); continue; + } accepted++; /* create new shred */