1 /* This merely extracts, doesn't do XML or anything. */
11 #include "talloc/talloc.h"
14 #define streq(a,b) (strcmp((a),(b)) == 0)
16 /* Does A start with B ? */
17 #define strstarts(a,b) (strncmp((a),(b),strlen(b)) == 0)
19 /* This version adds one byte (for nul term) */
20 static void *grab_file(void *ctx, const char *filename)
22 unsigned int max = 16384, size = 0;
26 if (streq(filename, "-"))
27 fd = dup(STDIN_FILENO);
29 fd = open(filename, O_RDONLY, 0);
34 buffer = talloc_array(ctx, char, max+1);
35 while ((ret = read(fd, buffer + size, max - size)) > 0) {
38 buffer = talloc_realloc(ctx, buffer, char, max*=2 + 1);
49 /* This is a dumb one which copies. We could mangle instead. */
50 static char **split(const char *text)
53 unsigned int max = 64, num = 0;
55 lines = talloc_array(text, char *, max+1);
57 while (*text != '\0') {
58 unsigned int len = strcspn(text, "\n");
59 lines[num] = talloc_array(lines, char, len + 1);
60 memcpy(lines[num], text, len);
61 lines[num][len] = '\0';
64 lines = talloc_realloc(text, lines, char *, max*=2 + 1);
70 int main(int argc, char *argv[])
74 for (i = 1; i < argc; i++) {
77 bool printing = false, printed = false;
79 file = grab_file(NULL, argv[i]);
81 err(1, "Reading file %s", argv[i]);
84 for (j = 0; lines[j]; j++) {
85 if (streq(lines[j], "/**")) {
89 } else if (streq(lines[j], " */"))
92 if (strstarts(lines[j], " * "))
94 else if (strstarts(lines[j], " *"))
97 errx(1, "Malformed line %s:%u",