diff options
-rw-r--r-- | mandoc.h | 24 | ||||
-rw-r--r-- | tbl_data.c | 18 | ||||
-rw-r--r-- | tree.c | 58 |
3 files changed, 69 insertions, 31 deletions
@@ -181,6 +181,14 @@ struct tbl_row { struct tbl_cell *last; }; +enum tbl_datt { + TBL_DATA_DATA, + TBL_DATA_HORIZ, + TBL_DATA_DHORIZ, + TBL_DATA_NHORIZ, + TBL_DATA_NDHORIZ +}; + /* * A cell within a row of data. The "string" field contains the actual * string value that's in the cell. The rest is layout. @@ -189,11 +197,13 @@ struct tbl_dat { struct tbl_cell *layout; /* layout cell: CAN BE NULL */ struct tbl_dat *next; char *string; - int flags; -#define TBL_DATA_HORIZ (1 << 0) -#define TBL_DATA_DHORIZ (1 << 1) -#define TBL_DATA_NHORIZ (1 << 2) -#define TBL_DATA_NDHORIZ (1 << 3) + enum tbl_datt pos; +}; + +enum tbl_spant { + TBL_SPAN_DATA, /* span consists of data */ + TBL_SPAN_HORIZ, /* span is horizontal line */ + TBL_SPAN_DHORIZ /* span is double horizontal line */ }; /* @@ -203,9 +213,7 @@ struct tbl_span { struct tbl_row *layout; /* layout row: CAN BE NULL */ struct tbl_dat *first; struct tbl_dat *last; - int flags; -#define TBL_SPAN_HORIZ (1 << 0) -#define TBL_SPAN_DHORIZ (1 << 1) + enum tbl_spant pos; struct tbl_span *next; }; @@ -68,16 +68,16 @@ data(struct tbl *tbl, struct tbl_span *dp, if (p[*pos]) (*pos)++; - /* XXX: do the strcmps, then malloc(). */ - if ( ! strcmp(dat->string, "_")) - dat->flags |= TBL_DATA_HORIZ; + dat->pos = TBL_DATA_HORIZ; else if ( ! strcmp(dat->string, "=")) - dat->flags |= TBL_DATA_DHORIZ; + dat->pos = TBL_DATA_DHORIZ; else if ( ! strcmp(dat->string, "\\_")) - dat->flags |= TBL_DATA_NHORIZ; + dat->pos = TBL_DATA_NHORIZ; else if ( ! strcmp(dat->string, "\\=")) - dat->flags |= TBL_DATA_NDHORIZ; + dat->pos = TBL_DATA_NDHORIZ; + else + dat->pos = TBL_DATA_DATA; } int @@ -119,13 +119,15 @@ tbl_data(struct tbl *tbl, int ln, const char *p) tbl->last_span = tbl->first_span = dp; if ( ! strcmp(p, "_")) { - dp->flags |= TBL_SPAN_HORIZ; + dp->pos = TBL_SPAN_HORIZ; return(1); } else if ( ! strcmp(p, "=")) { - dp->flags |= TBL_SPAN_DHORIZ; + dp->pos = TBL_SPAN_DHORIZ; return(1); } + dp->pos = TBL_SPAN_DATA; + while ('\0' != p[pos]) data(tbl, dp, ln, p, &pos); @@ -30,6 +30,7 @@ static void print_mdoc(const struct mdoc_node *, int); static void print_man(const struct man_node *, int); +static void print_span(const struct tbl_span *); /* ARGSUSED */ @@ -58,7 +59,6 @@ print_mdoc(const struct mdoc_node *n, int indent) size_t argc, sz; char **params; struct mdoc_argv *argv; - const struct tbl_dat *dp; argv = NULL; argc = sz = 0; @@ -141,12 +141,7 @@ print_mdoc(const struct mdoc_node *n, int indent) if (n->span) { assert(NULL == p); - printf("tbl: "); - for (dp = n->span->first; dp; dp = dp->next) { - printf("[%s]", dp->string); - if (dp->next) - putchar(' '); - } + print_span(n->span); } else { printf("%s (%s)", p, t); @@ -180,7 +175,6 @@ print_man(const struct man_node *n, int indent) { const char *p, *t; int i; - const struct tbl_dat *dp; switch (n->type) { case (MAN_ROOT): @@ -239,13 +233,8 @@ print_man(const struct man_node *n, int indent) if (n->span) { assert(NULL == p); - printf("tbl: "); - for (dp = n->span->first; dp; dp = dp->next) { - printf("[%s]", dp->string); - if (dp->next) - putchar(' '); - } - } else + print_span(n->span); + } else printf("%s (%s) %d:%d", p, t, n->line, n->pos); putchar('\n'); @@ -255,3 +244,42 @@ print_man(const struct man_node *n, int indent) if (n->next) print_man(n->next, indent); } + +static void +print_span(const struct tbl_span *sp) +{ + const struct tbl_dat *dp; + + printf("tbl: "); + + switch (sp->pos) { + case (TBL_SPAN_HORIZ): + putchar('-'); + return; + case (TBL_SPAN_DHORIZ): + putchar('='); + return; + default: + break; + } + + for (dp = sp->first; dp; dp = dp->next) { + switch (dp->pos) { + case (TBL_DATA_HORIZ): + /* FALLTHROUGH */ + case (TBL_DATA_NHORIZ): + putchar('-'); + continue; + case (TBL_DATA_DHORIZ): + /* FALLTHROUGH */ + case (TBL_DATA_NDHORIZ): + putchar('='); + continue; + default: + break; + } + printf("[%s]", dp->string); + if (dp->next) + putchar(' '); + } +} |