-#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;
int indent;
};
-#line 216 "../mdcode.mdc"
+#line 224 "../mdcode.mdc"
static void code_linearize(struct code_node *code)
{
struct code_node *t;
}
}
-#line 239 "../mdcode.mdc"
+#line 247 "../mdcode.mdc"
void code_free(struct code_node *code)
{
while (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)
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)
where->last = n;
}
-#line 290 "../mdcode.mdc"
+#line 299 "../mdcode.mdc"
void code_add_link(struct psection *where, struct psection *to,
int indent)
{
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)
return new;
}
-#line 410 "../mdcode.mdc"
+#line 419 "../mdcode.mdc"
static char *skip_lws(char *pos, char *end)
{
while (pos < end && (*pos == ' ' || *pos == '\t'))
return pos;
}
-#line 466 "../mdcode.mdc"
+#line 475 "../mdcode.mdc"
static struct text take_header(char *pos, char *end)
{
struct text section;
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;
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) {
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);
return pos;
}
-#line 630 "../mdcode.mdc"
+#line 641 "../mdcode.mdc"
static struct psection *code_find(char *pos, char *end)
{
struct psection *table = NULL;
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;
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"
-#line 119 "../mdcode.mdc"
+#line 120 "../mdcode.mdc"
#include <unistd.h>
#include <stdlib.h>
+#include <stdio.h>
#include "mdcode.h"
-#line 849 "../mdcode.mdc"
+#line 860 "../mdcode.mdc"
#include <fcntl.h>
#include <errno.h>
#include <sys/mman.h>
#include <string.h>
-#include <stdio.h>
-
-#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;
name[len] = 0;
}
-#line 857 "../mdcode.mdc"
+#line 867 "../mdcode.mdc"
static int errs;
static void pr_err(char *msg)
{
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"
-#line 158 "../mdcode.mdc"
+#line 96 "../mdcode.mdc"
+#include <stdio.h>
+#line 165 "../mdcode.mdc"
struct text {
char *txt;
int len;
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"