char *fullname;
/* Pristine version of the original file.
- * Use get_ccan_file_lines to fill this. */
+ * Use get_ccan_file_contents to fill this. */
const char *contents;
size_t contents_size;
/* A new ccan_file, with the given name (talloc_steal onto returned value). */
struct ccan_file *new_ccan_file(const void *ctx, const char *dir, char *name);
+/* Use this rather than accessing f->contents directly: loads on demand. */
+const char *get_ccan_file_contents(struct ccan_file *f);
+
/* Use this rather than accessing f->lines directly: loads on demand. */
char **get_ccan_file_lines(struct ccan_file *f);
const char *ccan_dir;
+const char *get_ccan_file_contents(struct ccan_file *f)
+{
+ if (!f->contents) {
+ f->contents = grab_file(f, f->fullname, &f->contents_size);
+ if (!f->contents)
+ err(1, "Reading file %s", f->fullname);
+ }
+ return f->contents;
+}
+
char **get_ccan_file_lines(struct ccan_file *f)
{
if (!f->lines)
- f->lines = strsplit(f, f->contents, "\n", &f->num_lines);
+ f->lines = strsplit(f, get_ccan_file_contents(f),
+ "\n", &f->num_lines);
return f->lines;
}
f->compiled = NULL;
f->name = talloc_steal(f, name);
f->fullname = talloc_asprintf(f, "%s/%s", dir, f->name);
+ f->contents = NULL;
+ f->cov_compiled = NULL;
return f;
}
if (streq(f->name, "_info")) {
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")) {
- /* We don't pull in contents of non-source files */
dest = &m->other_files;
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;
struct ccan_file *f;
name = maybe_temp_file(m, ".c", keep,
- talloc_asprintf(m, "%s/example-%s-%s",
+ talloc_asprintf(m, "%s/example-%s-%s.c",
talloc_dirname(m,
source->fullname),
source->name,
list_for_each(get_ccan_file_docs(m->info_file), d, list) {
if (streq(d->type, "example")) {
- score->error = add_example(m, m->info_file, keep, d);;
+ score->error = add_example(m, m->info_file, keep, d);
if (score->error)
return score;
score->info_example = true;