Browse Source

Store pristine contents of files: based on Joey's patch.

Rusty Russell 16 years ago
parent
commit
503dbd5986
2 changed files with 21 additions and 8 deletions
  1. 5 0
      tools/ccanlint/ccanlint.h
  2. 16 8
      tools/ccanlint/file_analysis.c

+ 5 - 0
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;

+ 16 - 8
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