]> ocean-lang.org Git - ocean/commitdiff
Record in a code_node whether it was indented or not.
authorNeilBrown <neilb@suse.de>
Sat, 22 Jun 2013 07:39:23 +0000 (17:39 +1000)
committerNeilBrown <neilb@suse.de>
Sat, 22 Jun 2013 07:39:23 +0000 (17:39 +1000)
This is needed to correctly adjust for this indent when processing the
code.

Signed-off-by: NeilBrown <neilb@suse.de>
csrc/mdcode.mdc

index dc78a12c1d3ec62fc1d96da351e97cbec2f25cbd..1b5d48f4b34248717593635162b75be7151a2cb6 100644 (file)
@@ -153,6 +153,11 @@ The `code_node` will also have an `indent` depth which eventually gets
 set to the sum for the indents from all references on the path from
 the root.
 
 set to the sum for the indents from all references on the path from
 the root.
 
+Finally we need to know if the `code_node` was recognised by being
+indented or not.  If it was, the client of this data will want to
+strip of the leading tab or 4 spaces.  Hence a `needs_strip` flag is
+needed.
+
 ##### exported types
 
        struct text {
 ##### exported types
 
        struct text {
@@ -170,6 +175,7 @@ the root.
                struct text code;
                int indent;
                int line_no;
                struct text code;
                int indent;
                int line_no;
+               int needs_strip;
                struct code_node *next;
                struct section *child;
        };
                struct code_node *next;
                struct section *child;
        };
@@ -266,7 +272,7 @@ in a new node.
 ##### internal functions
 
        static void code_add_text(struct psection *where, struct text txt,
 ##### internal functions
 
        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)
        {
                struct code_node *n;
                if (txt.len == 0)
@@ -275,6 +281,7 @@ in a new node.
                n->code = txt;
                n->indent = 0;
                n->line_no = line_no;
                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)
                n->next = NULL;
                n->child = NULL;
                if (where->last)
@@ -592,7 +599,8 @@ for that.
                                struct text txt;
                                txt.txt = start;
                                txt.len = pos - start;
                                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) {
                        }
                        ref = take_header(t, end);
                        if (ref.len) {
@@ -608,7 +616,8 @@ for that.
                        struct text txt;
                        txt.txt = start;
                        txt.len = pos - start;
                        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);
                }
                if (marker) {
                        pos = skip_line(pos, end);
@@ -774,18 +783,15 @@ for `Makefiles`.
                for (; node; node = node->next) {
                        char *c = node->code.txt;
                        int len = node->code.len;
                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 (!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, "");
                        while (len && *c) {
                                fprintf(out, "%*s", node->indent, "");
-                               if (undent) {
+                               if (node->needs_strip) {
                                        if (*c == '\t' && len > 1) {
                                                c++;
                                                len--;
                                        if (*c == '\t' && len > 1) {
                                                c++;
                                                len--;