From: Rusty Russell Date: Thu, 28 May 2009 03:49:33 +0000 (+0930) Subject: Store pristine contents of files: based on Joey's patch. X-Git-Url: http://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=503dbd5986e381f8d56b3e7ce0ee00b839a42aa6 Store pristine contents of files: based on Joey's patch. --- diff --git a/tools/ccanlint/ccanlint.h b/tools/ccanlint/ccanlint.h index 16a410a9..d704d58d 100644 --- a/tools/ccanlint/ccanlint.h +++ b/tools/ccanlint/ccanlint.h @@ -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; diff --git a/tools/ccanlint/file_analysis.c b/tools/ccanlint/file_analysis.c index dc23eb96..62e4a13a 100644 --- a/tools/ccanlint/file_analysis.c +++ b/tools/ccanlint/file_analysis.c @@ -17,12 +17,9 @@ 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