X-Git-Url: https://git.cameronkatri.com/mandoc.git/blobdiff_plain/127029dfaf617f304350eb1202db85c428fda879..385a2d9a12f28a334c3d74170511b5200d6166f7:/man_term.c?ds=inline diff --git a/man_term.c b/man_term.c index fbd1c5d2..f9a02fda 100644 --- a/man_term.c +++ b/man_term.c @@ -1,6 +1,6 @@ -/* $Id: man_term.c,v 1.79 2010/07/07 15:04:54 kristaps Exp $ */ +/* $Id: man_term.c,v 1.85 2010/09/15 14:36:16 kristaps Exp $ */ /* - * Copyright (c) 2008, 2009 Kristaps Dzonsons + * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -92,10 +92,9 @@ static int pre_RS(DECL_ARGS); static int pre_SH(DECL_ARGS); static int pre_SS(DECL_ARGS); static int pre_TP(DECL_ARGS); -static int pre_br(DECL_ARGS); -static int pre_fi(DECL_ARGS); static int pre_ign(DECL_ARGS); -static int pre_nf(DECL_ARGS); +static int pre_in(DECL_ARGS); +static int pre_literal(DECL_ARGS); static int pre_sp(DECL_ARGS); static void post_IP(DECL_ARGS); @@ -106,7 +105,7 @@ static void post_SS(DECL_ARGS); static void post_TP(DECL_ARGS); static const struct termact termacts[MAN_MAX] = { - { pre_br, NULL, MAN_NOTEXT }, /* br */ + { pre_sp, NULL, MAN_NOTEXT }, /* br */ { NULL, NULL, 0 }, /* TH */ { pre_SH, post_SH, 0 }, /* SH */ { pre_SS, post_SS, 0 }, /* SS */ @@ -130,8 +129,8 @@ static const struct termact termacts[MAN_MAX] = { { NULL, NULL, MAN_NOTEXT }, /* na */ { pre_I, NULL, 0 }, /* i */ { pre_sp, NULL, MAN_NOTEXT }, /* sp */ - { pre_nf, NULL, 0 }, /* nf */ - { pre_fi, NULL, 0 }, /* fi */ + { pre_literal, NULL, 0 }, /* nf */ + { pre_literal, NULL, 0 }, /* fi */ { NULL, NULL, 0 }, /* r */ { NULL, NULL, 0 }, /* RE */ { pre_RS, post_RS, 0 }, /* RS */ @@ -139,9 +138,10 @@ static const struct termact termacts[MAN_MAX] = { { pre_ign, NULL, 0 }, /* UC */ { pre_ign, NULL, 0 }, /* PD */ { pre_sp, NULL, MAN_NOTEXT }, /* Sp */ - { pre_nf, NULL, 0 }, /* Vb */ - { pre_fi, NULL, 0 }, /* Ve */ + { pre_literal, NULL, 0 }, /* Vb */ + { pre_literal, NULL, 0 }, /* Ve */ { pre_ign, NULL, 0 }, /* AT */ + { pre_in, NULL, MAN_NOTEXT }, /* in */ }; @@ -249,23 +249,25 @@ pre_I(DECL_ARGS) /* ARGSUSED */ static int -pre_fi(DECL_ARGS) +pre_literal(DECL_ARGS) { - mt->fl &= ~MANT_LITERAL; + term_newln(p); + switch (n->tok) { + case (MAN_Vb): + /* FALLTHROUGH */ + case (MAN_nf): + mt->fl |= MANT_LITERAL; + return(MAN_Vb != n->tok); + default: + mt->fl &= ~MANT_LITERAL; + break; + } + return(1); } -/* ARGSUSED */ -static int -pre_nf(DECL_ARGS) -{ - - mt->fl |= MANT_LITERAL; - return(MAN_Vb != n->tok); -} - /* ARGSUSED */ static int @@ -353,17 +355,40 @@ pre_B(DECL_ARGS) /* ARGSUSED */ static int -pre_sp(DECL_ARGS) +pre_in(DECL_ARGS) { - size_t i, len; + int len, less; + size_t v; + const char *cp; - len = n->child ? - a2height(p, n->child->string) : term_len(p, 1); + term_newln(p); - if (0 == len) - term_newln(p); - for (i = 0; i <= len; i++) - term_vspace(p); + if (NULL == n->child) { + p->offset = mt->offset; + return(0); + } + + cp = n->child->string; + less = 0; + + if ('-' == *cp) + less = -1; + else if ('+' == *cp) + less = 1; + else + cp--; + + if ((len = a2width(p, ++cp)) < 0) + return(0); + + v = (size_t)len; + + if (less < 0) + p->offset -= p->offset > v ? v : p->offset; + else if (less > 0) + p->offset += v; + else + p->offset = v; return(0); } @@ -371,10 +396,24 @@ pre_sp(DECL_ARGS) /* ARGSUSED */ static int -pre_br(DECL_ARGS) +pre_sp(DECL_ARGS) { + size_t i, len; + + switch (n->tok) { + case (MAN_br): + len = 0; + break; + default: + len = n->child ? a2height(p, n->child->string) : 1; + break; + } + + if (0 == len) + term_newln(p); + for (i = 0; i < len; i++) + term_vspace(p); - term_newln(p); return(0); } @@ -877,6 +916,10 @@ print_man_foot(struct termp *p, const void *arg) p->rmargin = p->maxrmargin - term_strlen(p, buf); p->offset = 0; + /* term_strlen() can return zero. */ + if (p->rmargin == p->maxrmargin) + p->rmargin--; + if (meta->source) term_word(p, meta->source); if (meta->source)