=================================================================== RCS file: /cvs/mandoc/mdoc_term.c,v retrieving revision 1.117 retrieving revision 1.118 diff -u -p -r1.117 -r1.118 --- mandoc/mdoc_term.c 2010/04/08 08:17:55 1.117 +++ mandoc/mdoc_term.c 2010/05/09 16:05:13 1.118 @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.117 2010/04/08 08:17:55 kristaps Exp $ */ +/* $Id: mdoc_term.c,v 1.118 2010/05/09 16:05:13 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -58,6 +59,7 @@ 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 int arg_disptype(const struct mdoc_node *); static int arg_listtype(const struct mdoc_node *); static void print_bvspace(struct termp *, const struct mdoc_node *, @@ -478,6 +480,35 @@ a2width(const struct mdoc_argv *arg, int pos) static int +arg_disptype(const struct mdoc_node *n) +{ + int i, len; + + assert(MDOC_BLOCK == n->type); + + len = (int)(n->args ? n->args->argc : 0); + + for (i = 0; i < len; i++) + switch (n->args->argv[i].arg) { + case (MDOC_Centred): + /* FALLTHROUGH */ + case (MDOC_Ragged): + /* FALLTHROUGH */ + case (MDOC_Filled): + /* FALLTHROUGH */ + case (MDOC_Unfilled): + /* FALLTHROUGH */ + case (MDOC_Literal): + return(n->args->argv[i].arg); + default: + break; + } + + return(-1); +} + + +static int arg_listtype(const struct mdoc_node *n) { int i, len; @@ -1126,7 +1157,7 @@ termp_an_post(DECL_ARGS) return; } - if (arg_getattr(MDOC_Split, n) > -1) { + if (arg_hasattr(MDOC_Split, n)) { p->flags &= ~TERMP_NOSPLIT; p->flags |= TERMP_SPLIT; } else { @@ -1598,6 +1629,7 @@ static int termp_bd_pre(DECL_ARGS) { int i, type; + size_t sv; const struct mdoc_node *nn; if (MDOC_BLOCK == n->type) { @@ -1608,27 +1640,12 @@ termp_bd_pre(DECL_ARGS) nn = n->parent; - for (type = -1, i = 0; i < (int)nn->args->argc; i++) { - switch (nn->args->argv[i].arg) { - case (MDOC_Centred): - /* FALLTHROUGH */ - case (MDOC_Ragged): - /* FALLTHROUGH */ - case (MDOC_Filled): - /* FALLTHROUGH */ - case (MDOC_Unfilled): - /* FALLTHROUGH */ - case (MDOC_Literal): - type = nn->args->argv[i].arg; - break; - case (MDOC_Offset): - p->offset += a2offs(&nn->args->argv[i]); - break; - default: - break; - } - } + type = arg_disptype(nn); + assert(-1 != type); + if (-1 != (i = arg_getattr(MDOC_Offset, nn))) + p->offset += a2offs(&nn->args->argv[i]); + /* * If -ragged or -filled are specified, the block does nothing * but change the indentation. If -unfilled or -literal are @@ -1637,10 +1654,12 @@ termp_bd_pre(DECL_ARGS) * lines are allowed. */ - assert(type > -1); if (MDOC_Literal != type && MDOC_Unfilled != type) return(1); + sv = p->rmargin; + p->rmargin = 100000; /* FIXME */ + for (nn = n->child; nn; nn = nn->next) { p->flags |= TERMP_NOSPACE; print_mdoc_node(p, pair, m, nn); @@ -1652,6 +1671,7 @@ termp_bd_pre(DECL_ARGS) term_flushln(p); } + p->rmargin = sv; return(0); } @@ -1660,11 +1680,24 @@ termp_bd_pre(DECL_ARGS) static void termp_bd_post(DECL_ARGS) { + int type; + size_t sv; if (MDOC_BODY != n->type) return; + + type = arg_disptype(n->parent); + assert(-1 != type); + + sv = p->rmargin; + + if (MDOC_Literal == type || MDOC_Unfilled == type) + p->rmargin = 100000; /* FIXME */ + p->flags |= TERMP_NOSPACE; term_flushln(p); + + p->rmargin = sv; }