1 /* This merely extracts, doesn't do XML or anything. */
5 #include <ccan/str/str.h>
6 #include <ccan/str_talloc/str_talloc.h>
7 #include <ccan/talloc/talloc.h>
8 #include <ccan/grab_file/grab_file.h>
9 #include "doc_extract.h"
11 int main(int argc, char *argv[])
15 const char *function = NULL;
18 errx(1, "Usage: doc_extract [--function=<funcname>] TYPE <file>...\n"
19 "Where TYPE is functions|author|license|maintainer|summary|description|example|all");
21 if (strstarts(argv[1], "--function=")) {
22 function = argv[1] + strlen("--function=");
28 for (i = 2; i < argc; i++) {
30 struct list_head *list;
31 struct doc_section *d;
33 file = grab_file(NULL, argv[i], NULL);
35 err(1, "Reading file %s", argv[i]);
36 lines = strsplit(file, file, "\n");
38 list = extract_doc_sections(lines);
40 errx(1, "No documentation in file %s", argv[i]);
43 if (streq(type, "functions")) {
44 const char *last = NULL;
45 list_for_each(list, d, list) {
47 if (!last || !streq(d->function, last))
48 printf("%s\n", d->function);
54 list_for_each(list, d, list) {
58 if (!streq(d->function, function))
61 if (streq(type, "all"))
62 printf("%s:\n", d->type);
63 else if (!streq(d->type, type))
66 for (j = 0; j < d->num_lines; j++)
67 printf("%s\n", d->lines[j]);