=================================================================== RCS file: /cvs/mandoc/mdoc_term.c,v retrieving revision 1.253 retrieving revision 1.263 diff -u -p -r1.253 -r1.263 --- mandoc/mdoc_term.c 2013/12/24 20:45:27 1.253 +++ mandoc/mdoc_term.c 2014/04/08 07:13:12 1.263 @@ -1,7 +1,8 @@ -/* $Id: mdoc_term.c,v 1.253 2013/12/24 20:45:27 schwarze Exp $ */ +/* $Id: mdoc_term.c,v 1.263 2014/04/08 07:13:12 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2010, 2012, 2013 Ingo Schwarze + * Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze + * Copyright (c) 2013 Franco Fichtner * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -100,10 +101,10 @@ static int termp_fl_pre(DECL_ARGS); static int termp_fn_pre(DECL_ARGS); static int termp_fo_pre(DECL_ARGS); static int termp_ft_pre(DECL_ARGS); -static int termp_igndelim_pre(DECL_ARGS); static int termp_in_pre(DECL_ARGS); static int termp_it_pre(DECL_ARGS); static int termp_li_pre(DECL_ARGS); +static int termp_ll_pre(DECL_ARGS); static int termp_lk_pre(DECL_ARGS); static int termp_nd_pre(DECL_ARGS); static int termp_nm_pre(DECL_ARGS); @@ -194,12 +195,12 @@ static const struct termact termacts[MDOC_MAX] = { { termp_quote_pre, termp_quote_post }, /* Eo */ { termp_xx_pre, NULL }, /* Fx */ { termp_bold_pre, NULL }, /* Ms */ - { termp_igndelim_pre, NULL }, /* No */ + { NULL, NULL }, /* No */ { termp_ns_pre, NULL }, /* Ns */ { termp_xx_pre, NULL }, /* Nx */ { termp_xx_pre, NULL }, /* Ox */ { NULL, NULL }, /* Pc */ - { termp_igndelim_pre, termp_pf_post }, /* Pf */ + { NULL, termp_pf_post }, /* Pf */ { termp_quote_pre, termp_quote_post }, /* Po */ { termp_quote_pre, termp_quote_post }, /* Pq */ { NULL, NULL }, /* Qc */ @@ -244,6 +245,7 @@ static const struct termact termacts[MDOC_MAX] = { { termp_sp_pre, NULL }, /* sp */ { NULL, termp____post }, /* %U */ { NULL, NULL }, /* Ta */ + { termp_ll_pre, NULL }, /* ll */ }; @@ -384,8 +386,10 @@ print_mdoc_node(DECL_ARGS) if (MDOC_EOS & n->flags) p->flags |= TERMP_SENTENCE; - p->offset = offset; - p->rmargin = rmargin; + if (MDOC_ll != n->tok) { + p->offset = offset; + p->rmargin = rmargin; + } } @@ -615,6 +619,16 @@ print_bvspace(struct termp *p, /* ARGSUSED */ static int +termp_ll_pre(DECL_ARGS) +{ + + term_setwidth(p, n->nchild ? n->child->string : NULL); + return(0); +} + + +/* ARGSUSED */ +static int termp_it_pre(DECL_ARGS) { const struct mdoc_node *bl, *nn; @@ -805,14 +819,14 @@ termp_it_pre(DECL_ARGS) MDOC_Bd == n->next->child->tok)) break; - p->flags |= TERMP_NOBREAK | TERMP_HANG; + p->flags |= TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG; p->trailspace = 1; break; case (LIST_tag): if (MDOC_HEAD != n->type) break; - p->flags |= TERMP_NOBREAK; + p->flags |= TERMP_NOBREAK | TERMP_BRIND; p->trailspace = 2; if (NULL == n->next || NULL == n->next->child) @@ -834,7 +848,7 @@ termp_it_pre(DECL_ARGS) case (LIST_diag): if (MDOC_HEAD != n->type) break; - p->flags |= TERMP_NOBREAK; + p->flags |= TERMP_NOBREAK | TERMP_BRIND; p->trailspace = 1; break; default: @@ -873,8 +887,11 @@ termp_it_pre(DECL_ARGS) assert(width); if (MDOC_HEAD == n->type) p->rmargin = p->offset + width; - else + else { p->offset += width; + if (p->rmargin < p->offset) + p->rmargin = p->offset; + } break; case (LIST_column): assert(width); @@ -985,9 +1002,8 @@ termp_it_post(DECL_ARGS) * has munged them in the meanwhile. */ - p->flags &= ~TERMP_DANGLE; - p->flags &= ~TERMP_NOBREAK; - p->flags &= ~TERMP_HANG; + p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND | + TERMP_DANGLE | TERMP_HANG); p->trailspace = 0; } @@ -1012,6 +1028,8 @@ termp_nm_pre(DECL_ARGS) MDOC_TEXT == n->prev->child->type ? term_strlen(p, n->prev->child->string) : term_len(p, 5)); + if (p->rmargin < p->offset) + p->rmargin = p->offset; return(1); } @@ -1022,7 +1040,7 @@ termp_nm_pre(DECL_ARGS) synopsis_pre(p, n->parent); if (MDOC_HEAD == n->type && n->next->child) { - p->flags |= TERMP_NOSPACE | TERMP_NOBREAK; + p->flags |= TERMP_NOSPACE | TERMP_NOBREAK | TERMP_BRIND; p->trailspace = 1; p->rmargin = p->offset + term_len(p, 1); if (NULL == n->child) { @@ -1053,7 +1071,7 @@ termp_nm_post(DECL_ARGS) p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP); } else if (MDOC_HEAD == n->type && n->next->child) { term_flushln(p); - p->flags &= ~(TERMP_NOBREAK | TERMP_HANG); + p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG); p->trailspace = 0; } else if (MDOC_BODY == n->type && n->child) term_flushln(p); @@ -1529,7 +1547,7 @@ termp_ft_pre(DECL_ARGS) static int termp_fn_pre(DECL_ARGS) { - size_t width, rmargin = 0; + size_t rmargin = 0; int pretty; pretty = MDOC_SYNPRETTY & n->flags; @@ -1540,10 +1558,9 @@ termp_fn_pre(DECL_ARGS) return(0); if (pretty) { - width = term_len(p, 4); rmargin = p->rmargin; - p->rmargin = p->offset + width; - p->flags |= TERMP_NOBREAK | TERMP_HANG; + p->rmargin = p->offset + term_len(p, 4); + p->flags |= TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG; } assert(MDOC_TEXT == n->type); @@ -1553,7 +1570,7 @@ termp_fn_pre(DECL_ARGS) if (pretty) { term_flushln(p); - p->flags &= ~(TERMP_NOBREAK | TERMP_HANG); + p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG); p->offset = p->rmargin; p->rmargin = rmargin; } @@ -1565,6 +1582,8 @@ termp_fn_pre(DECL_ARGS) for (n = n->next; n; n = n->next) { assert(MDOC_TEXT == n->type); term_fontpush(p, TERMFONT_UNDER); + if (pretty) + p->flags |= TERMP_NBRWORD; term_word(p, n->string); term_fontpop(p); @@ -1600,20 +1619,16 @@ termp_fa_pre(DECL_ARGS) for (nn = n->child; nn; nn = nn->next) { term_fontpush(p, TERMFONT_UNDER); + p->flags |= TERMP_NBRWORD; term_word(p, nn->string); term_fontpop(p); - if (nn->next) { + if (nn->next || (n->next && n->next->tok == MDOC_Fa)) { p->flags |= TERMP_NOSPACE; term_word(p, ","); } } - if (n->child && n->next && n->next->tok == MDOC_Fa) { - p->flags |= TERMP_NOSPACE; - term_word(p, ","); - } - return(0); } @@ -1788,16 +1803,6 @@ termp_xx_pre(DECL_ARGS) /* ARGSUSED */ -static int -termp_igndelim_pre(DECL_ARGS) -{ - - p->flags |= TERMP_IGNDELIM; - return(1); -} - - -/* ARGSUSED */ static void termp_pf_post(DECL_ARGS) { @@ -2045,16 +2050,33 @@ termp_quote_post(DECL_ARGS) static int termp_fo_pre(DECL_ARGS) { + size_t rmargin = 0; + int pretty; + pretty = MDOC_SYNPRETTY & n->flags; + if (MDOC_BLOCK == n->type) { synopsis_pre(p, n); return(1); } else if (MDOC_BODY == n->type) { + if (pretty) { + rmargin = p->rmargin; + p->rmargin = p->offset + term_len(p, 4); + p->flags |= TERMP_NOBREAK | TERMP_BRIND | + TERMP_HANG; + } p->flags |= TERMP_NOSPACE; term_word(p, "("); p->flags |= TERMP_NOSPACE; + if (pretty) { + term_flushln(p); + p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND | + TERMP_HANG); + p->offset = p->rmargin; + p->rmargin = rmargin; + } return(1); - } + } if (NULL == n->child) return(0); @@ -2082,6 +2104,7 @@ termp_fo_post(DECL_ARGS) if (MDOC_SYNPRETTY & n->flags) { p->flags |= TERMP_NOSPACE; term_word(p, ";"); + term_flushln(p); } }