From dbd5746117cfc008d44b2e9e53c8f76c8d92673d Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Sat, 1 Jan 2011 17:10:20 +0000 Subject: Make some bit-flags into enums as they should be. Make printing of -Ttree tables a little bit smarter. --- mandoc.h | 26 +++++++++++++++++--------- tbl_data.c | 20 +++++++++++--------- tree.c | 60 ++++++++++++++++++++++++++++++++++++++++++++---------------- 3 files changed, 72 insertions(+), 34 deletions(-) diff --git a/mandoc.h b/mandoc.h index 1d8913ab..094241f1 100644 --- a/mandoc.h +++ b/mandoc.h @@ -1,4 +1,4 @@ -/* $Id: mandoc.h,v 1.39 2011/01/01 15:45:18 kristaps Exp $ */ +/* $Id: mandoc.h,v 1.40 2011/01/01 17:10:20 kristaps Exp $ */ /* * Copyright (c) 2010 Kristaps Dzonsons * @@ -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; }; diff --git a/tbl_data.c b/tbl_data.c index b04d8046..b4810767 100644 --- a/tbl_data.c +++ b/tbl_data.c @@ -1,4 +1,4 @@ -/* $Id: tbl_data.c,v 1.4 2011/01/01 13:37:40 kristaps Exp $ */ +/* $Id: tbl_data.c,v 1.5 2011/01/01 17:10:20 kristaps Exp $ */ /* * Copyright (c) 2009, 2010 Kristaps Dzonsons * @@ -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); diff --git a/tree.c b/tree.c index 17d56843..d56eeaf6 100644 --- a/tree.c +++ b/tree.c @@ -1,4 +1,4 @@ -/* $Id: tree.c,v 1.27 2011/01/01 14:09:21 kristaps Exp $ */ +/* $Id: tree.c,v 1.28 2011/01/01 17:10:20 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -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(' '); + } +} -- cgit v1.2.3-56-ge451