=================================================================== RCS file: /cvs/mandoc/man_term.c,v retrieving revision 1.163 retrieving revision 1.168 diff -u -p -r1.163 -r1.168 --- mandoc/man_term.c 2014/12/23 13:48:57 1.163 +++ mandoc/man_term.c 2015/01/30 22:04:44 1.168 @@ -1,7 +1,7 @@ -/* $Id: man_term.c,v 1.163 2014/12/23 13:48:57 schwarze Exp $ */ +/* $Id: man_term.c,v 1.168 2015/01/30 22:04:44 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons - * Copyright (c) 2010-2014 Ingo Schwarze + * Copyright (c) 2010-2015 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -46,7 +47,7 @@ struct mtermp { #define DECL_ARGS struct termp *p, \ struct mtermp *mt, \ - const struct man_node *n, \ + struct man_node *n, \ const struct man_meta *meta struct termact { @@ -113,7 +114,6 @@ static const struct termact termacts[MAN_MAX] = { { pre_I, NULL, 0 }, /* I */ { pre_alternate, NULL, 0 }, /* IR */ { pre_alternate, NULL, 0 }, /* RI */ - { pre_ign, NULL, MAN_NOTEXT }, /* na */ { pre_sp, NULL, MAN_NOTEXT }, /* sp */ { pre_literal, NULL, 0 }, /* nf */ { pre_literal, NULL, 0 }, /* fi */ @@ -279,7 +279,7 @@ static int pre_alternate(DECL_ARGS) { enum termfont font[2]; - const struct man_node *nn; + struct man_node *nn; int savelit, i; switch (n->tok) { @@ -432,6 +432,8 @@ pre_in(DECL_ARGS) p->offset += v; else p->offset = v; + if (p->offset > SHRT_MAX) + p->offset = term_len(p, p->defindent); return(0); } @@ -508,16 +510,16 @@ pre_HP(DECL_ARGS) if ((nn = n->parent->head->child) != NULL && a2roffsu(nn->string, &su, SCALE_EN)) { len = term_hspan(p, &su); + if (len < 0 && (size_t)(-len) > mt->offset) + len = -mt->offset; + else if (len > SHRT_MAX) + len = term_len(p, p->defindent); mt->lmargin[mt->lmargincur] = len; } else len = mt->lmargin[mt->lmargincur]; p->offset = mt->offset; - if (len > 0 || (size_t)(-len) < mt->offset) - p->rmargin = mt->offset + len; - else - p->rmargin = 0; - + p->rmargin = mt->offset + len; return(1); } @@ -582,9 +584,11 @@ pre_IP(DECL_ARGS) (nn = nn->next) != NULL && a2roffsu(nn->string, &su, SCALE_EN)) { len = term_hspan(p, &su); - mt->lmargin[mt->lmargincur] = len; if (len < 0 && (size_t)(-len) > mt->offset) len = -mt->offset; + else if (len > SHRT_MAX) + len = term_len(p, p->defindent); + mt->lmargin[mt->lmargincur] = len; } else len = mt->lmargin[mt->lmargincur]; @@ -638,7 +642,7 @@ static int pre_TP(DECL_ARGS) { struct roffsu su; - const struct man_node *nn; + struct man_node *nn; int len, savelit; switch (n->type) { @@ -662,9 +666,11 @@ pre_TP(DECL_ARGS) nn->string != NULL && ! (MAN_LINE & nn->flags) && a2roffsu(nn->string, &su, SCALE_EN)) { len = term_hspan(p, &su); - mt->lmargin[mt->lmargincur] = len; if (len < 0 && (size_t)(-len) > mt->offset) len = -mt->offset; + else if (len > SHRT_MAX) + len = term_len(p, p->defindent); + mt->lmargin[mt->lmargincur] = len; } else len = mt->lmargin[mt->lmargincur]; @@ -833,7 +839,6 @@ static int pre_RS(DECL_ARGS) { struct roffsu su; - int len; switch (n->type) { case MAN_BLOCK: @@ -845,16 +850,16 @@ pre_RS(DECL_ARGS) break; } - if ((n = n->parent->head->child) != NULL && - a2roffsu(n->string, &su, SCALE_EN)) - len = term_hspan(p, &su); - else - len = term_len(p, p->defindent); + n = n->parent->head; + n->aux = SHRT_MAX + 1; + if (n->child != NULL && a2roffsu(n->child->string, &su, SCALE_EN)) + n->aux = term_hspan(p, &su); + if (n->aux < 0 && (size_t)(-n->aux) > mt->offset) + n->aux = -mt->offset; + else if (n->aux > SHRT_MAX) + n->aux = term_len(p, p->defindent); - if (len > 0 || (size_t)(-len) < mt->offset) - mt->offset += len; - else - mt->offset = 0; + mt->offset += n->aux; p->offset = mt->offset; p->rmargin = p->maxrmargin; @@ -868,8 +873,6 @@ pre_RS(DECL_ARGS) static void post_RS(DECL_ARGS) { - struct roffsu su; - int len; switch (n->type) { case MAN_BLOCK: @@ -881,16 +884,7 @@ post_RS(DECL_ARGS) break; } - if ((n = n->parent->head->child) != NULL && - a2roffsu(n->string, &su, SCALE_EN)) - len = term_hspan(p, &su); - else - len = term_len(p, p->defindent); - - if (len < 0 || (size_t)len < mt->offset) - mt->offset -= len; - else - mt->offset = 0; + mt->offset -= n->parent->head->aux; p->offset = mt->offset; if (--mt->lmarginsz < MAXMARGINS) @@ -955,7 +949,7 @@ print_man_node(DECL_ARGS) * Tables are preceded by a newline. Then process a * table line, which will cause line termination, */ - if (TBL_SPAN_FIRST & n->span->flags) + if (n->span->prev == NULL) term_newln(p); term_tbl(p, n->span); return; @@ -1013,10 +1007,10 @@ static void print_man_nodelist(DECL_ARGS) { - print_man_node(p, mt, n, meta); - if ( ! n->next) - return; - print_man_nodelist(p, mt, n->next, meta); + while (n != NULL) { + print_man_node(p, mt, n, meta); + n = n->next; + } } static void