- lines = strsplit(file, file, "\n", NULL);
-
- for (j = 0; lines[j]; j++) {
- if (streq(lines[j], "/**")) {
- printing = true;
- if (printed++)
- puts("\n");
- } else if (streq(lines[j], " */"))
- printing = false;
- else if (printing) {
- if (strstarts(lines[j], " * "))
- puts(lines[j] + 3);
- else if (strstarts(lines[j], " *"))
- puts(lines[j] + 2);
- else
- errx(1, "Malformed line %s:%u",
- argv[i], j);
+ lines = strsplit(file, file, "\n");
+
+ list = extract_doc_sections(lines);
+ if (list_empty(list))
+ errx(1, "No documentation in file %s", argv[i]);
+ talloc_free(file);
+
+ if (streq(type, "functions")) {
+ const char *last = NULL;
+ list_for_each(list, d, list) {
+ if (d->function) {
+ if (!last || !streq(d->function, last))
+ printf("%s\n", d->function);
+ last = d->function;
+ }
+ }
+ } else {
+ unsigned int j;
+ list_for_each(list, d, list) {
+ if (function) {
+ if (!d->function)
+ continue;
+ if (!streq(d->function, function))
+ continue;
+ }
+ if (streq(type, "all"))
+ printf("%s:\n", d->type);
+ else if (!streq(d->type, type))
+ continue;
+
+ for (j = 0; j < d->num_lines; j++)
+ printf("%s\n", d->lines[j]);