=================================================================== RCS file: /cvs/mandoc/mdoc_term.c,v retrieving revision 1.44 retrieving revision 1.54 diff -u -p -r1.44 -r1.54 --- mandoc/mdoc_term.c 2009/07/17 10:56:57 1.44 +++ mandoc/mdoc_term.c 2009/07/21 15:03:37 1.54 @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.44 2009/07/17 10:56:57 kristaps Exp $ */ +/* $Id: mdoc_term.c,v 1.54 2009/07/21 15:03:37 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 */ @@ -155,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); @@ -164,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); @@ -210,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 */ @@ -294,7 +293,7 @@ static const struct termact termacts[MDOC_MAX] = { { termp_xx_pre, NULL }, /* Dx */ { NULL, NULL }, /* %Q */ { termp_br_pre, NULL }, /* br */ - { NULL, NULL }, /* sp */ + { termp_sp_pre, NULL }, /* sp */ }; #ifdef __linux__ @@ -309,7 +308,7 @@ static int arg_getattr(int, const struct mdoc_node * static size_t arg_offset(const struct mdoc_argv *); static size_t arg_width(const struct mdoc_argv *, int); static int arg_listtype(const struct mdoc_node *); -static int fmt_block_vspace(struct termp *, +static void fmt_block_vspace(struct termp *, const struct mdoc_node *, const struct mdoc_node *); static void print_node(DECL_ARGS); @@ -363,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)) @@ -377,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) @@ -385,7 +393,6 @@ print_node(DECL_ARGS) p->offset = offset; p->rmargin = rmargin; - p->flags &= ~npair.flag; } @@ -652,7 +659,7 @@ arg_getattrs(const int *keys, int *vals, /* ARGSUSED */ -static int +static void fmt_block_vspace(struct termp *p, const struct mdoc_node *bl, const struct mdoc_node *node) @@ -662,22 +669,35 @@ fmt_block_vspace(struct termp *p, term_newln(p); if (arg_hasattr(MDOC_Compact, bl)) - return(1); + return; + /* + * Search through our prior nodes. If we follow a `Ss' or `Sh', + * then don't vspace. + */ + for (n = node; n; n = n->parent) { if (MDOC_BLOCK != n->type) continue; if (MDOC_Ss == n->tok) - break; + return; if (MDOC_Sh == n->tok) - break; + return; if (NULL == n->prev) continue; - term_vspace(p); break; } - return(1); + /* + * XXX - not documented: a `-column' does not ever assert + * vertical space within the list. + */ + + if (arg_hasattr(MDOC_Column, bl)) + if (node->prev && MDOC_It == node->prev->tok) + return; + + term_vspace(p); } @@ -717,8 +737,10 @@ termp_it_pre(DECL_ARGS) int i, type, keys[3], vals[3]; size_t width, offset; - if (MDOC_BLOCK == node->type) - return(fmt_block_vspace(p, node->parent->parent, node)); + if (MDOC_BLOCK == node->type) { + fmt_block_vspace(p, node->parent->parent, node); + return(1); + } bl = node->parent->parent->parent; @@ -786,6 +808,8 @@ termp_it_pre(DECL_ARGS) if (0 == width) width = 8; break; + case (MDOC_Column): + /* FALLTHROUGH */ case (MDOC_Tag): if (0 == width) width = 10; @@ -799,18 +823,22 @@ termp_it_pre(DECL_ARGS) * while diagonal bodies need two. */ + p->flags |= TERMP_NOSPACE; + switch (type) { + case (MDOC_Diag): + 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 +884,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 +932,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,11 +1024,10 @@ termp_it_post(DECL_ARGS) assert(-1 != type); switch (type) { - case (MDOC_Diag): - term_word(p, "\\ "); - /* FALLTHROUGH */ case (MDOC_Item): /* FALLTHROUGH */ + case (MDOC_Diag): + /* FALLTHROUGH */ case (MDOC_Inset): if (MDOC_BODY == node->type) term_flushln(p); @@ -1507,10 +1543,11 @@ termp_bd_pre(DECL_ARGS) * line. Blank lines are allowed. */ - if (MDOC_BLOCK == node->type) - return(fmt_block_vspace(p, node, node)); - else if (MDOC_BODY != node->type) + if (MDOC_BLOCK == node->type) { + fmt_block_vspace(p, node, node); return(1); + } else if (MDOC_BODY != node->type) + return(1); /* FIXME: display type should be mandated by parser. */ @@ -1560,7 +1597,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) { @@ -1583,10 +1619,7 @@ termp_bd_post(DECL_ARGS) if (MDOC_BODY != node->type) return; - term_flushln(p); - p->flags &= ~TERMP_LITERAL; - p->flags |= TERMP_NOSPACE; } @@ -1742,16 +1775,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) { @@ -1813,8 +1836,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; @@ -1828,6 +1852,27 @@ 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); }