-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdbool.h>
-#include "talloc/talloc.h"
-#include "string/string.h"
-
-static char **grab_doc(const char *fname)
-{
- char *file;
- char **lines, **ret;
- unsigned int i, num;
- bool printing = false, printed = false;
-
- file = grab_file(NULL, fname, NULL);
- if (!file)
- err(1, "Reading file %s", fname);
- lines = strsplit(file, file, "\n", &num);
- ret = talloc_array(NULL, char *, num+1);
-
- num = 0;
- for (i = 0; lines[i]; i++) {
- if (streq(lines[i], "/**")) {
- printing = true;
- if (printed++)
- talloc_append_string(ret[num], "\n");
- } else if (streq(lines[i], " */"))
- printing = false;
- else if (printing) {
- if (strstarts(lines[i], " * "))
- ret[num++] = talloc_strdup(ret, lines[i]+3);
- else if (strstarts(lines[i], " *"))
- ret[num++] = talloc_strdup(ret, lines[i]+2);
- else
- errx(1, "Malformed line %s:%u", fname, i);
- }
- }
- ret[num] = NULL;
- talloc_free(file);
- return ret;
-}
-
-static bool is_blank(const char *line)
-{
- return line && line[strspn(line, " \t\n")] == '\0';
-}
-
-static bool is_section(const char *line)
-{
- unsigned int len;
-
- len = strcspn(line, " \t\n:");
- if (len == 0)
- return false;
-
- return line[len] == ':' && is_blank(line+len+1);
-}
-
-
-static bool end_section(const char *line)
-{
- return !line || is_section(line);
-}
-
-static unsigned int find_section(char **lines, const char *name)
-{
- unsigned int i;
-
- for (i = 0; lines[i]; i++) {
- if (!is_section(lines[i]))
- continue;
- if (strncasecmp(lines[i], name, strlen(name)) != 0)
- continue;
- if (lines[i][strlen(name)] == ':')
- break;
- }
- return i;
-}