1 /* List files in a module, or modules. */
2 #include <ccan/opt/opt.h>
3 #include <ccan/foreach/foreach.h>
4 #include <ccan/tal/str/str.h>
8 static void add_file(const struct ccan_file *f,
9 bool fullpath, bool nul_term, bool gitonly)
11 /* Hacky way of seeing if git knows about this. */
13 char *cmd = tal_fmt(f, "git status --porcelain --ignored %s | grep -q '^ *[!?]'", f->fullname);
17 printf("%s%c", fullpath ? f->fullname : f->name,
18 nul_term ? '\0' : '\n');
21 int main(int argc, char *argv[])
29 bool nul_term = false;
30 bool fullpath = false;
33 opt_register_noarg("--no-code", opt_set_invbool, &code,
34 "Don't list .c and .h files");
35 opt_register_noarg("--no-license", opt_set_invbool, &license,
36 "Don't list license file");
37 opt_register_noarg("--no-info", opt_set_invbool, &info,
38 "Don't list _info file");
39 opt_register_noarg("--no-tests", opt_set_invbool, &tests,
40 "Don't list test files");
41 opt_register_noarg("--no-other", opt_set_invbool, &other,
42 "Don't list other files");
43 opt_register_noarg("--git-only", opt_set_bool, &gitonly,
44 "Only include files in git");
45 opt_register_noarg("--fullpath", opt_set_bool, &fullpath,
46 "Print full path names instead of module-relative ones");
47 opt_register_noarg("--null|-0", opt_set_bool, &nul_term,
48 "Separate files with nul character instead of \\n");
49 opt_register_noarg("-h|--help", opt_usage_and_exit,
53 opt_parse(&argc, argv, opt_log_stderr_exit);
55 opt_usage_exit_fail("Expected one or more module directories");
57 for (i = 1; i < argc; i++) {
58 struct manifest *m = get_manifest(NULL, argv[i]);
59 struct list_head *list;
63 add_file(m->info_file, fullpath, nul_term, gitonly);
66 foreach_ptr(list, &m->c_files, &m->h_files) {
67 list_for_each(list, f, list)
68 add_file(f, fullpath, nul_term, gitonly);
72 list_for_each(&m->other_files, f, list) {
73 if (streq(f->name, "LICENSE"))
74 add_file(f, fullpath, nul_term, gitonly);
78 foreach_ptr(list, &m->run_tests, &m->api_tests,
79 &m->compile_ok_tests, &m->compile_fail_tests,
80 &m->other_test_c_files,
81 &m->other_test_files) {
82 list_for_each(list, f, list)
83 add_file(f, fullpath, nul_term, gitonly);
87 list_for_each(&m->other_files, f, list) {
88 if (!streq(f->name, "LICENSE"))
89 add_file(f, fullpath, nul_term, gitonly);