- if (function) {
- /* Allow us to trawl multiple files for a function */
- line = find_summary(lines, function);
- if (!lines[line])
- continue;
-
- /* Trim to just this function then. */
- lines += line;
- lines[find_summary(lines+1, NULL)] = NULL;
- }
- /* Simple one-line fields. */
- if (streq(type, "author")
- || streq(type, "maintainer")
- || streq(type, "licence")) {
- line = find_section(lines, type, true);
- if (lines[line]) {
- const char *p = strchr(lines[line], ':') + 1;
- p += strspn(p, " \t\n");
- if (p[0] == '\0') {
- /* Must be on next line. */
- if (end_section(lines[line+1]))
- errx(1, "Malformed %s", type);
- puts(lines[line+1]);
- } else
- puts(p);
- }
- } else if (streq(type, "summary")) {
- /* Summary comes after - on first line. */
- char *dash;
-
- dash = strchr(lines[0], '-');
- if (!dash)
- errx(1, "Malformed first line: no -");
- dash += strspn(dash, "- ");
- puts(dash);
- } else if (streq(type, "description")) {
- line = 1;
- while (is_blank(lines[line]))
- line++;
-
- while (!end_section(lines[line]))
- puts(lines[line++]);
- } else if (streq(type, "example")) {
- line = find_section(lines, type, false);
- if (lines[line]) {
- unsigned int strip;
- line++;
-
- while (is_blank(lines[line]))
- line++;
-
- /* Examples can be indented. Take cue
- * from first non-blank line. */
- if (lines[line])
- strip = strspn(lines[line], " \t");
-
- while (!end_section(lines[line])) {
- if (strspn(lines[line], " \t") >= strip)
- puts(lines[line] + strip);
- else
- puts(lines[line]);
- line++;
+ 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;