1 /* This merely extracts, doesn't do XML or anything. */
2 #include <ccan/str/str.h>
3 #include <ccan/err/err.h>
7 #include "doc_extract.h"
9 /* We regard non-alphanumerics as equiv. */
10 static bool typematch(const char *a, const char *b)
14 for (i = 0; a[i]; i++) {
26 int main(int argc, char *argv[])
30 const char *function = NULL;
33 errx(1, "Usage: doc_extract [--function=<funcname>] TYPE <file>...\n"
34 "Where TYPE is functions|author|license|maintainer|summary|description|example|see_also|all");
36 if (strstarts(argv[1], "--function=")) {
37 function = argv[1] + strlen("--function=");
43 for (i = 2; i < argc; i++) {
45 struct list_head *list;
46 struct doc_section *d;
48 file = tal_grab_file(NULL, argv[i], NULL);
50 err(1, "Reading file %s", argv[i]);
51 lines = tal_strsplit(file, file, "\n", STR_EMPTY_OK);
53 list = extract_doc_sections(lines, argv[i]);
55 errx(1, "No documentation in file %s", argv[i]);
58 if (streq(type, "functions")) {
59 const char *last = NULL;
60 list_for_each(list, d, list) {
62 if (!last || !streq(d->function, last))
63 printf("%s\n", d->function);
69 list_for_each(list, d, list) {
73 if (!streq(d->function, function))
76 if (streq(type, "all"))
77 printf("%s:\n", d->type);
78 else if (!typematch(d->type, type))
81 for (j = 0; j < d->num_lines; j++)
82 printf("%s\n", d->lines[j]);