=================================================================== RCS file: /cvs/mandoc/mdoc_term.c,v retrieving revision 1.41 retrieving revision 1.52 diff -u -p -r1.41 -r1.52 --- mandoc/mdoc_term.c 2009/07/14 16:03:51 1.41 +++ mandoc/mdoc_term.c 2009/07/21 13:45:04 1.52 @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.41 2009/07/14 16:03:51 kristaps Exp $ */ +/* $Id: mdoc_term.c,v 1.52 2009/07/21 13:45:04 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -27,7 +27,6 @@ #include "mdoc.h" /* FIXME: macro arguments can be escaped. */ -/* FIXME: support more offset/width tokens. */ #define TTYPE_PROG 0 #define TTYPE_CMD_FLAG 1 @@ -66,7 +65,7 @@ const int ttypes[TTYPE_NMAX] = { TERMP_UNDER, /* TTYPE_FUNC_ARG */ TERMP_UNDER, /* TTYPE_LINK */ TERMP_BOLD, /* TTYPE_SSECTION */ - TERMP_UNDER, /* TTYPE_FILE */ + 0, /* TTYPE_FILE */ TERMP_UNDER, /* TTYPE_EMPH */ TERMP_BOLD, /* TTYPE_CONFIG */ TERMP_BOLD, /* TTYPE_CMD */ @@ -130,6 +129,7 @@ static int termp_ar_pre(DECL_ARGS); static int termp_bd_pre(DECL_ARGS); static int termp_bf_pre(DECL_ARGS); static int termp_bq_pre(DECL_ARGS); +static int termp_br_pre(DECL_ARGS); static int termp_brq_pre(DECL_ARGS); static int termp_bt_pre(DECL_ARGS); static int termp_cd_pre(DECL_ARGS); @@ -154,7 +154,6 @@ static int termp_nd_pre(DECL_ARGS); static int termp_nm_pre(DECL_ARGS); static int termp_ns_pre(DECL_ARGS); static int termp_op_pre(DECL_ARGS); -static int termp_pa_pre(DECL_ARGS); static int termp_pf_pre(DECL_ARGS); static int termp_pp_pre(DECL_ARGS); static int termp_pq_pre(DECL_ARGS); @@ -163,6 +162,7 @@ static int termp_rs_pre(DECL_ARGS); static int termp_rv_pre(DECL_ARGS); static int termp_sh_pre(DECL_ARGS); static int termp_sm_pre(DECL_ARGS); +static int termp_sp_pre(DECL_ARGS); static int termp_sq_pre(DECL_ARGS); static int termp_ss_pre(DECL_ARGS); static int termp_sx_pre(DECL_ARGS); @@ -209,7 +209,7 @@ static const struct termact termacts[MDOC_MAX] = { { termp_nm_pre, NULL }, /* Nm */ { termp_op_pre, termp_op_post }, /* Op */ { NULL, NULL }, /* Ot */ - { termp_pa_pre, NULL }, /* Pa */ + { NULL, NULL }, /* Pa */ { termp_rv_pre, NULL }, /* Rv */ { NULL, NULL }, /* St */ { termp_va_pre, NULL }, /* Va */ @@ -292,6 +292,8 @@ static const struct termact termacts[MDOC_MAX] = { { NULL, NULL }, /* En */ { termp_xx_pre, NULL }, /* Dx */ { NULL, NULL }, /* %Q */ + { termp_br_pre, NULL }, /* br */ + { termp_sp_pre, NULL }, /* sp */ }; #ifdef __linux__ @@ -360,6 +362,13 @@ print_node(DECL_ARGS) npair.flag = 0; npair.count = 0; + /* + * Note on termpair. This allows a pre function to set a termp + * flag that is automatically unset after the body, but before + * the post function. Thus, if a pre uses a termpair flag, it + * must be reapplied in the post for use. + */ + if (MDOC_TEXT != node->type) { if (termacts[node->tok].pre) if ( ! (*termacts[node->tok].pre)(p, &npair, meta, node)) @@ -374,6 +383,8 @@ print_node(DECL_ARGS) if (dochild && node->child) print_body(p, &npair, meta, node->child); + p->flags &= ~npair.flag; + /* Post-processing. */ if (MDOC_TEXT != node->type) @@ -382,7 +393,6 @@ print_node(DECL_ARGS) p->offset = offset; p->rmargin = rmargin; - p->flags &= ~npair.flag; } @@ -407,7 +417,7 @@ print_foot(struct termp *p, const struct mdoc_meta *me tm = localtime(&meta->date); - if (0 == strftime(buf, p->rmargin, "%B %d, %Y", tm)) + if (0 == strftime(buf, p->rmargin, "%B %e, %Y", tm)) err(1, "strftime"); (void)strlcpy(os, meta->os, p->rmargin); @@ -660,6 +670,9 @@ fmt_block_vspace(struct termp *p, if (arg_hasattr(MDOC_Compact, bl)) return(1); + /* XXX - not documented! */ + else if (arg_hasattr(MDOC_Column, bl)) + return(1); for (n = node; n; n = n->parent) { if (MDOC_BLOCK != n->type) @@ -783,6 +796,8 @@ termp_it_pre(DECL_ARGS) if (0 == width) width = 8; break; + case (MDOC_Column): + /* FALLTHROUGH */ case (MDOC_Tag): if (0 == width) width = 10; @@ -796,21 +811,22 @@ termp_it_pre(DECL_ARGS) * while diagonal bodies need two. */ + p->flags |= TERMP_NOSPACE; + switch (type) { case (MDOC_Diag): - term_word(p, "\\ "); - /* FALLTHROUGH */ + term_word(p, "\\ \\ "); + break; case (MDOC_Inset): if (MDOC_BODY == node->type) - p->flags &= ~TERMP_NOSPACE; - else - p->flags |= TERMP_NOSPACE; + term_word(p, "\\ "); break; default: - p->flags |= TERMP_NOSPACE; break; } + p->flags |= TERMP_NOSPACE; + /* * Style flags. Diagnostic heads need TTYPE_DIAG. */ @@ -856,7 +872,7 @@ termp_it_pre(DECL_ARGS) break; case (MDOC_Tag): if (MDOC_HEAD == node->type) - p->flags |= TERMP_NOBREAK; + p->flags |= TERMP_NOBREAK | TERMP_TWOSPACE; else p->flags |= TERMP_NOLPAD; @@ -904,13 +920,22 @@ termp_it_pre(DECL_ARGS) case (MDOC_Hang): /* FALLTHROUGH */ case (MDOC_Tag): + assert(width); if (MDOC_HEAD == node->type) p->rmargin = p->offset + width; else p->offset += width; break; case (MDOC_Column): + assert(width); p->rmargin = p->offset + width; + /* + * XXX - this behaviour is not documented: the + * right-most column is filled to the right margin. + */ + if (MDOC_HEAD == node->type && + MDOC_BODY == node->next->type) + p->rmargin = p->maxrmargin; break; default: break; @@ -987,8 +1012,6 @@ termp_it_post(DECL_ARGS) assert(-1 != type); switch (type) { - case (MDOC_Diag): - /* FALLTHROUGH */ case (MDOC_Item): /* FALLTHROUGH */ case (MDOC_Inset): @@ -1559,7 +1582,6 @@ termp_bd_pre(DECL_ARGS) * Ew. */ - p->flags |= TERMP_LITERAL; ln = node->child ? node->child->line : 0; for (node = node->child; node; node = node->next) { @@ -1582,10 +1604,7 @@ termp_bd_post(DECL_ARGS) if (MDOC_BODY != node->type) return; - term_flushln(p); - p->flags &= ~TERMP_LITERAL; - p->flags |= TERMP_NOSPACE; } @@ -1741,16 +1760,6 @@ termp_ss_post(DECL_ARGS) /* ARGSUSED */ static int -termp_pa_pre(DECL_ARGS) -{ - - pair->flag |= ttypes[TTYPE_FILE]; - return(1); -} - - -/* ARGSUSED */ -static int termp_em_pre(DECL_ARGS) { @@ -1812,8 +1821,9 @@ static void termp_in_post(DECL_ARGS) { - p->flags |= TERMP_NOSPACE; + p->flags |= TERMP_NOSPACE | ttypes[TTYPE_INCLUDE]; term_word(p, ">"); + p->flags &= ~ttypes[TTYPE_INCLUDE]; if (SEC_SYNOPSIS != node->sec) return; @@ -1827,6 +1837,37 @@ termp_in_post(DECL_ARGS) */ if (node->next && MDOC_In != node->next->tok) term_vspace(p); +} + + +/* ARGSUSED */ +static int +termp_sp_pre(DECL_ARGS) +{ + int i, len; + + if (NULL == node->child) { + term_vspace(p); + return(0); + } + + len = atoi(node->child->string); + if (0 == len) + term_newln(p); + for (i = 0; i < len; i++) + term_vspace(p); + + return(0); +} + + +/* ARGSUSED */ +static int +termp_br_pre(DECL_ARGS) +{ + + term_newln(p); + return(1); }