2 #include "get_file_lines.h"
3 #include <talloc/talloc.h>
4 #include <string/string.h>
5 #include <noerr/noerr.h>
14 char **get_ccan_file_lines(struct ccan_file *f)
17 f->lines = get_file_lines(f, f->name, &f->num_lines);
21 static void add_files(struct manifest *m, const char *dir)
31 err(1, "Opening directory %s", dir[0] ? dir : ".");
33 while ((ent = readdir(d)) != NULL) {
36 struct list_head *dest;
39 if (ent->d_name[0] == '.')
42 f = talloc(m, struct ccan_file);
44 f->name = talloc_asprintf(f, "%s%s", dir, ent->d_name);
45 if (lstat(f->name, &st) != 0)
46 err(1, "lstat %s", f->name);
48 if (S_ISDIR(st.st_mode)) {
49 f->name = talloc_append_string(f->name, "/");
50 add_files(m, f->name);
53 if (!S_ISREG(st.st_mode)) {
58 if (streq(f->name, "_info.c")) {
63 is_c_src = strends(f->name, ".c");
64 if (!is_c_src && !strends(f->name, ".h"))
65 dest = &m->other_files;
66 else if (!strchr(f->name, '/')) {
71 } else if (strstarts(f->name, "test/")) {
73 if (strstarts(f->name, "test/run"))
75 else if (strstarts(f->name, "test/compile_ok"))
76 dest = &m->compile_ok_tests;
77 else if (strstarts(f->name, "test/compile_fail"))
78 dest = &m->compile_fail_tests;
80 dest = &m->other_test_files;
82 dest = &m->other_test_files;
84 dest = &m->other_files;
86 list_add(dest, &f->list);
91 char *report_on_lines(struct list_head *files,
92 char *(*report)(const char *),
97 list_for_each(files, f, list) {
99 char **lines = get_ccan_file_lines(f);
101 for (i = 0; i < f->num_lines; i++) {
102 char *r = report(lines[i]);
106 sofar = talloc_asprintf_append(sofar,
115 struct manifest *get_manifest(void)
117 struct manifest *m = talloc(NULL, struct manifest);
121 list_head_init(&m->c_files);
122 list_head_init(&m->h_files);
123 list_head_init(&m->run_tests);
124 list_head_init(&m->compile_ok_tests);
125 list_head_init(&m->compile_fail_tests);
126 list_head_init(&m->other_test_files);
127 list_head_init(&m->other_files);
129 /* *This* is why people hate C. */
131 m->basename = talloc_array(m, char, len);
132 while (!getcwd(m->basename, len)) {
134 err(1, "Getting current directory");
135 m->basename = talloc_realloc(m, m->basename, char, len *= 2);
138 len = strlen(m->basename);
139 while (len && m->basename[len-1] == '/')
140 m->basename[--len] = '\0';
142 m->basename = strrchr(m->basename, '/');
144 errx(1, "I don't expect to be run from the root directory");