From d8cc7939c87b98bce901828e6ad799e21b6154dc Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Thu, 13 Aug 2009 12:54:52 +0000 Subject: Finished correct `IP' handling. --- man.7 | 21 ++++++++---- man_term.c | 112 +++++++++++++++++++++++++++++++++++++------------------------ 2 files changed, 84 insertions(+), 49 deletions(-) diff --git a/man.7 b/man.7 index 0743e4a6..8a313a84 100644 --- a/man.7 +++ b/man.7 @@ -1,4 +1,4 @@ -.\" $Id: man.7,v 1.24 2009/08/13 12:31:50 kristaps Exp $ +.\" $Id: man.7,v 1.25 2009/08/13 12:54:52 kristaps Exp $ .\" .\" Copyright (c) 2009 Kristaps Dzonsons .\" @@ -283,14 +283,24 @@ Whitespace between arguments is omitted in output. .It \&HP Begin a paragraph whose initial output line is left-justified, but subsequent output lines are indented. -.\" TODO. .It \&I Text is rendered in italics. .It \&IB Text is rendered alternately in italics and bold face. Whitespace between arguments is omitted in output. .It \&IP -.\" TODO. +Begin a paragraph with the following syntax: +.Bd -literal -offset indent +\&.IP [head [width]] +.Ed +.Pp +This follows the behaviour of the +.Sq \&TP +macro except that +.Va width , +which is only considered as such if properly-formed (e.g., 24n, 4, +etc.), is used as the indentation offset instead of the default +indentation value. .It \&IR Text is rendered alternately in italics and roman (the default font). Whitespace between arguments is omitted in output. @@ -339,12 +349,11 @@ string specifies the organisation providing the utility. The .Va volume replaces the default rendered volume as dictated by the manual section. .It \&TP -Begin a paragraph where the head, if exceeding the indentation point, is +Begin a paragraph where the head, if exceeding the indentation width, is followed by a newline; if not, the body follows on the same line after a -buffer to the indentation point. Subsequent output lines are indented. +buffer to the indentation width. Subsequent output lines are indented. .It \&br Breaks the current line. Consecutive invocations have no further effect. -.\" TODO. .It \&fi End literal mode begun by .Sq \&nf . diff --git a/man_term.c b/man_term.c index 6506d08e..56ac4ac9 100644 --- a/man_term.c +++ b/man_term.c @@ -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.22 2009/08/13 12:54:52 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,81 @@ pre_PP(DECL_ARGS) static int pre_IP(DECL_ARGS) { - /* TODO */ -#if 0 - const struct man_node *nn; - size_t offs, sv; - int ival; - - fmt_block_vspace(p, n); - - p->flags |= TERMP_NOSPACE; + const struct man_node *nn; + size_t len; + int ival; - sv = p->offset; - p->offset = INDENT; - - if (NULL == n->child) + switch (n->type) { + case (MAN_BLOCK): + fmt_block_vspace(p, n); + return(1); + case (MAN_BODY): + p->flags |= TERMP_NOLPAD; + p->flags |= TERMP_NOSPACE; + break; + case (MAN_HEAD): + p->flags |= TERMP_NOBREAK; + p->flags |= TERMP_TWOSPACE; + break; + default: return(1); + } - p->flags |= TERMP_NOBREAK; + len = INDENT * 2; + ival = -1; - offs = sv; + /* Calculate offset. */ - /* - * 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; - } + 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; } - print_node(p, fl, nn, m); - } - p->rmargin = p->offset + offs; + switch (n->type) { + case (MAN_BODY): + p->offset = INDENT + len; + p->rmargin = p->maxrmargin; + break; + case (MAN_HEAD): + p->offset = INDENT; + p->rmargin = INDENT + len; + if (ival < 0) + break; - term_flushln(p); + /* Don't print the length value. */ + for (nn = n->child; nn->next; nn = nn->next) + print_node(p, fl, nn, m); + return(0); + default: + break; + } - p->offset = offs; - p->rmargin = p->maxrmargin; + return(1); +} - p->flags |= TERMP_NOLPAD | TERMP_NOSPACE; - return(0); -#endif - return(1); +/* ARGSUSED */ +static void +post_IP(DECL_ARGS) +{ + + 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; + } } @@ -613,12 +641,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; -- cgit v1.2.3-56-ge451