=================================================================== RCS file: /cvs/mandoc/mdoc_term.c,v retrieving revision 1.113 retrieving revision 1.122 diff -u -p -r1.113 -r1.122 --- mandoc/mdoc_term.c 2010/04/03 14:25:12 1.113 +++ mandoc/mdoc_term.c 2010/05/13 06:22:11 1.122 @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.113 2010/04/03 14:25:12 kristaps Exp $ */ +/* $Id: mdoc_term.c,v 1.122 2010/05/13 06:22:11 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -58,6 +59,7 @@ static int arg_hasattr(int, const struct mdoc_node * static int arg_getattrs(const int *, int *, size_t, const struct mdoc_node *); static int arg_getattr(int, const struct mdoc_node *); +static int arg_disptype(const struct mdoc_node *); static int arg_listtype(const struct mdoc_node *); static void print_bvspace(struct termp *, const struct mdoc_node *, @@ -93,12 +95,12 @@ static void termp_sq_post(DECL_ARGS); static void termp_ss_post(DECL_ARGS); static void termp_vt_post(DECL_ARGS); -static int termp__t_pre(DECL_ARGS); static int termp_an_pre(DECL_ARGS); static int termp_ap_pre(DECL_ARGS); static int termp_aq_pre(DECL_ARGS); static int termp_bd_pre(DECL_ARGS); static int termp_bf_pre(DECL_ARGS); +static int termp_bl_pre(DECL_ARGS); static int termp_bold_pre(DECL_ARGS); static int termp_bq_pre(DECL_ARGS); static int termp_brq_pre(DECL_ARGS); @@ -148,7 +150,7 @@ static const struct termact termacts[MDOC_MAX] = { { termp_d1_pre, termp_d1_post }, /* Dl */ { termp_bd_pre, termp_bd_post }, /* Bd */ { NULL, NULL }, /* Ed */ - { NULL, termp_bl_post }, /* Bl */ + { termp_bl_pre, termp_bl_post }, /* Bl */ { NULL, NULL }, /* El */ { termp_it_pre, termp_it_post }, /* It */ { NULL, NULL }, /* Ad */ @@ -187,7 +189,7 @@ static const struct termact termacts[MDOC_MAX] = { { NULL, termp____post }, /* %O */ { NULL, termp____post }, /* %P */ { NULL, termp____post }, /* %R */ - { termp__t_pre, termp____post }, /* %T */ + { termp_under_pre, termp____post }, /* %T */ { NULL, termp____post }, /* %V */ { NULL, NULL }, /* Ac */ { termp_aq_pre, termp_aq_post }, /* Ao */ @@ -335,6 +337,9 @@ print_mdoc_node(DECL_ARGS) if (termacts[n->tok].post) (*termacts[n->tok].post)(p, &npair, m, n); + if (MDOC_EOS & n->flags) + p->flags |= TERMP_SENTENCE; + p->offset = offset; p->rmargin = rmargin; } @@ -478,6 +483,35 @@ a2width(const struct mdoc_argv *arg, int pos) static int +arg_disptype(const struct mdoc_node *n) +{ + int i, len; + + assert(MDOC_BLOCK == n->type); + + len = (int)(n->args ? n->args->argc : 0); + + for (i = 0; i < len; i++) + switch (n->args->argv[i].arg) { + case (MDOC_Centred): + /* FALLTHROUGH */ + case (MDOC_Ragged): + /* FALLTHROUGH */ + case (MDOC_Filled): + /* FALLTHROUGH */ + case (MDOC_Unfilled): + /* FALLTHROUGH */ + case (MDOC_Literal): + return(n->args->argv[i].arg); + default: + break; + } + + return(-1); +} + + +static int arg_listtype(const struct mdoc_node *n) { int i, len; @@ -1051,7 +1085,7 @@ static int termp_nm_pre(DECL_ARGS) { - if (SEC_SYNOPSIS == n->sec) + if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags) term_newln(p); term_fontpush(p, TERMFONT_BOLD); @@ -1070,10 +1104,10 @@ termp_fl_pre(DECL_ARGS) term_fontpush(p, TERMFONT_BOLD); term_word(p, "\\-"); - /* A blank `Fl' should incur a subsequent space. */ - if (n->child) p->flags |= TERMP_NOSPACE; + else if (n->next && n->next->line == n->line) + p->flags |= TERMP_NOSPACE; return(1); } @@ -1126,7 +1160,7 @@ termp_an_post(DECL_ARGS) return; } - if (arg_getattr(MDOC_Split, n) > -1) { + if (arg_hasattr(MDOC_Split, n)) { p->flags &= ~TERMP_NOSPLIT; p->flags |= TERMP_SPLIT; } else { @@ -1250,6 +1284,15 @@ termp_nd_pre(DECL_ARGS) /* ARGSUSED */ +static int +termp_bl_pre(DECL_ARGS) +{ + + return(MDOC_HEAD != n->type); +} + + +/* ARGSUSED */ static void termp_bl_post(DECL_ARGS) { @@ -1341,7 +1384,7 @@ static void termp_fd_post(DECL_ARGS) { - if (n->sec != SEC_SYNOPSIS) + if (n->sec != SEC_SYNOPSIS || ! (MDOC_LINE & n->flags)) return; term_newln(p); @@ -1428,7 +1471,7 @@ static void termp_lb_post(DECL_ARGS) { - if (SEC_LIBRARY == n->sec) + if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags) term_newln(p); } @@ -1497,7 +1540,7 @@ static int termp_ft_pre(DECL_ARGS) { - if (SEC_SYNOPSIS == n->sec) + if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags) if (n->prev && MDOC_Fo == n->prev->tok) term_vspace(p); @@ -1511,7 +1554,7 @@ static void termp_ft_post(DECL_ARGS) { - if (SEC_SYNOPSIS == n->sec) + if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags) term_newln(p); } @@ -1552,7 +1595,7 @@ static void termp_fn_post(DECL_ARGS) { - if (n->sec == SEC_SYNOPSIS && n->next) + if (n->sec == SEC_SYNOPSIS && n->next && MDOC_LINE & n->flags) term_vspace(p); } @@ -1589,37 +1632,23 @@ static int termp_bd_pre(DECL_ARGS) { int i, type; + size_t rm, rmax; const struct mdoc_node *nn; if (MDOC_BLOCK == n->type) { print_bvspace(p, n, n); return(1); - } else if (MDOC_BODY != n->type) - return(1); + } else if (MDOC_HEAD == n->type) + return(0); nn = n->parent; - for (type = -1, i = 0; i < (int)nn->args->argc; i++) { - switch (nn->args->argv[i].arg) { - case (MDOC_Centred): - /* FALLTHROUGH */ - case (MDOC_Ragged): - /* FALLTHROUGH */ - case (MDOC_Filled): - /* FALLTHROUGH */ - case (MDOC_Unfilled): - /* FALLTHROUGH */ - case (MDOC_Literal): - type = nn->args->argv[i].arg; - break; - case (MDOC_Offset): - p->offset += a2offs(&nn->args->argv[i]); - break; - default: - break; - } - } + type = arg_disptype(nn); + assert(-1 != type); + if (-1 != (i = arg_getattr(MDOC_Offset, nn))) + p->offset += a2offs(&nn->args->argv[i]); + /* * If -ragged or -filled are specified, the block does nothing * but change the indentation. If -unfilled or -literal are @@ -1628,10 +1657,13 @@ termp_bd_pre(DECL_ARGS) * lines are allowed. */ - assert(type > -1); if (MDOC_Literal != type && MDOC_Unfilled != type) return(1); + rm = p->rmargin; + rmax = p->maxrmargin; + p->rmargin = p->maxrmargin = TERM_MAXMARGIN; + for (nn = n->child; nn; nn = nn->next) { p->flags |= TERMP_NOSPACE; print_mdoc_node(p, pair, m, nn); @@ -1643,6 +1675,8 @@ termp_bd_pre(DECL_ARGS) term_flushln(p); } + p->rmargin = rm; + p->maxrmargin = rmax; return(0); } @@ -1651,11 +1685,26 @@ termp_bd_pre(DECL_ARGS) static void termp_bd_post(DECL_ARGS) { + int type; + size_t rm, rmax; if (MDOC_BODY != n->type) return; + + type = arg_disptype(n->parent); + assert(-1 != type); + + rm = p->rmargin; + rmax = p->maxrmargin; + + if (MDOC_Literal == type || MDOC_Unfilled == type) + p->rmargin = p->maxrmargin = TERM_MAXMARGIN; + p->flags |= TERMP_NOSPACE; term_flushln(p); + + p->rmargin = rm; + p->maxrmargin = rmax; } @@ -1845,7 +1894,7 @@ termp_in_post(DECL_ARGS) term_word(p, ">"); term_fontpop(p); - if (SEC_SYNOPSIS != n->sec) + if (SEC_SYNOPSIS != n->sec && ! (MDOC_LINE & n->flags)) return; term_newln(p); @@ -2070,14 +2119,6 @@ termp____post(DECL_ARGS) /* TODO: %U. */ p->flags |= TERMP_NOSPACE; - switch (n->tok) { - case (MDOC__T): - term_word(p, "\\(rq"); - p->flags |= TERMP_NOSPACE; - break; - default: - break; - } term_word(p, n->next ? "," : "."); } @@ -2125,16 +2166,5 @@ termp_under_pre(DECL_ARGS) { term_fontpush(p, TERMFONT_UNDER); - return(1); -} - - -/* ARGSUSED */ -static int -termp__t_pre(DECL_ARGS) -{ - - term_word(p, "\\(lq"); - p->flags |= TERMP_NOSPACE; return(1); }