From: NeilBrown Date: Thu, 25 Jul 2013 10:15:43 +0000 (+1000) Subject: Refresh boot-strap files. X-Git-Tag: indentparser~6 X-Git-Url: https://ocean-lang.org/code/?p=ocean;a=commitdiff_plain;h=f8480284851202f57fd148cd2cc30502340a8494 Refresh boot-strap files. There have been some changes to mdcode.mdc, so time to update the generated files in 'boot-strap' Signed-off-by: NeilBrown --- diff --git a/csrc/boot-strap/libmdcode.c b/csrc/boot-strap/libmdcode.c index 78a4262..a91bd60 100644 --- a/csrc/boot-strap/libmdcode.c +++ b/csrc/boot-strap/libmdcode.c @@ -1,15 +1,15 @@ -#line 100 "../mdcode.mdc" +#line 101 "../mdcode.mdc" #define _GNU_SOURCE #include #include #include #include "mdcode.h" -#line 461 "../mdcode.mdc" +#line 470 "../mdcode.mdc" #include #include -#line 179 "../mdcode.mdc" +#line 187 "../mdcode.mdc" struct psection { struct section; struct code_node *last; @@ -17,7 +17,7 @@ struct psection { int indent; }; -#line 216 "../mdcode.mdc" +#line 224 "../mdcode.mdc" static void code_linearize(struct code_node *code) { struct code_node *t; @@ -38,7 +38,7 @@ static void code_linearize(struct code_node *code) } } -#line 239 "../mdcode.mdc" +#line 247 "../mdcode.mdc" void code_free(struct code_node *code) { while (code) { @@ -51,9 +51,9 @@ void code_free(struct code_node *code) } } -#line 268 "../mdcode.mdc" +#line 276 "../mdcode.mdc" static void code_add_text(struct psection *where, struct text txt, - int line_no) + int line_no, int needs_strip) { struct code_node *n; if (txt.len == 0) @@ -62,6 +62,7 @@ static void code_add_text(struct psection *where, struct text txt, n->code = txt; n->indent = 0; n->line_no = line_no; + n->needs_strip = needs_strip; n->next = NULL; n->child = NULL; if (where->last) @@ -71,7 +72,7 @@ static void code_add_text(struct psection *where, struct text txt, where->last = n; } -#line 290 "../mdcode.mdc" +#line 299 "../mdcode.mdc" void code_add_link(struct psection *where, struct psection *to, int indent) { @@ -96,7 +97,7 @@ void code_add_link(struct psection *where, struct psection *to, where->last = n; } -#line 329 "../mdcode.mdc" +#line 338 "../mdcode.mdc" static int text_cmp(struct text a, struct text b) { if (a.len != b.len) @@ -127,7 +128,7 @@ static struct psection *section_find(struct psection **list, struct text name) return new; } -#line 410 "../mdcode.mdc" +#line 419 "../mdcode.mdc" static char *skip_lws(char *pos, char *end) { while (pos < end && (*pos == ' ' || *pos == '\t')) @@ -167,7 +168,7 @@ static char *skip_para(char *pos, char *end, int *line_no) return pos; } -#line 466 "../mdcode.mdc" +#line 475 "../mdcode.mdc" static struct text take_header(char *pos, char *end) { struct text section; @@ -208,7 +209,7 @@ static int matches(char *start, char *pos, char *end) strncmp(pos, start, strlen(start)) == 0); } -#line 538 "../mdcode.mdc" +#line 547 "../mdcode.mdc" static int count_space(char *sol, char *p) { int c = 0; @@ -266,7 +267,8 @@ static char *take_code(char *pos, char *end, char *marker, struct text txt; txt.txt = start; txt.len = pos - start; - code_add_text(sect, txt, start_line); + code_add_text(sect, txt, start_line, + marker == NULL); } ref = take_header(t, end); if (ref.len) { @@ -282,7 +284,8 @@ static char *take_code(char *pos, char *end, char *marker, struct text txt; txt.txt = start; txt.len = pos - start; - code_add_text(sect, txt, start_line); + code_add_text(sect, txt, start_line, + marker == NULL); } if (marker) { pos = skip_line(pos, end); @@ -292,7 +295,7 @@ static char *take_code(char *pos, char *end, char *marker, return pos; } -#line 630 "../mdcode.mdc" +#line 641 "../mdcode.mdc" static struct psection *code_find(char *pos, char *end) { struct psection *table = NULL; @@ -333,7 +336,7 @@ static struct psection *code_find(char *pos, char *end) return table; } -#line 690 "../mdcode.mdc" +#line 701 "../mdcode.mdc" struct section *code_extract(char *pos, char *end, code_err_fn error) { struct psection *table; @@ -380,5 +383,38 @@ struct section *code_extract(char *pos, char *end, code_err_fn error) return result; } -#line 109 "../mdcode.mdc" +#line 782 "../mdcode.mdc" +void code_node_print(FILE *out, struct code_node *node, + char *fname) +{ + for (; node; node = node->next) { + char *c = node->code.txt; + int len = node->code.len; + + if (!len) + continue; + + fprintf(out, "#line %d \"%s\"\n", + node->line_no, fname); + while (len && *c) { + fprintf(out, "%*s", node->indent, ""); + if (node->needs_strip) { + if (*c == '\t' && len > 1) { + c++; + len--; + } else if (strncmp(c, " ", 4) == 0 && len > 4) { + c += 4; + len-= 4; + } + } + do { + fputc(*c, out); + c++; + len--; + } while (len && c[-1] != '\n'); + } + } +} + +#line 110 "../mdcode.mdc" diff --git a/csrc/boot-strap/md2c.c b/csrc/boot-strap/md2c.c index 2b18737..71e3771 100644 --- a/csrc/boot-strap/md2c.c +++ b/csrc/boot-strap/md2c.c @@ -1,53 +1,17 @@ -#line 119 "../mdcode.mdc" +#line 120 "../mdcode.mdc" #include #include +#include #include "mdcode.h" -#line 849 "../mdcode.mdc" +#line 860 "../mdcode.mdc" #include #include #include #include -#include - -#line 771 "../mdcode.mdc" -static void code_print(FILE *out, struct code_node *node, - char *fname) -{ - for (; node; node = node->next) { - char *c = node->code.txt; - int len = node->code.len; - int undent = 0; - - if (!len) - continue; - - fprintf(out, "#line %d \"%s\"\n", - node->line_no, fname); - if (*c == ' ' || *c == '\t') - undent = 1; - while (len && *c) { - fprintf(out, "%*s", node->indent, ""); - if (undent) { - if (*c == '\t' && len > 1) { - c++; - len--; - } else if (strncmp(c, " ", 4) == 0 && len > 4) { - c += 4; - len-= 4; - } - } - do { - fputc(*c, out); - c++; - len--; - } while (len && c[-1] != '\n'); - } - } -} -#line 821 "../mdcode.mdc" +#line 832 "../mdcode.mdc" static void copy_fname(char *name, int space, struct text t) { char *sec = t.txt; @@ -67,7 +31,7 @@ static void copy_fname(char *name, int space, struct text t) name[len] = 0; } -#line 857 "../mdcode.mdc" +#line 867 "../mdcode.mdc" static int errs; static void pr_err(char *msg) { @@ -123,11 +87,11 @@ int main(int argc, char *argv[]) errs++; continue; } - code_print(fl, s->code, argv[1]); + code_node_print(fl, s->code, argv[1]); fclose(fl); } exit(!!errs); } -#line 126 "../mdcode.mdc" +#line 128 "../mdcode.mdc" diff --git a/csrc/boot-strap/mdcode.h b/csrc/boot-strap/mdcode.h index 6a17e44..4ab95dc 100644 --- a/csrc/boot-strap/mdcode.h +++ b/csrc/boot-strap/mdcode.h @@ -1,4 +1,6 @@ -#line 158 "../mdcode.mdc" +#line 96 "../mdcode.mdc" +#include +#line 165 "../mdcode.mdc" struct text { char *txt; int len; @@ -14,19 +16,23 @@ struct code_node { struct text code; int indent; int line_no; + int needs_strip; struct code_node *next; struct section *child; }; -#line 687 "../mdcode.mdc" +#line 698 "../mdcode.mdc" typedef void (*code_err_fn)(char *msg); -#line 253 "../mdcode.mdc" +#line 261 "../mdcode.mdc" void code_free(struct code_node *code); -#line 738 "../mdcode.mdc" +#line 749 "../mdcode.mdc" struct section *code_extract(char *pos, char *end, code_err_fn error); -#line 98 "../mdcode.mdc" +#line 815 "../mdcode.mdc" +void code_node_print(FILE *out, struct code_node *node, char *fname); + +#line 99 "../mdcode.mdc" diff --git a/csrc/boot-strap/mdcode.mk b/csrc/boot-strap/mdcode.mk index 22a35a1..5cf9365 100644 --- a/csrc/boot-strap/mdcode.mk +++ b/csrc/boot-strap/mdcode.mk @@ -5,19 +5,19 @@ mdcode.h libmdcode.c md2c.c mdcode.mk : mdcode.mdc ./md2c mdcode.mdc -#line 112 "../mdcode.mdc" +#line 113 "../mdcode.mdc" all :: libmdcode.o libmdcode.o : libmdcode.c mdcode.h $(CC) $(CFLAGS) -c libmdcode.c -#line 129 "../mdcode.mdc" +#line 131 "../mdcode.mdc" all :: md2c md2c : md2c.o libmdcode.o $(CC) $(CFLAGS) -o md2c md2c.o libmdcode.o md2c.o : md2c.c mdcode.h $(CC) $(CFLAGS) -c md2c.c -#line 192 "../mdcode.mdc" +#line 200 "../mdcode.mdc" CFLAGS += -fplan9-extensions