1 #line 120 "../mdcode.mdc"
8 #line 860 "../mdcode.mdc"
14 #line 832 "../mdcode.mdc"
15 static void copy_fname(char *name, int space, struct text t)
20 if (len < 5 || strncmp(sec, "File:", 5) != 0)
24 while (len && sec[0] == ' ') {
30 strncpy(name, sec, len);
34 #line 867 "../mdcode.mdc"
36 static void pr_err(char *msg)
39 fprintf(stderr, "%s\n", msg);
42 int main(int argc, char *argv[])
47 struct section *table, *s, *prev;
51 fprintf(stderr, "Usage: mdcode file.mdc\n");
54 fd = open(argv[1], O_RDONLY);
56 fprintf(stderr, "mdcode: cannot open %s: %s\n",
57 argv[1], strerror(errno));
60 len = lseek(fd, 0, 2);
61 file = mmap(NULL, len, PROT_READ, MAP_SHARED, fd, 0);
62 table = code_extract(file, file+len, pr_err);
65 (code_free(s->code), prev = s, s = s->next, free(prev))) {
68 if (strncmp(s->section.txt, "Example:", 8) == 0)
70 if (strncmp(s->section.txt, "File:", 5) != 0) {
71 fprintf(stderr, "Unreferenced section is not a file name: %.*s\n",
72 s->section.len, s->section.txt);
76 copy_fname(fname, sizeof(fname), s->section);
78 fprintf(stderr, "Missing file name at:%.*s\n",
79 s->section.len, s->section.txt);
83 fl = fopen(fname, "w");
85 fprintf(stderr, "Cannot create %s: %s\n",
86 fname, strerror(errno));
90 code_node_print(fl, s->code, argv[1]);
96 #line 128 "../mdcode.mdc"