1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/doc_extract.h>
3 #include <tools/tools.h>
13 #include <ccan/str/str.h>
14 #include <ccan/talloc/talloc.h>
15 #include <ccan/noerr/noerr.h>
16 #include <ccan/grab_file/grab_file.h>
18 static void create_info_template_doc(struct manifest *m, struct score *score)
20 int fd = open("_info.new", O_WRONLY|O_CREAT|O_EXCL, 0666);
24 if (fd < 0 || !(new = fdopen(fd, "w")))
25 err(1, "Creating _info.new to insert documentation");
29 " * %s - [[ONE LINE DESCRIPTION HERE]]\n"
31 " * Paragraphs why %s exists and where to use it.\n"
33 " * Followed by an Example: section with a standalone\n"
34 " * (trivial and usually useless) program\n"
35 " */\n", m->basename, m->basename) < 0) {
36 unlink_noerr("_info.new");
37 err(1, "Writing to _info.new to insert documentation");
40 oldcontents = grab_file(m, "_info", NULL);
42 unlink_noerr("_info.new");
43 err(1, "Reading _info");
45 if (fprintf(new, "%s", oldcontents) < 0) {
46 unlink_noerr("_info.new");
47 err(1, "Appending _info to _info.new");
49 if (fclose(new) != 0) {
50 unlink_noerr("_info.new");
51 err(1, "Closing _info.new");
53 if (!move_file("_info.new", "_info")) {
54 unlink_noerr("_info.new");
55 err(1, "Renaming _info.new to _info");
59 static void check_has_info_documentation(struct manifest *m,
61 unsigned int *timeleft,
64 struct list_head *infodocs = get_ccan_file_docs(m->info_file);
65 struct doc_section *d;
66 bool summary = false, description = false;
68 list_for_each(infodocs, d, list) {
69 if (!streq(d->function, m->basename))
71 if (streq(d->type, "summary"))
73 if (streq(d->type, "description"))
77 if (summary && description) {
78 score->score = score->total;
80 } else if (!summary) {
81 score->error = "_info file has no module documentation.\n\n"
82 "CCAN modules use /**-style comments for documentation: the\n"
83 "overall documentation belongs in the _info metafile.\n";
84 has_info_documentation.handle = create_info_template_doc;
85 } else if (!description) {
86 score->error = "_info file has no module description.\n\n"
87 "The lines after the first summary line in the _info file\n"
88 "documentation should describe the purpose and use of the\n"
93 struct ccanlint has_info_documentation = {
94 .key = "info-documentation",
95 .name = "Module has documentation in _info",
96 .check = check_has_info_documentation,
99 REGISTER_TEST(has_info_documentation, NULL);