]> thyrsus.com Git - comparator.git/commitdiff
Capture trailing braces on C functions.
authorEric S. Raymond <esr@thyrsus.com>
Fri, 12 Sep 2003 22:16:41 +0000 (22:16 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Fri, 12 Sep 2003 22:16:41 +0000 (22:16 +0000)
main.c
shred.h
shredtree.c

diff --git a/main.c b/main.c
index 40e37854b2e24c75d23bb059ed525cca9d52be82..a627e828ebe6fdfa1a9791dcfe13fa6244f74f64 100644 (file)
--- 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 98da0ba8fb1b9e5d0021655b509cd6aba8e80ece..425644c9b2d13281e866dac853099d3f71ae453a 100644 (file)
--- 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);
 
index 8a4de6d0094907c0386aed7271b5c9ce52b5c790..08537ac4baaf00f274800f92bfa90d3ce2e92bf1 100644 (file)
@@ -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 */