=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/man_term.c,v retrieving revision 1.115 retrieving revision 1.116 diff -c -r1.115 -r1.116 *** src/usr.bin/mandoc/man_term.c 2014/12/23 09:31:17 1.115 --- src/usr.bin/mandoc/man_term.c 2014/12/23 13:48:15 1.116 *************** *** 1,4 **** ! /* $OpenBSD: man_term.c,v 1.115 2014/12/23 09:31:17 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze --- 1,4 ---- ! /* $OpenBSD: man_term.c,v 1.116 2014/12/23 13:48:15 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze *************** *** 35,41 **** struct mtermp { int fl; #define MANT_LITERAL (1 << 0) ! size_t lmargin[MAXMARGINS]; /* margins (incl. visible page) */ int lmargincur; /* index of current margin */ int lmarginsz; /* actual number of nested margins */ size_t offset; /* default offset to visible page */ --- 35,41 ---- struct mtermp { int fl; #define MANT_LITERAL (1 << 0) ! int lmargin[MAXMARGINS]; /* margins (incl. vis. page) */ int lmargincur; /* index of current margin */ int lmarginsz; /* actual number of nested margins */ size_t offset; /* default offset to visible page */ *************** *** 54,61 **** #define MAN_NOTEXT (1 << 0) /* Never has text children. */ }; - static int a2width(const struct termp *, const char *); - static void print_man_nodelist(DECL_ARGS); static void print_man_node(DECL_ARGS); static void print_man_head(struct termp *, const void *); --- 54,59 ---- *************** *** 181,197 **** } } - static int - a2width(const struct termp *p, const char *cp) - { - struct roffsu su; - - if ( ! a2roffsu(cp, &su, SCALE_EN)) - return(-1); - - return((int)term_hspan(p, &su)); - } - /* * Printing leading vertical space before a block. * This is used for the paragraph macros. --- 179,184 ---- *************** *** 410,418 **** static int pre_in(DECL_ARGS) { ! int len, less; ! size_t v; const char *cp; term_newln(p); --- 397,406 ---- static int pre_in(DECL_ARGS) { ! struct roffsu su; const char *cp; + size_t v; + int less; term_newln(p); *************** *** 431,440 **** 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; --- 419,428 ---- else cp--; ! if ( ! a2roffsu(++cp, &su, SCALE_EN)) return(0); ! v = term_hspan(p, &su); if (less < 0) p->offset -= p->offset > v ? v : p->offset; *************** *** 450,458 **** pre_sp(DECL_ARGS) { struct roffsu su; ! char *s; ! size_t i, len; ! int neg; if ((NULL == n->prev && n->parent)) { switch (n->parent->tok) { --- 438,444 ---- pre_sp(DECL_ARGS) { struct roffsu su; ! int i, len; if ((NULL == n->prev && n->parent)) { switch (n->parent->tok) { *************** *** 472,502 **** } } ! neg = 0; ! switch (n->tok) { ! case MAN_br: len = 0; ! break; ! default: ! if (NULL == n->child) { ! len = 1; ! break; ! } ! s = n->child->string; ! if ('-' == *s) { ! neg = 1; ! s++; ! } ! if ( ! a2roffsu(s, &su, SCALE_VS)) su.scale = 1.0; len = term_vspan(p, &su); - break; } ! if (0 == len) term_newln(p); ! else if (neg) ! p->skipvsp += len; else for (i = 0; i < len; i++) term_vspace(p); --- 458,477 ---- } } ! if (n->tok == MAN_br) len = 0; ! else if (n->child == NULL) ! len = 1; ! else { ! if ( ! a2roffsu(n->child->string, &su, SCALE_VS)) su.scale = 1.0; len = term_vspan(p, &su); } ! if (len == 0) term_newln(p); ! else if (len < 0) ! p->skipvsp -= len; else for (i = 0; i < len; i++) term_vspace(p); *************** *** 507,515 **** static int pre_HP(DECL_ARGS) { ! size_t len, one; ! int ival; const struct man_node *nn; switch (n->type) { case MAN_BLOCK: --- 482,490 ---- static int pre_HP(DECL_ARGS) { ! struct roffsu su; const struct man_node *nn; + int len; switch (n->type) { case MAN_BLOCK: *************** *** 526,550 **** p->trailspace = 2; } - len = mt->lmargin[mt->lmargincur]; - ival = -1; - /* Calculate offset. */ ! if (NULL != (nn = n->parent->head->child)) ! if ((ival = a2width(p, nn->string)) >= 0) ! len = (size_t)ival; - one = term_len(p, 1); - if (len < one) - len = one; - p->offset = mt->offset; ! p->rmargin = mt->offset + len; - if (ival >= 0) - mt->lmargin[mt->lmargincur] = (size_t)ival; - return(1); } --- 501,521 ---- p->trailspace = 2; } /* Calculate offset. */ ! if ((nn = n->parent->head->child) != NULL && ! a2roffsu(nn->string, &su, SCALE_EN)) { ! len = term_hspan(p, &su); ! 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; return(1); } *************** *** 585,593 **** static int pre_IP(DECL_ARGS) { const struct man_node *nn; ! size_t len; ! int savelit, ival; switch (n->type) { case MAN_BODY: --- 556,564 ---- static int pre_IP(DECL_ARGS) { + struct roffsu su; const struct man_node *nn; ! int len, savelit; switch (n->type) { case MAN_BODY: *************** *** 604,631 **** return(1); } - len = mt->lmargin[mt->lmargincur]; - ival = -1; - /* Calculate the offset from the optional second argument. */ ! if (NULL != (nn = n->parent->head->child)) ! if (NULL != (nn = nn->next)) ! if ((ival = a2width(p, nn->string)) >= 0) ! len = (size_t)ival; switch (n->type) { case MAN_HEAD: - /* Handle zero-width lengths. */ - if (0 == len) - len = term_len(p, 1); - p->offset = mt->offset; p->rmargin = mt->offset + len; - /* Set the saved left-margin. */ - if (ival >= 0) - mt->lmargin[mt->lmargincur] = (size_t)ival; - savelit = MANT_LITERAL & mt->fl; mt->fl &= ~MANT_LITERAL; --- 575,596 ---- return(1); } /* Calculate the offset from the optional second argument. */ ! if ((nn = n->parent->head->child) != NULL && ! (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 ! len = mt->lmargin[mt->lmargincur]; switch (n->type) { case MAN_HEAD: p->offset = mt->offset; p->rmargin = mt->offset + len; savelit = MANT_LITERAL & mt->fl; mt->fl &= ~MANT_LITERAL; *************** *** 670,678 **** static int pre_TP(DECL_ARGS) { const struct man_node *nn; ! size_t len; ! int savelit, ival; switch (n->type) { case MAN_HEAD: --- 635,643 ---- static int pre_TP(DECL_ARGS) { + struct roffsu su; const struct man_node *nn; ! int len, savelit; switch (n->type) { case MAN_HEAD: *************** *** 689,710 **** return(1); } - len = (size_t)mt->lmargin[mt->lmargincur]; - ival = -1; - /* Calculate offset. */ ! if (NULL != (nn = n->parent->head->child)) ! if (nn->string && 0 == (MAN_LINE & nn->flags)) ! if ((ival = a2width(p, nn->string)) >= 0) ! len = (size_t)ival; switch (n->type) { case MAN_HEAD: - /* Handle zero-length properly. */ - if (0 == len) - len = term_len(p, 1); - p->offset = mt->offset; p->rmargin = mt->offset + len; --- 654,673 ---- return(1); } /* Calculate offset. */ ! if ((nn = n->parent->head->child) != NULL && ! 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 ! len = mt->lmargin[mt->lmargincur]; switch (n->type) { case MAN_HEAD: p->offset = mt->offset; p->rmargin = mt->offset + len; *************** *** 723,731 **** if (savelit) mt->fl |= MANT_LITERAL; - if (ival >= 0) - mt->lmargin[mt->lmargincur] = (size_t)ival; - return(0); case MAN_BODY: p->offset = mt->offset + len; --- 686,691 ---- *************** *** 870,877 **** static int pre_RS(DECL_ARGS) { ! int ival; ! size_t sz; switch (n->type) { case MAN_BLOCK: --- 830,837 ---- static int pre_RS(DECL_ARGS) { ! struct roffsu su; ! int len; switch (n->type) { case MAN_BLOCK: *************** *** 883,895 **** break; } ! sz = term_len(p, p->defindent); ! if (NULL != (n = n->parent->head->child)) ! if ((ival = a2width(p, n->string)) >= 0) ! sz = (size_t)ival; ! ! mt->offset += sz; p->offset = mt->offset; p->rmargin = p->maxrmargin; --- 843,858 ---- 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; p->offset = mt->offset; p->rmargin = p->maxrmargin; *************** *** 903,910 **** static void post_RS(DECL_ARGS) { ! int ival; ! size_t sz; switch (n->type) { case MAN_BLOCK: --- 866,873 ---- static void post_RS(DECL_ARGS) { ! struct roffsu su; ! int len; switch (n->type) { case MAN_BLOCK: *************** *** 916,928 **** break; } ! sz = term_len(p, p->defindent); ! if (NULL != (n = n->parent->head->child)) ! if ((ival = a2width(p, n->string)) >= 0) ! sz = (size_t)ival; ! ! mt->offset = mt->offset < sz ? 0 : mt->offset - sz; p->offset = mt->offset; if (--mt->lmarginsz < MAXMARGINS) --- 879,894 ---- 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; p->offset = mt->offset; if (--mt->lmarginsz < MAXMARGINS)