]> git.ozlabs.org Git - ccan/commitdiff
Store pristine contents of files: based on Joey's patch.
authorRusty Russell <rusty@rustcorp.com.au>
Thu, 28 May 2009 03:49:33 +0000 (13:19 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 28 May 2009 03:49:33 +0000 (13:19 +0930)
tools/ccanlint/ccanlint.h
tools/ccanlint/file_analysis.c

index 16a410a98aecb3b3fa864d865515854f0e7ec572..d704d58d6b9fcbd0ee484badeee4b0ba969bb764 100644 (file)
@@ -88,6 +88,11 @@ struct ccan_file {
 
        char *name;
 
+       /* Pristine version of the original file.
+        * Use get_ccan_file_lines to fill this. */
+       const char *contents;
+       size_t contents_size;
+
        /* Use get_ccan_file_lines / get_ccan_line_info to fill these. */
        unsigned int num_lines;
        char **lines;
index dc23eb964b2f5ba3c49bf03a3e52dd3de1311d1b..62e4a13afa8ba1ebcb5efad06c6c34756b5a917b 100644 (file)
 
 char **get_ccan_file_lines(struct ccan_file *f)
 {
-       if (!f->lines) {
-               char *buffer = grab_file(f, f->name, NULL);
-               if (!buffer)
-                       err(1, "Getting file %s", f->name);
-               f->lines = strsplit(f, buffer, "\n", &f->num_lines);
-       }
+       if (!f->lines)
+               f->lines = strsplit(f, f->contents, "\n", &f->num_lines);
+
        return f->lines;
 }
 
@@ -76,13 +73,24 @@ static void add_files(struct manifest *m, const char *dir)
 
                if (streq(f->name, "_info.c")) {
                        m->info_file = f;
+                       f->contents = grab_file(f, f->name, &f->contents_size);
+                       if (!f->contents)
+                               err(1, "Reading file %s", f->name);
                        continue;
                }
 
                is_c_src = strends(f->name, ".c");
-               if (!is_c_src && !strends(f->name, ".h"))
+               if (!is_c_src && !strends(f->name, ".h")) {
+                       /* We don't pull in contents of non-source files */
                        dest = &m->other_files;
-               else if (!strchr(f->name, '/')) {
+                       continue;
+               }
+
+               f->contents = grab_file(f, f->name, &f->contents_size);
+               if (!f->contents)
+                       err(1, "Reading file %s", f->name);
+
+               if (!strchr(f->name, '/')) {
                        if (is_c_src)
                                dest = &m->c_files;
                        else