1 /* This merely extracts, doesn't do XML or anything. */
2 #include <ccan/str/str.h>
3 #include <ccan/err/err.h>
4 #include <ccan/tal/grab_file/grab_file.h>
8 #include "doc_extract.h"
10 /* We regard non-alphanumerics as equiv. */
11 static bool typematch(const char *a, const char *b)
15 for (i = 0; a[i]; i++) {
27 int main(int argc, char *argv[])
31 const char *function = NULL;
34 errx(1, "Usage: doc_extract [--function=<funcname>] TYPE <file>...\n"
35 "Where TYPE is functions|author|license|maintainer|summary|description|example|see_also|all");
37 if (strstarts(argv[1], "--function=")) {
38 function = argv[1] + strlen("--function=");
44 for (i = 2; i < argc; i++) {
46 struct list_head *list;
47 struct doc_section *d;
49 file = grab_file(NULL, argv[i]);
51 err(1, "Reading file %s", argv[i]);
52 lines = tal_strsplit(file, file, "\n", STR_EMPTY_OK);
54 list = extract_doc_sections(lines, argv[i]);
56 errx(1, "No documentation in file %s", argv[i]);
59 if (streq(type, "functions")) {
60 const char *last = NULL;
61 list_for_each(list, d, list) {
63 if (!last || !streq(d->function, last))
64 printf("%s\n", d->function);
70 list_for_each(list, d, list) {
74 if (!streq(d->function, function))
77 if (streq(type, "all"))
78 printf("%s:\n", d->type);
79 else if (!typematch(d->type, type))
82 for (j = 0; j < d->num_lines; j++)
83 printf("%s\n", d->lines[j]);