=================================================================== RCS file: /cvs/mandoc/mdoc_term.c,v retrieving revision 1.11 retrieving revision 1.17 diff -u -p -r1.11 -r1.17 --- mandoc/mdoc_term.c 2009/06/11 13:13:44 1.11 +++ mandoc/mdoc_term.c 2009/06/22 12:38:07 1.17 @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.11 2009/06/11 13:13:44 kristaps Exp $ */ +/* $Id: mdoc_term.c,v 1.17 2009/06/22 12:38:07 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -183,7 +183,7 @@ struct termact { }; static const struct termact termacts[MDOC_MAX] = { - { NULL, NULL }, /* \" */ + { termp_ap_pre, NULL }, /* Ap */ { NULL, NULL }, /* Dd */ { NULL, NULL }, /* Dt */ { NULL, NULL }, /* Os */ @@ -290,8 +290,7 @@ static const struct termact termacts[MDOC_MAX] = { { NULL, NULL }, /* Fr */ { termp_ud_pre, NULL }, /* Ud */ { termp_lb_pre, termp_lb_post }, /* Lb */ - { termp_ap_pre, NULL }, /* Lb */ - { termp_pp_pre, NULL }, /* Pp */ + { termp_pp_pre, NULL }, /* Lp */ { termp_lk_pre, NULL }, /* Lk */ { termp_mt_pre, NULL }, /* Mt */ { termp_brq_pre, termp_brq_post }, /* Brq */ @@ -336,7 +335,10 @@ mdoc_run(struct termp *p, const struct mdoc *m) */ print_head(p, mdoc_meta(m)); - print_body(p, NULL, mdoc_meta(m), mdoc_node(m)); + assert(mdoc_node(m)); + assert(MDOC_ROOT == mdoc_node(m)->type); + if (mdoc_node(m)->child) + print_body(p, NULL, mdoc_meta(m), mdoc_node(m)->child); print_foot(p, mdoc_meta(m)); return(1); } @@ -415,11 +417,7 @@ print_foot(struct termp *p, const struct mdoc_meta *me tm = localtime(&meta->date); -#ifdef __OpenBSD__ - if (NULL == strftime(buf, p->rmargin, "%B %d, %Y", tm)) -#else if (0 == strftime(buf, p->rmargin, "%B %d, %Y", tm)) -#endif err(1, "strftime"); (void)strlcpy(os, meta->os, p->rmargin); @@ -535,9 +533,9 @@ arg_width(const struct mdoc_argv *arg, int pos) assert(pos < (int)arg->sz && pos >= 0); assert(arg->value[pos]); if (0 == strcmp(arg->value[pos], "indent")) - return(INDENT); + return(INDENT + 3); if (0 == strcmp(arg->value[pos], "indent-two")) - return(INDENT * 2); + return(INDENT * 2 + 2); if (0 == (len = (int)strlen(arg->value[pos]))) return(0); @@ -547,13 +545,14 @@ arg_width(const struct mdoc_argv *arg, int pos) break; if (i == len - 1) { - if ('n' == arg->value[pos][len - 1]) { + if ('n' == arg->value[pos][len - 1] || + 'm' == arg->value[pos][len - 1]) { v = (size_t)atoi(arg->value[pos]); - return(v); + return(v + 2); } } - return(strlen(arg->value[pos]) + 1); + return(strlen(arg->value[pos]) + 2); } @@ -605,9 +604,9 @@ arg_offset(const struct mdoc_argv *arg) assert(*arg->value); if (0 == strcmp(*arg->value, "left")) - return(0); + return(INDENT - 1); if (0 == strcmp(*arg->value, "indent")) - return(INDENT); + return(INDENT + 1); if (0 == strcmp(*arg->value, "indent-two")) return(INDENT * 2); @@ -716,7 +715,7 @@ termp_it_pre(DECL_ARGS) { const struct mdoc_node *bl, *n; char buf[7]; - int i, type, keys[3], vals[3]; + int i, type, keys[3], vals[3], sv; size_t width, offset; if (MDOC_BLOCK == node->type) @@ -777,12 +776,14 @@ termp_it_pre(DECL_ARGS) /* FALLTHROUGH */ case (MDOC_Dash): /* FALLTHROUGH */ - case (MDOC_Enum): - /* FALLTHROUGH */ case (MDOC_Hyphen): if (width < 4) width = 4; break; + case (MDOC_Enum): + if (width < 5) + width = 5; + break; case (MDOC_Tag): if (0 == width) width = 10; @@ -792,11 +793,13 @@ termp_it_pre(DECL_ARGS) } /* - * Whitespace control. Inset bodies need an initial space. + * Whitespace control. Inset bodies need an initial space, + * while diagonal bodies need two. */ switch (type) { case (MDOC_Diag): + term_word(p, "\\ "); /* FALLTHROUGH */ case (MDOC_Inset): if (MDOC_BODY == node->type) @@ -900,17 +903,20 @@ termp_it_pre(DECL_ARGS) /* * The dash, hyphen, bullet and enum lists all have a special - * HEAD character. Print it now. + * HEAD character (temporarily bold, in some cases). */ + sv = p->flags; if (MDOC_HEAD == node->type) switch (type) { case (MDOC_Bullet): + p->flags |= TERMP_BOLD; term_word(p, "\\[bu]"); break; case (MDOC_Dash): /* FALLTHROUGH */ case (MDOC_Hyphen): + p->flags |= TERMP_BOLD; term_word(p, "\\-"); break; case (MDOC_Enum): @@ -923,6 +929,8 @@ termp_it_pre(DECL_ARGS) break; } + p->flags = sv; /* Restore saved flags. */ + /* * If we're not going to process our children, indicate so here. */ @@ -1337,7 +1345,8 @@ termp_d1_pre(DECL_ARGS) if (MDOC_BLOCK != node->type) return(1); term_newln(p); - p->offset += (pair->offset = INDENT); + pair->offset = INDENT + 1; + p->offset += pair->offset; return(1); } @@ -2119,17 +2128,22 @@ termp_lk_pre(DECL_ARGS) assert(node->child); n = node->child; + if (NULL == n->next) { + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_LINK_ANCHOR]); + return(1); + } + p->flags |= ttypes[TTYPE_LINK_ANCHOR]; term_word(p, n->string); - p->flags &= ~ttypes[TTYPE_LINK_ANCHOR]; p->flags |= TERMP_NOSPACE; term_word(p, ":"); + p->flags &= ~ttypes[TTYPE_LINK_ANCHOR]; p->flags |= ttypes[TTYPE_LINK_TEXT]; - for ( ; n; n = n->next) + for (n = n->next; n; n = n->next) term_word(p, n->string); - p->flags &= ~ttypes[TTYPE_LINK_TEXT]; + p->flags &= ~ttypes[TTYPE_LINK_TEXT]; return(0); }