=================================================================== RCS file: /cvs/mandoc/mdoc_term.c,v retrieving revision 1.150 retrieving revision 1.155 diff -u -p -r1.150 -r1.155 --- mandoc/mdoc_term.c 2010/06/12 12:10:55 1.150 +++ mandoc/mdoc_term.c 2010/06/13 22:05:43 1.155 @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.150 2010/06/12 12:10:55 kristaps Exp $ */ +/* $Id: mdoc_term.c,v 1.155 2010/06/13 22:05:43 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -52,15 +52,14 @@ struct termact { void (*post)(DECL_ARGS); }; -static size_t a2width(const struct mdoc_argv *, int); +static size_t a2width(const char *); static size_t a2height(const struct mdoc_node *); static size_t a2offs(const char *); static int arg_hasattr(int, const struct mdoc_node *); -static int arg_getattrs(const int *, int *, size_t, - const struct mdoc_node *); static int arg_getattr(int, const struct mdoc_node *); static void print_bvspace(struct termp *, + const struct mdoc_node *, const struct mdoc_node *); static void print_mdoc_node(DECL_ARGS); static void print_mdoc_nodelist(DECL_ARGS); @@ -475,13 +474,13 @@ a2height(const struct mdoc_node *n) static size_t -a2width(const struct mdoc_argv *arg, int pos) +a2width(const char *v) { struct roffsu su; - assert(arg->value[pos]); - if ( ! a2roffsu(arg->value[pos], &su, SCALE_MAX)) - SCALE_HS_INIT(&su, strlen(arg->value[pos])); + assert(v); + if ( ! a2roffsu(v, &su, SCALE_MAX)) + SCALE_HS_INIT(&su, strlen(v)); return(term_hspan(&su)); } @@ -521,39 +520,21 @@ arg_hasattr(int arg, const struct mdoc_node *n) /* * Get the index of an argument in a node's argument list or -1 if it - * does not exist. See arg_getattrs(). + * does not exist. */ static int arg_getattr(int v, const struct mdoc_node *n) { - int val; + int i; - return(arg_getattrs(&v, &val, 1, n) ? val : -1); -} - - -/* - * Walk through the argument list for a node and fill an array "vals" - * with the positions of the argument structures listed in "keys". - * Return the number of elements that were written into "vals", which - * can be zero. - */ -static int -arg_getattrs(const int *keys, int *vals, - size_t sz, const struct mdoc_node *n) -{ - int i, j, k; - if (NULL == n->args) return(0); - for (k = i = 0; i < (int)n->args->argc; i++) - for (j = 0; j < (int)sz; j++) - if (n->args->argv[i].arg == keys[j]) { - vals[j] = i; - k++; - } - return(k); + for (i = 0; i < (int)n->args->argc; i++) + if (n->args->argv[i].arg == v) + return(i); + + return(-1); } @@ -563,15 +544,17 @@ arg_getattrs(const int *keys, int *vals, * too. */ static void -print_bvspace(struct termp *p, const struct mdoc_node *n) +print_bvspace(struct termp *p, + const struct mdoc_node *bl, + const struct mdoc_node *n) { const struct mdoc_node *nn; term_newln(p); - if (MDOC_Bl == n->tok && n->data.Bl.comp) + if (MDOC_Bd == bl->tok && bl->data.Bd.comp) return; - if (MDOC_Bd == n->tok && n->data.Bd.comp) + if (MDOC_Bl == bl->tok && bl->data.Bl.comp) return; /* Do not vspace directly after Ss/Sh. */ @@ -590,13 +573,13 @@ print_bvspace(struct termp *p, const struct mdoc_node /* A `-column' does not assert vspace within the list. */ - if (MDOC_Bl == n->tok && LIST_column == n->data.Bl.type) + if (MDOC_Bl == bl->tok && LIST_column == bl->data.Bl.type) if (n->prev && MDOC_It == n->prev->tok) return; /* A `-diag' without body does not vspace. */ - if (MDOC_Bl == n->tok && LIST_diag == n->data.Bl.type) + if (MDOC_Bl == bl->tok && LIST_diag == bl->data.Bl.type) if (n->prev && MDOC_It == n->prev->tok) { assert(n->prev->body); if (NULL == n->prev->body->child) @@ -640,27 +623,16 @@ termp_it_pre(DECL_ARGS) { const struct mdoc_node *bl, *nn; char buf[7]; - int i, keys[3], vals[3]; + int i, col; size_t width, offset, ncols, dcol; enum mdoc_list type; if (MDOC_BLOCK == n->type) { - print_bvspace(p, n); + print_bvspace(p, n->parent->parent, n); return(1); } bl = n->parent->parent->parent; - - /* Get list width, offset, and list type from argument list. */ - - keys[0] = MDOC_Width; - keys[1] = MDOC_Offset; - keys[2] = MDOC_Column; - - vals[0] = vals[1] = vals[2] = -1; - - arg_getattrs(keys, vals, 3, bl); - type = bl->data.Bl.type; /* @@ -671,13 +643,16 @@ termp_it_pre(DECL_ARGS) width = offset = 0; - if (vals[1] >= 0) - offset = a2offs(bl->args->argv[vals[1]].value[0]); + if (bl->data.Bl.offs) + offset = a2offs(bl->data.Bl.offs); switch (type) { case (LIST_column): if (MDOC_HEAD == n->type) break; + + col = arg_getattr(MDOC_Column, bl); + /* * Imitate groff's column handling: * - For each earlier column, add its width. @@ -687,7 +662,7 @@ termp_it_pre(DECL_ARGS) * column. * - For more than 5 columns, add only one column. */ - ncols = bl->args->argv[vals[2]].sz; + ncols = bl->args->argv[col].sz; /* LINTED */ dcol = ncols < 5 ? 4 : ncols == 5 ? 3 : 1; @@ -700,9 +675,8 @@ termp_it_pre(DECL_ARGS) nn->prev && i < (int)ncols; nn = nn->prev, i++) offset += dcol + a2width - (&bl->args->argv[vals[2]], i); + (bl->args->argv[col].value[i]); - /* * When exceeding the declared number of columns, leave * the remaining widths at 0. This will later be @@ -716,10 +690,10 @@ termp_it_pre(DECL_ARGS) * Use the declared column widths, extended as explained * in the preceding paragraph. */ - width = a2width(&bl->args->argv[vals[2]], i) + dcol; + width = a2width(bl->args->argv[col].value[i]) + dcol; break; default: - if (vals[0] < 0) + if (NULL == bl->data.Bl.width) break; /* @@ -727,7 +701,8 @@ termp_it_pre(DECL_ARGS) * number for buffering single arguments. See the above * handling for column for how this changes. */ - width = a2width(&bl->args->argv[vals[0]], 0) + 2; + assert(bl->data.Bl.width); + width = a2width(bl->data.Bl.width) + 2; break; } @@ -1606,7 +1581,7 @@ termp_bd_pre(DECL_ARGS) const struct mdoc_node *nn; if (MDOC_BLOCK == n->type) { - print_bvspace(p, n); + print_bvspace(p, n, n); return(1); } else if (MDOC_HEAD == n->type) return(0);