=================================================================== RCS file: /cvs/mandoc/mdoc_man.c,v retrieving revision 1.102 retrieving revision 1.108 diff -u -p -r1.102 -r1.108 --- mandoc/mdoc_man.c 2017/02/06 03:44:58 1.102 +++ mandoc/mdoc_man.c 2017/04/17 13:26:47 1.108 @@ -1,4 +1,4 @@ -/* $Id: mdoc_man.c,v 1.102 2017/02/06 03:44:58 schwarze Exp $ */ +/* $Id: mdoc_man.c,v 1.108 2017/04/17 13:26:47 schwarze Exp $ */ /* * Copyright (c) 2011-2017 Ingo Schwarze * @@ -44,6 +44,7 @@ static int cond_body(DECL_ARGS); static int cond_head(DECL_ARGS); static void font_push(char); static void font_pop(void); +static int man_strlen(const char *); static void mid_it(void); static void post__t(DECL_ARGS); static void post_aq(DECL_ARGS); @@ -274,6 +275,49 @@ static struct { } fontqueue; +static int +man_strlen(const char *cp) +{ + size_t rsz; + int skip, sz; + + sz = 0; + skip = 0; + for (;;) { + rsz = strcspn(cp, "\\"); + if (rsz) { + cp += rsz; + if (skip) { + skip = 0; + rsz--; + } + sz += rsz; + } + if ('\0' == *cp) + break; + cp++; + switch (mandoc_escape(&cp, NULL, NULL)) { + case ESCAPE_ERROR: + return sz; + case ESCAPE_UNICODE: + case ESCAPE_NUMBERED: + case ESCAPE_SPECIAL: + case ESCAPE_OVERSTRIKE: + if (skip) + skip = 0; + else + sz++; + break; + case ESCAPE_SKIPCHAR: + skip = 1; + break; + default: + break; + } + } + return sz; +} + static void font_push(char newfont) { @@ -447,7 +491,7 @@ print_offs(const char *v, int keywords) return; } } else - sz = strlen(v); + sz = man_strlen(v); /* * We are inside an enclosing list. @@ -485,13 +529,13 @@ print_width(const struct mdoc_bl *bl, const struct rof numeric = 0; } } else - sz = strlen(bl->width); + sz = man_strlen(bl->width); /* XXX Rough estimation, might have multiple parts. */ if (bl->type == LIST_enum) chsz = (bl->count > 8) + 1; else if (child != NULL && child->type == ROFFT_TEXT) - chsz = strlen(child->string); + chsz = man_strlen(child->string); else chsz = 0; @@ -639,9 +683,6 @@ print_node(DECL_ARGS) if (ENDBODY_NOT != n->end) n->body->flags |= NODE_ENDED; - - if (ENDBODY_NOSPACE == n->end) - outflags &= ~(MMAN_spc | MMAN_nl); } static int @@ -718,10 +759,8 @@ static int pre__t(DECL_ARGS) { - if (n->parent && MDOC_Rs == n->parent->tok && - n->parent->norm->Rs.quote_T) { - print_word(""); - putchar('\"'); + if (n->parent->tok == MDOC_Rs && n->parent->norm->Rs.quote_T) { + print_word("\\(lq"); outflags &= ~MMAN_spc; } else font_push('I'); @@ -732,11 +771,9 @@ static void post__t(DECL_ARGS) { - if (n->parent && MDOC_Rs == n->parent->tok && - n->parent->norm->Rs.quote_T) { + if (n->parent->tok == MDOC_Rs && n->parent->norm->Rs.quote_T) { outflags &= ~MMAN_spc; - print_word(""); - putchar('\"'); + print_word("\\(rq"); } else font_pop(); post_percent(meta, n); @@ -1471,23 +1508,40 @@ static int pre_lk(DECL_ARGS) { const struct roff_node *link, *descr; + int display; - if (NULL == (link = n->child)) + if ((link = n->child) == NULL) return 0; - if (NULL != (descr = link->next)) { + /* Link text. */ + if ((descr = link->next) != NULL && !(descr->flags & NODE_DELIMC)) { font_push('I'); - while (NULL != descr) { + while (descr != NULL && !(descr->flags & NODE_DELIMC)) { print_word(descr->string); descr = descr->next; } - print_word(":"); font_pop(); + print_word(":"); } + /* Link target. */ + display = man_strlen(link->string) >= 26; + if (display) { + print_line(".RS", MMAN_Bk_susp); + print_word("6n"); + outflags |= MMAN_nl; + } font_push('B'); print_word(link->string); font_pop(); + + /* Trailing punctuation. */ + while (descr != NULL) { + print_word(descr->string); + descr = descr->next; + } + if (display) + print_line(".RE", MMAN_nl); return 0; } @@ -1525,7 +1579,7 @@ pre_nm(DECL_ARGS) if (NULL == n->parent->prev) outflags |= MMAN_sp; print_block(".HP", 0); - printf(" %zun", strlen(name) + 1); + printf(" %dn", man_strlen(name) + 1); outflags |= MMAN_nl; } font_push('B');