Non-compiling version of ccan_depends by default.
[ccan] / tools / doc_extract.c
1 /* This merely extracts, doesn't do XML or anything. */
2 #include <err.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <string.h>
7 #include <sys/types.h>
8 #include <sys/stat.h>
9 #include <fcntl.h>
10 #include <stdbool.h>
11 #include "talloc/talloc.h"
12 #include "string/string.h"
13
14
15 int main(int argc, char *argv[])
16 {
17         unsigned int i, j;
18
19         for (i = 1; i < argc; i++) {
20                 char *file;
21                 char **lines;
22                 bool printing = false, printed = false;
23
24                 file = grab_file(NULL, argv[i]);
25                 if (!file)
26                         err(1, "Reading file %s", argv[i]);
27                 lines = strsplit(file, file, "\n", NULL);
28
29                 for (j = 0; lines[j]; j++) {
30                         if (streq(lines[j], "/**")) {
31                                 printing = true;
32                                 if (printed++)
33                                         puts("\n");
34                         } else if (streq(lines[j], " */"))
35                                 printing = false;
36                         else if (printing) {
37                                 if (strstarts(lines[j], " * "))
38                                         puts(lines[j] + 3);
39                                 else if (strstarts(lines[j], " *"))
40                                         puts(lines[j] + 2);
41                                 else
42                                         errx(1, "Malformed line %s:%u",
43                                              argv[i], j);
44                         }
45                 }
46                 talloc_free(file);
47         }
48         return 0;
49 }
50
51                 
52