]> ocean-lang.org Git - ocean/blobdiff - csrc/boot-strap/libmdcode.c
Refresh boot-strap files.
[ocean] / csrc / boot-strap / libmdcode.c
index 78a4262d8d9873a9e8cf9493bbf1850c4cab9c43..a91bd60f2817efc55c2c1645ec636d4dc667d9ee 100644 (file)
@@ -1,15 +1,15 @@
-#line 100 "../mdcode.mdc"
+#line 101 "../mdcode.mdc"
 #define _GNU_SOURCE
 #include <unistd.h>
 #include <stdlib.h>
 #include <stdio.h>
 
 #include "mdcode.h"
-#line 461 "../mdcode.mdc"
+#line 470 "../mdcode.mdc"
 #include  <ctype.h>
 #include  <string.h>
 
-#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"