=================================================================== RCS file: /cvs/mandoc/man_term.c,v retrieving revision 1.21 retrieving revision 1.23 diff -u -p -r1.21 -r1.23 --- mandoc/man_term.c 2009/08/13 12:31:50 1.21 +++ mandoc/man_term.c 2009/08/17 11:03:07 1.23 @@ -1,4 +1,4 @@ -/* $Id: man_term.c,v 1.21 2009/08/13 12:31:50 kristaps Exp $ */ +/* $Id: man_term.c,v 1.23 2009/08/17 11:03:07 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -66,6 +66,7 @@ static int pre_sp(DECL_ARGS); static void post_B(DECL_ARGS); static void post_I(DECL_ARGS); +static void post_IP(DECL_ARGS); static void post_HP(DECL_ARGS); static void post_SH(DECL_ARGS); static void post_SS(DECL_ARGS); @@ -81,7 +82,7 @@ static const struct termact termacts[MAN_MAX] = { { pre_PP, NULL }, /* LP */ { pre_PP, NULL }, /* PP */ { pre_PP, NULL }, /* P */ - { pre_IP, NULL }, /* IP */ + { pre_IP, post_IP }, /* IP */ { pre_HP, post_HP }, /* HP */ { NULL, NULL }, /* SM */ { pre_B, post_B }, /* SB */ @@ -468,54 +469,85 @@ pre_PP(DECL_ARGS) static int pre_IP(DECL_ARGS) { - /* TODO */ -#if 0 - const struct man_node *nn; - size_t offs, sv; - int ival; + const struct man_node *nn; + size_t len; + int ival; - fmt_block_vspace(p, n); + switch (n->type) { + case (MAN_BODY): + p->flags |= TERMP_NOLPAD; + p->flags |= TERMP_NOSPACE; + break; + case (MAN_HEAD): + p->flags |= TERMP_NOBREAK; + p->flags |= TERMP_TWOSPACE; + break; + case (MAN_BLOCK): + fmt_block_vspace(p, n); + /* FALLTHROUGH */ + default: + return(1); + } - p->flags |= TERMP_NOSPACE; + len = INDENT; + ival = -1; - sv = p->offset; - p->offset = INDENT; + /* Calculate offset. */ - if (NULL == n->child) - return(1); + if (NULL != (nn = n->parent->head->child)) + if (NULL != (nn = nn->next)) { + for ( ; nn->next; nn = nn->next) + /* Do nothing. */ ; + if ((ival = arg_width(nn)) >= 0) + len = (size_t)ival; + } - p->flags |= TERMP_NOBREAK; + switch (n->type) { + case (MAN_HEAD): + /* Handle zero-width lengths. */ + if (0 == len) + len = 1; - offs = sv; + p->offset = INDENT; + p->rmargin = INDENT + len; + if (ival < 0) + break; - /* - * If the last token is number-looking (3m, 3n, 3) then - * interpret it as the width specifier, else we stick with the - * prior saved offset. XXX - obviously not documented. - */ - for (nn = n->child; nn; nn = nn->next) { - if (NULL == nn->next) { - ival = arg_width(nn); - if (ival >= 0) { - offs = (size_t)ival; - break; - } - } - print_node(p, fl, nn, m); + /* Don't print the length value. */ + for (nn = n->child; nn->next; nn = nn->next) + print_node(p, fl, nn, m); + return(0); + case (MAN_BODY): + p->offset = INDENT + len; + p->rmargin = p->maxrmargin; + break; + default: + break; } - p->rmargin = p->offset + offs; + return(1); +} - term_flushln(p); - p->offset = offs; - p->rmargin = p->maxrmargin; +/* ARGSUSED */ +static void +post_IP(DECL_ARGS) +{ - p->flags |= TERMP_NOLPAD | TERMP_NOSPACE; - - return(0); -#endif - return(1); + switch (n->type) { + case (MAN_HEAD): + term_flushln(p); + p->flags &= ~TERMP_NOBREAK; + p->flags &= ~TERMP_TWOSPACE; + p->rmargin = p->maxrmargin; + break; + case (MAN_BODY): + term_flushln(p); + p->flags &= ~TERMP_NOLPAD; + break; + default: + break; + } } @@ -523,24 +555,56 @@ pre_IP(DECL_ARGS) static int pre_TP(DECL_ARGS) { + const struct man_node *nn; + size_t len; + int ival; switch (n->type) { - case (MAN_BLOCK): - fmt_block_vspace(p, n); - break; case (MAN_HEAD): - p->rmargin = INDENT * 2; - p->offset = INDENT; p->flags |= TERMP_NOBREAK; p->flags |= TERMP_TWOSPACE; break; case (MAN_BODY): p->flags |= TERMP_NOLPAD; p->flags |= TERMP_NOSPACE; - p->offset = INDENT * 2; break; + case (MAN_BLOCK): + fmt_block_vspace(p, n); + /* FALLTHROUGH */ default: + return(1); + } + + len = INDENT; + ival = -1; + + /* Calculate offset. */ + + if (NULL != (nn = n->parent->head->child)) + if (NULL != nn->next) + if ((ival = arg_width(nn)) >= 0) + len = (size_t)ival; + + switch (n->type) { + case (MAN_HEAD): + /* Handle zero-length properly. */ + if (0 == len) + len = 1; + + p->offset = INDENT; + p->rmargin = INDENT + len; + + /* Don't print same-line elements. */ + for (nn = n->child; nn; nn = nn->next) + if (nn->line > n->line) + print_node(p, fl, nn, m); + return(0); + case (MAN_BODY): + p->offset = INDENT + len; + p->rmargin = p->maxrmargin; break; + default: + break; } return(1); @@ -613,12 +677,10 @@ post_SS(DECL_ARGS) static int pre_SH(DECL_ARGS) { - /* - * XXX: undocumented: using two `SH' macros in sequence has no - * vspace between calls, only a newline. - */ + switch (n->type) { case (MAN_BLOCK): + /* If following a prior empty `SH', no vspace. */ if (n->prev && MAN_SH == n->prev->tok) if (NULL == n->prev->body->child) break;