From 1e5f268d2c213a9dc0e83227ba5c9ba6a3fa8b84 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Fri, 19 Sep 2003 11:50:54 +0000 Subject: [PATCH] Clean up the chunk-extension logic. --- linebyline.c | 13 +------------ main.c | 8 ++++---- shred.h | 2 +- shredtree.c | 9 +++++++++ 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/linebyline.c b/linebyline.c index e915ef3..b3302f3 100644 --- a/linebyline.c +++ b/linebyline.c @@ -213,7 +213,7 @@ feature_t *analyzer_get(const struct filehdr_t *file, FILE *fp, linenum_t *linen char buf[BUFSIZ]; static feature_t feature; - while(fgets(buf, sizeof(buf), fp) != NULL) + while (fgets(buf, sizeof(buf), fp) != NULL) { int braceline = 0; @@ -233,18 +233,7 @@ feature_t *analyzer_get(const struct filehdr_t *file, FILE *fp, linenum_t *linen 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(file->length); continue; - } /* maybe we can get the file type from the first line? */ if (linecount == 1 && buf[0] == '#') diff --git a/main.c b/main.c index 8c8b364..913f760 100644 --- a/main.c +++ b/main.c @@ -88,13 +88,13 @@ void corehook(struct hash_t hash, struct filehdr_t *file) sort_count++; } -void extend_current_chunk(limit) -/* bump the end-line number on the last chunk, if there is one */ +void extend_current_chunk(linenum_t linenumber) +/* set the end-line number on the last chunk, if there is one */ { if (sort_count > 0) - sort_buffer[sort_count-1].hash.end++; + sort_buffer[sort_count-1].hash.end = linenumber; if (chunk_count > 0) - chunk_buffer[chunk_count-1].end++; + chunk_buffer[chunk_count-1].end = linenumber; } static void write_options(char *buf) diff --git a/shred.h b/shred.h index 7c27233..8fb366a 100644 --- a/shred.h +++ b/shred.h @@ -70,7 +70,7 @@ extern int shredsize, minsize; extern void report_time(char *legend, ...); struct filehdr_t *register_file(const char *file, linenum_t length); extern void corehook(struct hash_t hash, struct filehdr_t *file); -extern void extend_current_chunk(int); +extern void extend_current_chunk(linenum_t); extern void dump_array(const char *legend, struct sorthash_t *obarray, int hashcount); extern void dump_flags(const int flags, FILE *fp); diff --git a/shredtree.c b/shredtree.c index 86434da..16821d0 100644 --- a/shredtree.c +++ b/shredtree.c @@ -162,6 +162,15 @@ int shredfile(struct filehdr_t *file, } if (accepted && accepted < shredsize) hook(emit_chunk(display, linenumber), file); + else if (accepted) + /* + * 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. + */ + extend_current_chunk(linenumber); free(display); fclose(fp); -- 2.43.0