From e9ed9b35dc4fd863125a597aff030d991806984f Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Sat, 12 Jun 2010 12:38:01 +0000 Subject: Cached `Bl -offset' into mdoc_bl. Removed erroneous "-offset defaults to 6n if no value is specified" and added regression tests for `Bl' testing against the empty -offset argument. --- mdoc.h | 3 ++- mdoc_action.c | 44 ++--------------------------------------- mdoc_html.c | 14 +++++-------- mdoc_term.c | 22 ++++++++++----------- mdoc_validate.c | 23 ++++++++++++++------- regress/mdoc/Bl/empty-offset.in | 15 ++++++++++++++ 6 files changed, 51 insertions(+), 70 deletions(-) create mode 100644 regress/mdoc/Bl/empty-offset.in diff --git a/mdoc.h b/mdoc.h index 24811c90..aaa81129 100644 --- a/mdoc.h +++ b/mdoc.h @@ -1,4 +1,4 @@ -/* $Id: mdoc.h,v 1.87 2010/06/12 12:10:55 kristaps Exp $ */ +/* $Id: mdoc.h,v 1.88 2010/06/12 12:38:01 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -279,6 +279,7 @@ struct mdoc_bd { }; struct mdoc_bl { + const char *offs; /* -offset */ enum mdoc_list type; /* -tag, -enum, etc. */ int comp; /* -compact */ }; diff --git a/mdoc_action.c b/mdoc_action.c index e103eb98..a783943c 100644 --- a/mdoc_action.c +++ b/mdoc_action.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_action.c,v 1.67 2010/06/12 11:21:44 kristaps Exp $ */ +/* $Id: mdoc_action.c,v 1.68 2010/06/12 12:38:01 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -68,9 +68,7 @@ static int post_st(POST_ARGS); static int post_std(POST_ARGS); static int pre_bd(PRE_ARGS); -static int pre_bl(PRE_ARGS); static int pre_dl(PRE_ARGS); -static int pre_offset(PRE_ARGS); static const struct actions mdoc_actions[MDOC_MAX] = { { NULL, NULL }, /* Ap */ @@ -84,7 +82,7 @@ static const struct actions mdoc_actions[MDOC_MAX] = { { pre_dl, post_display }, /* Dl */ { pre_bd, post_display }, /* Bd */ { NULL, NULL }, /* Ed */ - { pre_bl, post_bl }, /* Bl */ + { NULL, post_bl }, /* Bl */ { NULL, NULL }, /* El */ { NULL, NULL }, /* It */ { NULL, NULL }, /* Ad */ @@ -937,44 +935,6 @@ pre_dl(PRE_ARGS) } -/* ARGSUSED */ -static int -pre_offset(PRE_ARGS) -{ - int i; - - /* - * Make sure that an empty offset produces an 8n length space as - * stipulated by mdoc.samples. - */ - - for (i = 0; n->args && i < (int)n->args->argc; i++) { - if (MDOC_Offset != n->args->argv[i].arg) - continue; - if (n->args->argv[i].sz) - break; - assert(1 == n->args->refcnt); - /* If no value set, length of . */ - n->args->argv[i].sz++; - n->args->argv[i].value = mandoc_malloc(sizeof(char *)); - n->args->argv[i].value[0] = mandoc_strdup("8n"); - break; - } - - return(1); -} - - -static int -pre_bl(PRE_ARGS) -{ - - if (MDOC_BLOCK == n->type) - return(pre_offset(m, n)); - return(1); -} - - static int pre_bd(PRE_ARGS) { diff --git a/mdoc_html.c b/mdoc_html.c index ac58c701..bc483471 100644 --- a/mdoc_html.c +++ b/mdoc_html.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_html.c,v 1.82 2010/06/12 12:10:55 kristaps Exp $ */ +/* $Id: mdoc_html.c,v 1.83 2010/06/12 12:38:01 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -1035,12 +1035,13 @@ mdoc_it_pre(MDOC_ARGS) if (MDOC_BLOCK != n->type) bl = bl->parent; + SCALE_HS_INIT(&offs, 0); + type = bl->data.Bl.type; comp = bl->data.Bl.comp; - /* Set default width and offset. */ - - SCALE_HS_INIT(&offs, 0); + if (bl->data.Bl.offs) + a2offs(bl->data.Bl.offs, &offs); switch (type) { case (LIST_enum): @@ -1057,8 +1058,6 @@ mdoc_it_pre(MDOC_ARGS) break; } - /* Get width, offset, and compact arguments. */ - wp = -1; for (i = 0; bl->args && i < (int)bl->args->argc; i++) switch (bl->args->argv[i].arg) { @@ -1068,9 +1067,6 @@ mdoc_it_pre(MDOC_ARGS) case (MDOC_Width): a2width(bl->args->argv[i].value[0], &width); break; - case (MDOC_Offset): - a2offs(bl->args->argv[i].value[0], &offs); - break; default: break; } diff --git a/mdoc_term.c b/mdoc_term.c index 9105e71c..49771eaa 100644 --- a/mdoc_term.c +++ b/mdoc_term.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.151 2010/06/12 12:21:41 kristaps Exp $ */ +/* $Id: mdoc_term.c,v 1.152 2010/06/12 12:38:01 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -643,7 +643,7 @@ termp_it_pre(DECL_ARGS) { const struct mdoc_node *bl, *nn; char buf[7]; - int i, keys[3], vals[3]; + int i, keys[2], vals[2]; size_t width, offset, ncols, dcol; enum mdoc_list type; @@ -657,12 +657,11 @@ termp_it_pre(DECL_ARGS) /* Get list width, offset, and list type from argument list. */ keys[0] = MDOC_Width; - keys[1] = MDOC_Offset; - keys[2] = MDOC_Column; + keys[1] = MDOC_Column; - vals[0] = vals[1] = vals[2] = -1; + vals[0] = vals[1] = -1; - arg_getattrs(keys, vals, 3, bl); + arg_getattrs(keys, vals, 2, bl); type = bl->data.Bl.type; @@ -674,8 +673,9 @@ 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): @@ -690,7 +690,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[vals[1]].sz; /* LINTED */ dcol = ncols < 5 ? 4 : ncols == 5 ? 3 : 1; @@ -703,7 +703,7 @@ 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[vals[1]], i); /* @@ -719,7 +719,7 @@ 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[vals[1]], i) + dcol; break; default: if (vals[0] < 0) diff --git a/mdoc_validate.c b/mdoc_validate.c index b15fe397..843b45db 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.97 2010/06/12 12:10:55 kristaps Exp $ */ +/* $Id: mdoc_validate.c,v 1.98 2010/06/12 12:38:01 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -532,7 +532,8 @@ pre_display(PRE_ARGS) static int pre_bl(PRE_ARGS) { - int i, width, offs, comp, dup; + int i, width, comp, dup; + const char *offs; enum mdoc_list lt; if (MDOC_BLOCK != n->type) { @@ -552,12 +553,13 @@ pre_bl(PRE_ARGS) */ assert(LIST__NONE == n->data.Bl.type); - offs = width = -1; + width = -1; /* LINTED */ for (i = 0; n->args && i < (int)n->args->argc; i++) { lt = LIST__NONE; dup = comp = 0; + offs = NULL; switch (n->args->argv[i].arg) { /* Set list types. */ case (MDOC_Bullet): @@ -604,9 +606,14 @@ pre_bl(PRE_ARGS) width = i; break; case (MDOC_Offset): - if (offs >= 0) - dup++; - offs = i; + /* NB: this can be empty! */ + if (n->args->argv[i].sz) { + offs = n->args->argv[i].value[0]; + dup = (NULL != n->data.Bd.offs); + break; + } + if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_IGNARGV)) + return(0); break; } @@ -617,6 +624,8 @@ pre_bl(PRE_ARGS) if (comp && ! dup) n->data.Bl.comp = comp; + if (offs && ! dup) + n->data.Bl.offs = offs; /* Check: multiple list types. */ @@ -632,7 +641,7 @@ pre_bl(PRE_ARGS) /* The list type should come first. */ if (n->data.Bl.type == LIST__NONE) - if (width >= 0 || offs >= 0 || n->data.Bl.comp) + if (width >= 0 || n->data.Bl.offs || n->data.Bl.comp) if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_LISTFIRST)) return(0); diff --git a/regress/mdoc/Bl/empty-offset.in b/regress/mdoc/Bl/empty-offset.in new file mode 100644 index 00000000..63ac458a --- /dev/null +++ b/regress/mdoc/Bl/empty-offset.in @@ -0,0 +1,15 @@ +.Dd $Mdocdate: June 12 2010 $ +.Dt FOO 1 +.Os +.Sh NAME +.Nm foo +.Nd bar +.Sh DESCRIPTION +.Bl -tag -width Ds -offset +.It foo +bar +.El +.Bl -tag -width Ds +.It foo +bar +.El -- cgit v1.2.3-56-ge451