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|licence|maintainer|summary|description|example|all");
21 if (strstarts(argv[1], "--function=")) {
22 function = argv[1] + strlen("--function=");
28 for (i = 2; i < argc; i++) {
31 struct list_head *list;
32 struct doc_section *d;
34 file = grab_file(NULL, argv[i], NULL);
36 err(1, "Reading file %s", argv[i]);
37 lines = strsplit(file, file, "\n", &num);
39 list = extract_doc_sections(lines, num);
41 errx(1, "No documentation in file %s", argv[i]);
44 if (streq(type, "functions")) {
45 const char *last = NULL;
46 list_for_each(list, d, list) {
48 if (!last || !streq(d->function, last))
49 printf("%s\n", d->function);
55 list_for_each(list, d, list) {
59 if (!streq(d->function, function))
62 if (streq(type, "all"))
63 printf("%s:\n", d->type);
64 else if (!streq(d->type, type))
67 for (j = 0; j < d->num_lines; j++)
68 printf("%s\n", d->lines[j]);