=================================================================== RCS file: /cvs/mandoc/mdoc_man.c,v retrieving revision 1.30 retrieving revision 1.33 diff -u -p -r1.30 -r1.33 --- mandoc/mdoc_man.c 2012/07/10 14:38:51 1.30 +++ mandoc/mdoc_man.c 2012/07/11 16:19:08 1.33 @@ -1,4 +1,4 @@ -/* $Id: mdoc_man.c,v 1.30 2012/07/10 14:38:51 schwarze Exp $ */ +/* $Id: mdoc_man.c,v 1.33 2012/07/11 16:19:08 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Ingo Schwarze * @@ -100,7 +100,7 @@ static int pre_ux(DECL_ARGS); static int pre_xr(DECL_ARGS); static void print_word(const char *); static void print_offs(const char *); -static void print_width(const char *); +static void print_width(const char *, const struct mdoc_node *); static void print_count(int *); static void print_node(DECL_ARGS); @@ -360,22 +360,34 @@ print_offs(const char *v) } void -print_width(const char *v) +print_width(const char *v, const struct mdoc_node *child) { char buf[24]; struct roffsu su; - size_t sz; + size_t sz, chsz; + /* XXX Rough estimation, might have multiple parts. */ + chsz = (NULL != child && MDOC_TEXT == child->type) ? + strlen(child->string) : 0; + if (a2roffsu(v, &su, SCALE_MAX)) { if (SCALE_EN == su.unit) sz = su.scale; else { + if (chsz) + print_word(".HP"); + else + print_word(".TP"); print_word(v); return; } } else sz = strlen(v); + if (chsz > sz) + print_word(".HP"); + else + print_word(".TP"); snprintf(buf, sizeof(buf), "%ldn", sz + 2); print_word(buf); } @@ -742,9 +754,24 @@ post_bk(DECL_ARGS) static int pre_bl(DECL_ARGS) { + size_t icol; - if (LIST_enum == n->norm->Bl.type) + switch (n->norm->Bl.type) { + case (LIST_enum): n->norm->Bl.count = 0; + return(1); + case (LIST_column): + break; + default: + return(1); + } + + outflags |= MMAN_nl; + print_word(".TS"); + outflags |= MMAN_nl; + for (icol = 0; icol < n->norm->Bl.ncols; icol++) + print_word("l"); + print_word("."); return(1); } @@ -752,8 +779,18 @@ static void post_bl(DECL_ARGS) { - if (LIST_enum == n->norm->Bl.type) + switch (n->norm->Bl.type) { + case (LIST_enum): n->norm->Bl.count = 0; + break; + case (LIST_column): + outflags |= MMAN_nl; + print_word(".TE"); + break; + default: + break; + } + outflags |= MMAN_br; } static int @@ -1027,8 +1064,7 @@ pre_it(DECL_ARGS) case (LIST_dash): /* FALLTHROUGH */ case (LIST_hyphen): - print_word(".TP"); - print_width(bln->norm->Bl.width); + print_width(bln->norm->Bl.width, NULL); outflags |= MMAN_nl; font_push('B'); if (LIST_bullet == bln->norm->Bl.type) @@ -1038,16 +1074,18 @@ pre_it(DECL_ARGS) font_pop(); break; case (LIST_enum): - print_word(".TP"); - print_width(bln->norm->Bl.width); + print_width(bln->norm->Bl.width, NULL); outflags |= MMAN_nl; print_count(&bln->norm->Bl.count); - outflags |= MMAN_nl; break; - default: - if (bln->norm->Bl.width) - print_width(bln->norm->Bl.width); + case (LIST_hang): + print_width(bln->norm->Bl.width, n->child); break; + case (LIST_tag): + print_width(bln->norm->Bl.width, NULL); + break; + default: + return(1); } outflags |= MMAN_nl; default: @@ -1061,8 +1099,10 @@ post_it(DECL_ARGS) { const struct mdoc_node *bln; - if (MDOC_HEAD == n->type) { - bln = n->parent->parent; + bln = n->parent->parent; + + switch (n->type) { + case (MDOC_HEAD): switch (bln->norm->Bl.type) { case (LIST_diag): outflags &= ~MMAN_spc; @@ -1074,6 +1114,16 @@ post_it(DECL_ARGS) default: break; } + break; + case (MDOC_BODY): + if (LIST_column == bln->norm->Bl.type && + NULL != n->next) { + putchar('\t'); + outflags &= ~MMAN_spc; + } + break; + default: + break; } }