=================================================================== RCS file: /cvs/mandoc/mdoc_term.c,v retrieving revision 1.249 retrieving revision 1.261 diff -u -p -r1.249 -r1.261 --- mandoc/mdoc_term.c 2013/06/02 18:16:57 1.249 +++ mandoc/mdoc_term.c 2014/03/30 21:28:01 1.261 @@ -1,7 +1,8 @@ -/* $Id: mdoc_term.c,v 1.249 2013/06/02 18:16:57 schwarze Exp $ */ +/* $Id: mdoc_term.c,v 1.261 2014/03/30 21:28:01 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2010, 2012 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 */ }; @@ -307,13 +309,10 @@ print_mdoc_node(DECL_ARGS) /* * Keeps only work until the end of a line. If a keep was * invoked in a prior line, revert it to PREKEEP. - * - * Also let SYNPRETTY sections behave as if they were wrapped - * in a `Bk' block. */ - if (TERMP_KEEP & p->flags || MDOC_SYNPRETTY & n->flags) { - if (n->prev ? (n->prev->line != n->line) : + if (TERMP_KEEP & p->flags) { + if (n->prev ? (n->prev->lastline != n->line) : (n->parent && n->parent->line != n->line)) { p->flags &= ~TERMP_KEEP; p->flags |= TERMP_PREKEEP; @@ -321,16 +320,6 @@ print_mdoc_node(DECL_ARGS) } /* - * Since SYNPRETTY sections aren't "turned off" with `Ek', - * we have to intuit whether we should disable formatting. - */ - - if ( ! (MDOC_SYNPRETTY & n->flags) && - ((n->prev && MDOC_SYNPRETTY & n->prev->flags) || - (n->parent && MDOC_SYNPRETTY & n->parent->flags))) - p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP); - - /* * After the keep flags have been set up, we may now * produce output. Note that some pre-handlers do so. */ @@ -397,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; + } } @@ -424,6 +415,7 @@ print_mdoc_foot(struct termp *p, const void *arg) p->offset = 0; p->rmargin = (p->maxrmargin - term_strlen(p, meta->date) + term_len(p, 1)) / 2; + p->trailspace = 1; p->flags |= TERMP_NOSPACE | TERMP_NOBREAK; term_word(p, meta->os); @@ -438,6 +430,7 @@ print_mdoc_foot(struct termp *p, const void *arg) p->offset = p->rmargin; p->rmargin = p->maxrmargin; + p->trailspace = 0; p->flags &= ~TERMP_NOBREAK; p->flags |= TERMP_NOSPACE; @@ -489,6 +482,7 @@ print_mdoc_head(struct termp *p, const void *arg) titlen = term_strlen(p, title); p->flags |= TERMP_NOBREAK | TERMP_NOSPACE; + p->trailspace = 1; p->offset = 0; p->rmargin = 2 * (titlen+1) + buflen < p->maxrmargin ? (p->maxrmargin - @@ -507,6 +501,7 @@ print_mdoc_head(struct termp *p, const void *arg) term_flushln(p); p->flags &= ~TERMP_NOBREAK; + p->trailspace = 0; if (p->rmargin + titlen <= p->maxrmargin) { p->flags |= TERMP_NOSPACE; p->offset = p->rmargin; @@ -624,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; @@ -794,13 +799,13 @@ termp_it_pre(DECL_ARGS) case (LIST_dash): /* FALLTHROUGH */ case (LIST_hyphen): - if (MDOC_HEAD == n->type) - p->flags |= TERMP_NOBREAK; + if (MDOC_HEAD != n->type) + break; + p->flags |= TERMP_NOBREAK; + p->trailspace = 1; break; case (LIST_hang): - if (MDOC_HEAD == n->type) - p->flags |= TERMP_NOBREAK; - else + if (MDOC_HEAD != n->type) break; /* @@ -812,16 +817,18 @@ termp_it_pre(DECL_ARGS) if (n->next->child && (MDOC_Bl == n->next->child->tok || MDOC_Bd == n->next->child->tok)) - p->flags &= ~TERMP_NOBREAK; - else - p->flags |= TERMP_HANG; + break; + + p->flags |= TERMP_NOBREAK | TERMP_HANG; + p->trailspace = 1; break; case (LIST_tag): - if (MDOC_HEAD == n->type) - p->flags |= TERMP_NOBREAK | TERMP_TWOSPACE; - if (MDOC_HEAD != n->type) break; + + p->flags |= TERMP_NOBREAK; + p->trailspace = 2; + if (NULL == n->next || NULL == n->next->child) p->flags |= TERMP_DANGLE; break; @@ -829,15 +836,20 @@ termp_it_pre(DECL_ARGS) if (MDOC_HEAD == n->type) break; - if (NULL == n->next) + if (NULL == n->next) { p->flags &= ~TERMP_NOBREAK; - else + p->trailspace = 0; + } else { p->flags |= TERMP_NOBREAK; + p->trailspace = 1; + } break; case (LIST_diag): - if (MDOC_HEAD == n->type) - p->flags |= TERMP_NOBREAK; + if (MDOC_HEAD != n->type) + break; + p->flags |= TERMP_NOBREAK; + p->trailspace = 1; break; default: break; @@ -875,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); @@ -989,8 +1004,8 @@ termp_it_post(DECL_ARGS) p->flags &= ~TERMP_DANGLE; p->flags &= ~TERMP_NOBREAK; - p->flags &= ~TERMP_TWOSPACE; p->flags &= ~TERMP_HANG; + p->trailspace = 0; } @@ -999,8 +1014,10 @@ static int termp_nm_pre(DECL_ARGS) { - if (MDOC_BLOCK == n->type) + if (MDOC_BLOCK == n->type) { + p->flags |= TERMP_PREKEEP; return(1); + } if (MDOC_BODY == n->type) { if (NULL == n->child) @@ -1023,6 +1040,7 @@ termp_nm_pre(DECL_ARGS) if (MDOC_HEAD == n->type && n->next->child) { p->flags |= TERMP_NOSPACE | TERMP_NOBREAK; + p->trailspace = 1; p->rmargin = p->offset + term_len(p, 1); if (NULL == n->child) { p->rmargin += term_strlen(p, meta->name); @@ -1048,9 +1066,12 @@ static void termp_nm_post(DECL_ARGS) { - if (MDOC_HEAD == n->type && n->next->child) { + if (MDOC_BLOCK == n->type) { + 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->trailspace = 0; } else if (MDOC_BODY == n->type && n->child) term_flushln(p); } @@ -1525,6 +1546,7 @@ termp_ft_pre(DECL_ARGS) static int termp_fn_pre(DECL_ARGS) { + size_t rmargin = 0; int pretty; pretty = MDOC_SYNPRETTY & n->flags; @@ -1534,11 +1556,24 @@ termp_fn_pre(DECL_ARGS) if (NULL == (n = n->child)) return(0); + if (pretty) { + rmargin = p->rmargin; + p->rmargin = p->offset + term_len(p, 4); + p->flags |= TERMP_NOBREAK | TERMP_HANG; + } + assert(MDOC_TEXT == n->type); term_fontpush(p, TERMFONT_BOLD); term_word(p, n->string); term_fontpop(p); + if (pretty) { + term_flushln(p); + p->flags &= ~(TERMP_NOBREAK | TERMP_HANG); + p->offset = p->rmargin; + p->rmargin = rmargin; + } + p->flags |= TERMP_NOSPACE; term_word(p, "("); p->flags |= TERMP_NOSPACE; @@ -1546,6 +1581,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); @@ -1561,6 +1598,7 @@ termp_fn_pre(DECL_ARGS) if (pretty) { p->flags |= TERMP_NOSPACE; term_word(p, ";"); + term_flushln(p); } return(0); @@ -1580,20 +1618,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); } @@ -1768,16 +1802,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) { @@ -2025,16 +2049,31 @@ 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_HANG; + } p->flags |= TERMP_NOSPACE; term_word(p, "("); p->flags |= TERMP_NOSPACE; + if (pretty) { + term_flushln(p); + p->flags &= ~(TERMP_NOBREAK | TERMP_HANG); + p->offset = p->rmargin; + p->rmargin = rmargin; + } return(1); - } + } if (NULL == n->child) return(0); @@ -2062,6 +2101,7 @@ termp_fo_post(DECL_ARGS) if (MDOC_SYNPRETTY & n->flags) { p->flags |= TERMP_NOSPACE; term_word(p, ";"); + term_flushln(p); } } @@ -2211,7 +2251,7 @@ static void termp_bk_post(DECL_ARGS) { - if (MDOC_BODY == n->type && ! (MDOC_SYNPRETTY & n->flags)) + if (MDOC_BODY == n->type) p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP); }