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 /* We regard non-alphanumerics as equiv. */
12 static bool typematch(const char *a, const char *b)
16 for (i = 0; a[i]; i++) {
28 int main(int argc, char *argv[])
32 const char *function = NULL;
35 errx(1, "Usage: doc_extract [--function=<funcname>] TYPE <file>...\n"
36 "Where TYPE is functions|author|license|maintainer|summary|description|example|see_also|all");
38 if (strstarts(argv[1], "--function=")) {
39 function = argv[1] + strlen("--function=");
45 for (i = 2; i < argc; i++) {
47 struct list_head *list;
48 struct doc_section *d;
50 file = grab_file(NULL, argv[i], NULL);
52 err(1, "Reading file %s", argv[i]);
53 lines = strsplit(file, file, "\n");
55 list = extract_doc_sections(lines);
57 errx(1, "No documentation in file %s", argv[i]);
60 if (streq(type, "functions")) {
61 const char *last = NULL;
62 list_for_each(list, d, list) {
64 if (!last || !streq(d->function, last))
65 printf("%s\n", d->function);
71 list_for_each(list, d, list) {
75 if (!streq(d->function, function))
78 if (streq(type, "all"))
79 printf("%s:\n", d->type);
80 else if (!typematch(d->type, type))
83 for (j = 0; j < d->num_lines; j++)
84 printf("%s\n", d->lines[j]);