diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2017-06-07 17:38:09 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2017-06-07 17:38:09 +0000 |
commit | 3612e11b65cfc0da438fb1ecf019daffeca42814 (patch) | |
tree | 965f11e99e49e9905f370785f221afbe1d3bb59e | |
parent | 1ca8dd9bca3cf0d57b621b33e3f94087ce7ac0c6 (diff) |
Prepare the terminal driver for filling multiple columns in parallel,
first step: split column data out of the terminal state struct into
a new column state struct and use an array of such column state
structs. No functional change.
-rw-r--r-- | usr.bin/mandoc/man_term.c | 120 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_term.c | 150 | ||||
-rw-r--r-- | usr.bin/mandoc/roff_term.c | 30 | ||||
-rw-r--r-- | usr.bin/mandoc/tbl_term.c | 14 | ||||
-rw-r--r-- | usr.bin/mandoc/term.c | 136 | ||||
-rw-r--r-- | usr.bin/mandoc/term.h | 24 | ||||
-rw-r--r-- | usr.bin/mandoc/term_ascii.c | 18 | ||||
-rw-r--r-- | usr.bin/mandoc/term_ps.c | 13 |
8 files changed, 261 insertions, 244 deletions
diff --git a/usr.bin/mandoc/man_term.c b/usr.bin/mandoc/man_term.c index 39cee3a82ec..70d57c5d252 100644 --- a/usr.bin/mandoc/man_term.c +++ b/usr.bin/mandoc/man_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: man_term.c,v 1.155 2017/06/04 22:43:50 schwarze Exp $ */ +/* $OpenBSD: man_term.c,v 1.156 2017/06/07 17:38:08 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2015, 2017 Ingo Schwarze <schwarze@openbsd.org> @@ -139,7 +139,7 @@ terminal_man(void *arg, const struct roff_man *man) size_t save_defindent; p = (struct termp *)arg; - p->rmargin = p->maxrmargin = p->defrmargin; + p->tcol->rmargin = p->maxrmargin = p->defrmargin; term_tab_set(p, NULL); term_tab_set(p, "T"); term_tab_set(p, ".5i"); @@ -226,7 +226,7 @@ pre_literal(DECL_ARGS) term_newln(p); - if (MAN_nf == n->tok || MAN_EX == n->tok) + if (n->tok == MAN_nf || n->tok == MAN_EX) mt->fl |= MANT_LITERAL; else mt->fl &= ~MANT_LITERAL; @@ -236,9 +236,9 @@ pre_literal(DECL_ARGS) * So in case a second call to term_flushln() is needed, * indentation has to be set up explicitly. */ - if (MAN_HP == n->parent->tok && p->rmargin < p->maxrmargin) { - p->offset = p->rmargin; - p->rmargin = p->maxrmargin; + if (n->parent->tok == MAN_HP && p->tcol->rmargin < p->maxrmargin) { + p->tcol->offset = p->tcol->rmargin; + p->tcol->rmargin = p->maxrmargin; p->trailspace = 0; p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND); p->flags |= TERMP_NOSPACE; @@ -357,8 +357,8 @@ pre_in(DECL_ARGS) term_newln(p); - if (NULL == n->child) { - p->offset = mt->offset; + if (n->child == NULL) { + p->tcol->offset = mt->offset; return 0; } @@ -378,13 +378,13 @@ pre_in(DECL_ARGS) v = (term_hspan(p, &su) + 11) / 24; if (less < 0) - p->offset -= p->offset > v ? v : p->offset; + p->tcol->offset -= p->tcol->offset > v ? v : p->tcol->offset; else if (less > 0) - p->offset += v; + p->tcol->offset += v; else - p->offset = v; - if (p->offset > SHRT_MAX) - p->offset = term_len(p, p->defindent); + p->tcol->offset = v; + if (p->tcol->offset > SHRT_MAX) + p->tcol->offset = term_len(p, p->defindent); return 0; } @@ -433,8 +433,8 @@ pre_HP(DECL_ARGS) } else len = mt->lmargin[mt->lmargincur]; - p->offset = mt->offset; - p->rmargin = mt->offset + len; + p->tcol->offset = mt->offset; + p->tcol->rmargin = mt->offset + len; return 1; } @@ -458,8 +458,8 @@ post_HP(DECL_ARGS) p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND); p->trailspace = 0; - p->offset = mt->offset; - p->rmargin = p->maxrmargin; + p->tcol->offset = mt->offset; + p->tcol->rmargin = p->maxrmargin; break; default: break; @@ -476,7 +476,7 @@ pre_PP(DECL_ARGS) print_bvspace(p, n, mt->pardist); break; default: - p->offset = mt->offset; + p->tcol->offset = mt->offset; break; } @@ -520,8 +520,8 @@ pre_IP(DECL_ARGS) switch (n->type) { case ROFFT_HEAD: - p->offset = mt->offset; - p->rmargin = mt->offset + len; + p->tcol->offset = mt->offset; + p->tcol->rmargin = mt->offset + len; savelit = MANT_LITERAL & mt->fl; mt->fl &= ~MANT_LITERAL; @@ -534,8 +534,8 @@ pre_IP(DECL_ARGS) return 0; case ROFFT_BODY: - p->offset = mt->offset + len; - p->rmargin = p->maxrmargin; + p->tcol->offset = mt->offset + len; + p->tcol->rmargin = p->maxrmargin; break; default: break; @@ -553,11 +553,11 @@ post_IP(DECL_ARGS) term_flushln(p); p->flags &= ~TERMP_NOBREAK; p->trailspace = 0; - p->rmargin = p->maxrmargin; + p->tcol->rmargin = p->maxrmargin; break; case ROFFT_BODY: term_newln(p); - p->offset = mt->offset; + p->tcol->offset = mt->offset; break; default: break; @@ -602,8 +602,8 @@ pre_TP(DECL_ARGS) switch (n->type) { case ROFFT_HEAD: - p->offset = mt->offset; - p->rmargin = mt->offset + len; + p->tcol->offset = mt->offset; + p->tcol->rmargin = mt->offset + len; savelit = MANT_LITERAL & mt->fl; mt->fl &= ~MANT_LITERAL; @@ -622,8 +622,8 @@ pre_TP(DECL_ARGS) mt->fl |= MANT_LITERAL; return 0; case ROFFT_BODY: - p->offset = mt->offset + len; - p->rmargin = p->maxrmargin; + p->tcol->offset = mt->offset + len; + p->tcol->rmargin = p->maxrmargin; p->trailspace = 0; p->flags &= ~(TERMP_NOBREAK | TERMP_BRTRSP); break; @@ -644,7 +644,7 @@ post_TP(DECL_ARGS) break; case ROFFT_BODY: term_newln(p); - p->offset = mt->offset; + p->tcol->offset = mt->offset; break; default: break; @@ -679,14 +679,14 @@ pre_SS(DECL_ARGS) break; case ROFFT_HEAD: term_fontrepl(p, TERMFONT_BOLD); - p->offset = term_len(p, 3); - p->rmargin = mt->offset; + p->tcol->offset = term_len(p, 3); + p->tcol->rmargin = mt->offset; p->trailspace = mt->offset; p->flags |= TERMP_NOBREAK | TERMP_BRIND; break; case ROFFT_BODY: - p->offset = mt->offset; - p->rmargin = p->maxrmargin; + p->tcol->offset = mt->offset; + p->tcol->rmargin = p->maxrmargin; p->trailspace = 0; p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND); break; @@ -741,14 +741,14 @@ pre_SH(DECL_ARGS) break; case ROFFT_HEAD: term_fontrepl(p, TERMFONT_BOLD); - p->offset = 0; - p->rmargin = mt->offset; + p->tcol->offset = 0; + p->tcol->rmargin = mt->offset; p->trailspace = mt->offset; p->flags |= TERMP_NOBREAK | TERMP_BRIND; break; case ROFFT_BODY: - p->offset = mt->offset; - p->rmargin = p->maxrmargin; + p->tcol->offset = mt->offset; + p->tcol->rmargin = p->maxrmargin; p->trailspace = 0; p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND); break; @@ -802,8 +802,8 @@ pre_RS(DECL_ARGS) n->aux = term_len(p, p->defindent); mt->offset += n->aux; - p->offset = mt->offset; - p->rmargin = p->maxrmargin; + p->tcol->offset = mt->offset; + p->tcol->rmargin = p->maxrmargin; if (++mt->lmarginsz < MAXMARGINS) mt->lmargincur = mt->lmarginsz; @@ -827,7 +827,7 @@ post_RS(DECL_ARGS) } mt->offset -= n->parent->head->aux; - p->offset = mt->offset; + p->tcol->offset = mt->offset; if (--mt->lmarginsz < MAXMARGINS) mt->lmargincur = mt->lmarginsz; @@ -933,9 +933,10 @@ out: else term_newln(p); p->flags &= ~TERMP_BRNEVER; - if (p->rmargin < p->maxrmargin && n->parent->tok == MAN_HP) { - p->offset = p->rmargin; - p->rmargin = p->maxrmargin; + if (p->tcol->rmargin < p->maxrmargin && + n->parent->tok == MAN_HP) { + p->tcol->offset = p->tcol->rmargin; + p->tcol->rmargin = p->maxrmargin; } } if (NODE_EOS & n->flags) @@ -992,8 +993,8 @@ print_man_foot(struct termp *p, const struct roff_meta *meta) p->flags |= TERMP_NOSPACE | TERMP_NOBREAK; p->trailspace = 1; - p->offset = 0; - p->rmargin = p->maxrmargin > datelen ? + p->tcol->offset = 0; + p->tcol->rmargin = p->maxrmargin > datelen ? (p->maxrmargin + term_len(p, 1) - datelen) / 2 : 0; if (meta->os) @@ -1002,9 +1003,10 @@ print_man_foot(struct termp *p, const struct roff_meta *meta) /* At the bottom in the middle: manual date. */ - p->offset = p->rmargin; + p->tcol->offset = p->tcol->rmargin; titlen = term_strlen(p, title); - p->rmargin = p->maxrmargin > titlen ? p->maxrmargin - titlen : 0; + p->tcol->rmargin = p->maxrmargin > titlen ? + p->maxrmargin - titlen : 0; p->flags |= TERMP_NOSPACE; term_word(p, meta->date); @@ -1015,8 +1017,8 @@ print_man_foot(struct termp *p, const struct roff_meta *meta) p->flags &= ~TERMP_NOBREAK; p->flags |= TERMP_NOSPACE; p->trailspace = 0; - p->offset = p->rmargin; - p->rmargin = p->maxrmargin; + p->tcol->offset = p->tcol->rmargin; + p->tcol->rmargin = p->maxrmargin; term_word(p, title); term_flushln(p); @@ -1043,8 +1045,8 @@ print_man_head(struct termp *p, const struct roff_meta *meta) p->flags |= TERMP_NOBREAK | TERMP_NOSPACE; p->trailspace = 1; - p->offset = 0; - p->rmargin = 2 * (titlen+1) + vollen < p->maxrmargin ? + p->tcol->offset = 0; + p->tcol->rmargin = 2 * (titlen+1) + vollen < p->maxrmargin ? (p->maxrmargin - vollen + term_len(p, 1)) / 2 : vollen < p->maxrmargin ? p->maxrmargin - vollen : 0; @@ -1054,9 +1056,9 @@ print_man_head(struct termp *p, const struct roff_meta *meta) /* At the top in the middle: manual volume. */ p->flags |= TERMP_NOSPACE; - p->offset = p->rmargin; - p->rmargin = p->offset + vollen + titlen < p->maxrmargin ? - p->maxrmargin - titlen : p->maxrmargin; + p->tcol->offset = p->tcol->rmargin; + p->tcol->rmargin = p->tcol->offset + vollen + titlen < + p->maxrmargin ? p->maxrmargin - titlen : p->maxrmargin; term_word(p, volume); term_flushln(p); @@ -1065,17 +1067,17 @@ print_man_head(struct termp *p, const struct roff_meta *meta) p->flags &= ~TERMP_NOBREAK; p->trailspace = 0; - if (p->rmargin + titlen <= p->maxrmargin) { + if (p->tcol->rmargin + titlen <= p->maxrmargin) { p->flags |= TERMP_NOSPACE; - p->offset = p->rmargin; - p->rmargin = p->maxrmargin; + p->tcol->offset = p->tcol->rmargin; + p->tcol->rmargin = p->maxrmargin; term_word(p, title); term_flushln(p); } p->flags &= ~TERMP_NOSPACE; - p->offset = 0; - p->rmargin = p->maxrmargin; + p->tcol->offset = 0; + p->tcol->rmargin = p->maxrmargin; /* * Groff prints three blank lines before the content. diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c index d3b643e9b9a..2426f311c43 100644 --- a/usr.bin/mandoc/mdoc_term.c +++ b/usr.bin/mandoc/mdoc_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_term.c,v 1.260 2017/06/04 22:43:50 schwarze Exp $ */ +/* $OpenBSD: mdoc_term.c,v 1.261 2017/06/07 17:38:08 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2012-2017 Ingo Schwarze <schwarze@openbsd.org> @@ -257,7 +257,7 @@ terminal_mdoc(void *arg, const struct roff_man *mdoc) size_t save_defindent; p = (struct termp *)arg; - p->rmargin = p->maxrmargin = p->defrmargin; + p->tcol->rmargin = p->maxrmargin = p->defrmargin; term_tab_set(p, NULL); term_tab_set(p, "T"); term_tab_set(p, ".5i"); @@ -314,8 +314,8 @@ print_mdoc_node(DECL_ARGS) return; chld = 1; - offset = p->offset; - rmargin = p->rmargin; + offset = p->tcol->offset; + rmargin = p->tcol->rmargin; n->flags &= ~NODE_ENDED; n->prev_font = p->fonti; @@ -405,8 +405,8 @@ print_mdoc_node(DECL_ARGS) p->flags |= TERMP_SENTENCE; if (n->type != ROFFT_TEXT) - p->offset = offset; - p->rmargin = rmargin; + p->tcol->offset = offset; + p->tcol->rmargin = rmargin; } static void @@ -426,9 +426,9 @@ print_mdoc_foot(struct termp *p, const struct roff_meta *meta) term_vspace(p); - p->offset = 0; + p->tcol->offset = 0; sz = term_strlen(p, meta->date); - p->rmargin = p->maxrmargin > sz ? + p->tcol->rmargin = p->maxrmargin > sz ? (p->maxrmargin + term_len(p, 1) - sz) / 2 : 0; p->trailspace = 1; p->flags |= TERMP_NOSPACE | TERMP_NOBREAK; @@ -436,16 +436,16 @@ print_mdoc_foot(struct termp *p, const struct roff_meta *meta) term_word(p, meta->os); term_flushln(p); - p->offset = p->rmargin; + p->tcol->offset = p->tcol->rmargin; sz = term_strlen(p, meta->os); - p->rmargin = p->maxrmargin > sz ? p->maxrmargin - sz : 0; + p->tcol->rmargin = p->maxrmargin > sz ? p->maxrmargin - sz : 0; p->flags |= TERMP_NOSPACE; term_word(p, meta->date); term_flushln(p); - p->offset = p->rmargin; - p->rmargin = p->maxrmargin; + p->tcol->offset = p->tcol->rmargin; + p->tcol->rmargin = p->maxrmargin; p->trailspace = 0; p->flags &= ~TERMP_NOBREAK; p->flags |= TERMP_NOSPACE; @@ -453,8 +453,8 @@ print_mdoc_foot(struct termp *p, const struct roff_meta *meta) term_word(p, meta->os); term_flushln(p); - p->offset = 0; - p->rmargin = p->maxrmargin; + p->tcol->offset = 0; + p->tcol->rmargin = p->maxrmargin; p->flags = 0; } @@ -494,8 +494,8 @@ print_mdoc_head(struct termp *p, const struct roff_meta *meta) p->flags |= TERMP_NOBREAK | TERMP_NOSPACE; p->trailspace = 1; - p->offset = 0; - p->rmargin = 2 * (titlen+1) + vollen < p->maxrmargin ? + p->tcol->offset = 0; + p->tcol->rmargin = 2 * (titlen+1) + vollen < p->maxrmargin ? (p->maxrmargin - vollen + term_len(p, 1)) / 2 : vollen < p->maxrmargin ? p->maxrmargin - vollen : 0; @@ -503,26 +503,26 @@ print_mdoc_head(struct termp *p, const struct roff_meta *meta) term_flushln(p); p->flags |= TERMP_NOSPACE; - p->offset = p->rmargin; - p->rmargin = p->offset + vollen + titlen < p->maxrmargin ? - p->maxrmargin - titlen : p->maxrmargin; + p->tcol->offset = p->tcol->rmargin; + p->tcol->rmargin = p->tcol->offset + vollen + titlen < + p->maxrmargin ? p->maxrmargin - titlen : p->maxrmargin; term_word(p, volume); term_flushln(p); p->flags &= ~TERMP_NOBREAK; p->trailspace = 0; - if (p->rmargin + titlen <= p->maxrmargin) { + if (p->tcol->rmargin + titlen <= p->maxrmargin) { p->flags |= TERMP_NOSPACE; - p->offset = p->rmargin; - p->rmargin = p->maxrmargin; + p->tcol->offset = p->tcol->rmargin; + p->tcol->rmargin = p->maxrmargin; term_word(p, title); term_flushln(p); } p->flags &= ~TERMP_NOSPACE; - p->offset = 0; - p->rmargin = p->maxrmargin; + p->tcol->offset = 0; + p->tcol->rmargin = p->maxrmargin; free(title); free(volume); } @@ -647,8 +647,8 @@ termp_it_pre(DECL_ARGS) if (bl->norm->Bl.offs != NULL) { offset = a2width(p, bl->norm->Bl.offs); - if (offset < 0 && (size_t)(-offset) > p->offset) - offset = -p->offset; + if (offset < 0 && (size_t)(-offset) > p->tcol->offset) + offset = -p->tcol->offset; else if (offset > SHRT_MAX) offset = 0; } @@ -712,8 +712,8 @@ termp_it_pre(DECL_ARGS) * handling for column for how this changes. */ width = a2width(p, bl->norm->Bl.width) + term_len(p, 2); - if (width < 0 && (size_t)(-width) > p->offset) - width = -p->offset; + if (width < 0 && (size_t)(-width) > p->tcol->offset) + width = -p->tcol->offset; else if (width > SHRT_MAX) width = 0; break; @@ -813,7 +813,7 @@ termp_it_pre(DECL_ARGS) * necessarily lengthened. Everybody gets the offset. */ - p->offset += offset; + p->tcol->offset += offset; switch (type) { case LIST_bullet: @@ -823,21 +823,21 @@ termp_it_pre(DECL_ARGS) case LIST_hang: case LIST_tag: if (n->type == ROFFT_HEAD) - p->rmargin = p->offset + width; + p->tcol->rmargin = p->tcol->offset + width; else - p->offset += width; + p->tcol->offset += width; break; case LIST_column: assert(width); - p->rmargin = p->offset + width; + p->tcol->rmargin = p->tcol->offset + width; /* * XXX - this behaviour is not documented: the * right-most column is filled to the right margin. */ if (n->type == ROFFT_HEAD) break; - if (NULL == n->next && p->rmargin < p->maxrmargin) - p->rmargin = p->maxrmargin; + if (n->next == NULL && p->tcol->rmargin < p->maxrmargin) + p->tcol->rmargin = p->maxrmargin; break; default: break; @@ -943,7 +943,7 @@ termp_nm_pre(DECL_ARGS) } if (n->type == ROFFT_BODY) { - if (NULL == n->child) + if (n->child == NULL) return 0; p->flags |= TERMP_NOSPACE; cp = NULL; @@ -952,9 +952,10 @@ termp_nm_pre(DECL_ARGS) if (cp == NULL) cp = meta->name; if (cp == NULL) - p->offset += term_len(p, 6); + p->tcol->offset += term_len(p, 6); else - p->offset += term_len(p, 1) + term_strlen(p, cp); + p->tcol->offset += term_len(p, 1) + + term_strlen(p, cp); return 1; } @@ -965,18 +966,18 @@ termp_nm_pre(DECL_ARGS) synopsis_pre(p, n->parent); if (n->type == ROFFT_HEAD && - NULL != n->next && NULL != n->next->child) { + n->next != NULL && n->next->child != NULL) { p->flags |= TERMP_NOSPACE | TERMP_NOBREAK | TERMP_BRIND; p->trailspace = 1; - p->rmargin = p->offset + term_len(p, 1); - if (NULL == n->child) { - p->rmargin += term_strlen(p, meta->name); - } else if (n->child->type == ROFFT_TEXT) { - p->rmargin += term_strlen(p, n->child->string); - if (n->child->next) + p->tcol->rmargin = p->tcol->offset + term_len(p, 1); + if (n->child == NULL) + p->tcol->rmargin += term_strlen(p, meta->name); + else if (n->child->type == ROFFT_TEXT) { + p->tcol->rmargin += term_strlen(p, n->child->string); + if (n->child->next != NULL) p->flags |= TERMP_HANG; } else { - p->rmargin += term_len(p, 5); + p->tcol->rmargin += term_len(p, 5); p->flags |= TERMP_HANG; } } @@ -1248,7 +1249,7 @@ termp_sh_pre(DECL_ARGS) term_fontpush(p, TERMFONT_BOLD); break; case ROFFT_BODY: - p->offset = term_len(p, p->defindent); + p->tcol->offset = term_len(p, p->defindent); term_tab_set(p, NULL); term_tab_set(p, "T"); term_tab_set(p, ".5i"); @@ -1279,7 +1280,7 @@ termp_sh_post(DECL_ARGS) break; case ROFFT_BODY: term_newln(p); - p->offset = 0; + p->tcol->offset = 0; break; default: break; @@ -1301,7 +1302,7 @@ termp_d1_pre(DECL_ARGS) if (n->type != ROFFT_BLOCK) return 1; term_newln(p); - p->offset += term_len(p, p->defindent + 1); + p->tcol->offset += term_len(p, p->defindent + 1); term_tab_set(p, NULL); term_tab_set(p, "T"); term_tab_set(p, ".5i"); @@ -1332,8 +1333,8 @@ termp_fn_pre(DECL_ARGS) return 0; if (pretty) { - rmargin = p->rmargin; - p->rmargin = p->offset + term_len(p, 4); + rmargin = p->tcol->rmargin; + p->tcol->rmargin = p->tcol->offset + term_len(p, 4); p->flags |= TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG; } @@ -1349,8 +1350,8 @@ termp_fn_pre(DECL_ARGS) term_flushln(p); p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG); p->flags |= TERMP_NOPAD; - p->offset = p->rmargin; - p->rmargin = rmargin; + p->tcol->offset = p->tcol->rmargin; + p->tcol->rmargin = rmargin; } p->flags |= TERMP_NOSPACE; @@ -1427,15 +1428,15 @@ termp_bd_pre(DECL_ARGS) ! strcmp(n->norm->Bd.offs, "left")) /* nothing */; else if ( ! strcmp(n->norm->Bd.offs, "indent")) - p->offset += term_len(p, p->defindent + 1); + p->tcol->offset += term_len(p, p->defindent + 1); else if ( ! strcmp(n->norm->Bd.offs, "indent-two")) - p->offset += term_len(p, (p->defindent + 1) * 2); + p->tcol->offset += term_len(p, (p->defindent + 1) * 2); else { offset = a2width(p, n->norm->Bd.offs); - if (offset < 0 && (size_t)(-offset) > p->offset) - p->offset = 0; + if (offset < 0 && (size_t)(-offset) > p->tcol->offset) + p->tcol->offset = 0; else if (offset < SHRT_MAX) - p->offset += offset; + p->tcol->offset += offset; } /* @@ -1446,9 +1447,9 @@ termp_bd_pre(DECL_ARGS) * lines are allowed. */ - if (DISP_literal != n->norm->Bd.type && - DISP_unfilled != n->norm->Bd.type && - DISP_centered != n->norm->Bd.type) + if (n->norm->Bd.type != DISP_literal && + n->norm->Bd.type != DISP_unfilled && + n->norm->Bd.type != DISP_centered) return 1; if (n->norm->Bd.type == DISP_literal) { @@ -1457,17 +1458,18 @@ termp_bd_pre(DECL_ARGS) term_tab_set(p, "8n"); } - lm = p->offset; + lm = p->tcol->offset; p->flags |= TERMP_BRNEVER; - for (nn = n->child; nn; nn = nn->next) { - if (DISP_centered == n->norm->Bd.type) { + for (nn = n->child; nn != NULL; nn = nn->next) { + if (n->norm->Bd.type == DISP_centered) { if (nn->type == ROFFT_TEXT) { len = term_strlen(p, nn->string); - p->offset = len >= p->rmargin ? 0 : - lm + len >= p->rmargin ? p->rmargin - len : - (lm + p->rmargin - len) / 2; + p->tcol->offset = len >= p->tcol->rmargin ? + 0 : lm + len >= p->tcol->rmargin ? + p->tcol->rmargin - len : + (lm + p->tcol->rmargin - len) / 2; } else - p->offset = lm; + p->tcol->offset = lm; } print_mdoc_node(p, pair, meta, nn); /* @@ -1551,10 +1553,10 @@ termp_ss_pre(DECL_ARGS) break; case ROFFT_HEAD: term_fontpush(p, TERMFONT_BOLD); - p->offset = term_len(p, (p->defindent+1)/2); + p->tcol->offset = term_len(p, (p->defindent+1)/2); break; case ROFFT_BODY: - p->offset = term_len(p, p->defindent); + p->tcol->offset = term_len(p, p->defindent); term_tab_set(p, NULL); term_tab_set(p, "T"); term_tab_set(p, ".5i"); @@ -1801,8 +1803,8 @@ termp_fo_pre(DECL_ARGS) return 1; } else if (n->type == ROFFT_BODY) { if (pretty) { - rmargin = p->rmargin; - p->rmargin = p->offset + term_len(p, 4); + rmargin = p->tcol->rmargin; + p->tcol->rmargin = p->tcol->offset + term_len(p, 4); p->flags |= TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG; } @@ -1814,8 +1816,8 @@ termp_fo_pre(DECL_ARGS) p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG); p->flags |= TERMP_NOPAD; - p->offset = p->rmargin; - p->rmargin = rmargin; + p->tcol->offset = p->tcol->rmargin; + p->tcol->rmargin = rmargin; } return 1; } @@ -1963,7 +1965,7 @@ termp_lk_pre(DECL_ARGS) display = term_strlen(p, link->string) >= 26; if (display) { term_newln(p); - p->offset += term_len(p, p->defindent + 1); + p->tcol->offset += term_len(p, p->defindent + 1); } term_fontpush(p, TERMFONT_BOLD); term_word(p, link->string); diff --git a/usr.bin/mandoc/roff_term.c b/usr.bin/mandoc/roff_term.c index dc4c7400a45..f3a97e26a3e 100644 --- a/usr.bin/mandoc/roff_term.c +++ b/usr.bin/mandoc/roff_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: roff_term.c,v 1.8 2017/06/06 15:00:56 schwarze Exp $ */ +/* $OpenBSD: roff_term.c,v 1.9 2017/06/07 17:38:08 schwarze Exp $ */ /* * Copyright (c) 2010, 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org> * @@ -60,8 +60,8 @@ roff_term_pre_br(ROFF_TERM_ARGS) { term_newln(p); if (p->flags & TERMP_BRIND) { - p->offset = p->rmargin; - p->rmargin = p->maxrmargin; + p->tcol->offset = p->tcol->rmargin; + p->tcol->rmargin = p->maxrmargin; p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND); } } @@ -73,7 +73,7 @@ roff_term_pre_ce(ROFF_TERM_ARGS) size_t len, lm; roff_term_pre_br(p, n); - lm = p->offset; + lm = p->tcol->offset; n = n->child->next; while (n != NULL) { nch = n; @@ -87,9 +87,9 @@ roff_term_pre_ce(ROFF_TERM_ARGS) nch = nch->next; } while (nch != NULL && (n->type != ROFFT_TEXT || (n->flags & NODE_LINE) == 0)); - p->offset = len >= p->rmargin ? 0 : - lm + len >= p->rmargin ? p->rmargin - len : - (lm + p->rmargin - len) / 2; + p->tcol->offset = len >= p->tcol->rmargin ? 0 : + lm + len >= p->tcol->rmargin ? p->tcol->rmargin - len : + (lm + p->tcol->rmargin - len) / 2; while (n != nch) { if (n->type == ROFFT_TEXT) term_word(p, n->string); @@ -100,7 +100,7 @@ roff_term_pre_ce(ROFF_TERM_ARGS) p->flags |= TERMP_NOSPACE; term_flushln(p); } - p->offset = lm; + p->tcol->offset = lm; } static void @@ -206,16 +206,16 @@ roff_term_pre_ti(ROFF_TERM_ARGS) len = term_hspan(p, &su) / 24; if (sign == 0) { - p->ti = len - p->offset; - p->offset = len; + p->ti = len - p->tcol->offset; + p->tcol->offset = len; } else if (sign == 1) { p->ti = len; - p->offset += len; - } else if ((size_t)len < p->offset) { + p->tcol->offset += len; + } else if ((size_t)len < p->tcol->offset) { p->ti = -len; - p->offset -= len; + p->tcol->offset -= len; } else { - p->ti = -p->offset; - p->offset = 0; + p->ti = -p->tcol->offset; + p->tcol->offset = 0; } } diff --git a/usr.bin/mandoc/tbl_term.c b/usr.bin/mandoc/tbl_term.c index 1c911f9b12a..7e459046509 100644 --- a/usr.bin/mandoc/tbl_term.c +++ b/usr.bin/mandoc/tbl_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tbl_term.c,v 1.32 2017/06/04 22:43:50 schwarze Exp $ */ +/* $OpenBSD: tbl_term.c,v 1.33 2017/06/07 17:38:08 schwarze Exp $ */ /* * Copyright (c) 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011,2012,2014,2015,2017 Ingo Schwarze <schwarze@openbsd.org> @@ -78,21 +78,21 @@ term_tbl(struct termp *tp, const struct tbl_span *sp) tp->tbl.slen = term_tbl_strlen; tp->tbl.arg = tp; - tblcalc(&tp->tbl, sp, tp->rmargin - tp->offset); + tblcalc(&tp->tbl, sp, tp->tcol->rmargin - tp->tcol->offset); /* Center the table as a whole. */ - offset = tp->offset; + offset = tp->tcol->offset; if (sp->opts->opts & TBL_OPT_CENTRE) { tsz = sp->opts->opts & (TBL_OPT_BOX | TBL_OPT_DBOX) ? 2 : !!sp->opts->lvert + !!sp->opts->rvert; for (ic = 0; ic < sp->opts->cols; ic++) tsz += tp->tbl.cols[ic].width + 3; tsz -= 3; - if (offset + tsz > tp->rmargin) + if (offset + tsz > tp->tcol->rmargin) tsz -= 1; - tp->offset = (offset + tp->rmargin > tsz) ? - (offset + tp->rmargin - tsz) / 2 : 0; + tp->tcol->offset = offset + tp->tcol->rmargin > tsz ? + (offset + tp->tcol->rmargin - tsz) / 2 : 0; } /* Horizontal frame at the start of boxed tables. */ @@ -191,7 +191,7 @@ term_tbl(struct termp *tp, const struct tbl_span *sp) assert(tp->tbl.cols); free(tp->tbl.cols); tp->tbl.cols = NULL; - tp->offset = offset; + tp->tcol->offset = offset; } tp->flags &= ~(TERMP_NONOSPACE | TERMP_BRNEVER); } diff --git a/usr.bin/mandoc/term.c b/usr.bin/mandoc/term.c index a7316d1ade6..56dd2ed7dcf 100644 --- a/usr.bin/mandoc/term.c +++ b/usr.bin/mandoc/term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: term.c,v 1.125 2017/06/07 02:13:52 schwarze Exp $ */ +/* $OpenBSD: term.c,v 1.126 2017/06/07 17:38:08 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org> @@ -30,7 +30,7 @@ #include "main.h" static size_t cond_width(const struct termp *, int, int *); -static void adjbuf(struct termp *p, size_t); +static void adjbuf(struct termp_col *, size_t); static void bufferc(struct termp *, char); static void encode(struct termp *, const char *, size_t); static void encode1(struct termp *, int); @@ -40,8 +40,9 @@ static void endline(struct termp *); void term_free(struct termp *p) { - - free(p->buf); + for (p->tcol = p->tcols; p->tcol < p->tcols + p->maxtcol; p->tcol++) + free(p->tcol->buf); + free(p->tcols); free(p->fontq); free(p); } @@ -92,23 +93,23 @@ term_end(struct termp *p) void term_flushln(struct termp *p) { - size_t i; /* current input position in p->buf */ - int ntab; /* number of tabs to prepend */ + size_t i; /* current input position in p->tcol->buf */ size_t vis; /* current visual position on output */ size_t vbl; /* number of blanks to prepend to output */ size_t vend; /* end of word visual position on output */ size_t bp; /* visual right border position */ size_t dv; /* temporary for visual pos calculations */ - size_t j; /* temporary loop index for p->buf */ + size_t j; /* temporary loop index for p->tcol->buf */ size_t jhy; /* last hyph before overflow w/r/t j */ size_t maxvis; /* output position of visible boundary */ + int ntab; /* number of tabs to prepend */ - vbl = (p->flags & TERMP_NOPAD) || p->offset < p->viscol ? 0 : - p->offset - p->viscol; + vbl = (p->flags & TERMP_NOPAD) || p->tcol->offset < p->viscol ? + 0 : p->tcol->offset - p->viscol; if (p->minbl && vbl < p->minbl) vbl = p->minbl; - maxvis = p->rmargin > p->viscol + vbl ? - p->rmargin - p->viscol - vbl : 0; + maxvis = p->tcol->rmargin > p->viscol + vbl ? + p->tcol->rmargin - p->viscol - vbl : 0; bp = !(p->flags & TERMP_NOBREAK) ? maxvis : p->maxrmargin > p->viscol + vbl ? p->maxrmargin - p->viscol - vbl : 0; @@ -121,7 +122,7 @@ term_flushln(struct termp *p) * subsequent tabs into a single huge set of spaces. */ ntab = 0; - while (i < p->lastcol && p->buf[i] == '\t') { + while (i < p->lastcol && p->tcol->buf[i] == '\t') { vend = term_tab_next(vis); vbl += vend - vis; vis = vend; @@ -137,31 +138,31 @@ term_flushln(struct termp *p) */ for (j = i, jhy = 0; j < p->lastcol; j++) { - if (' ' == p->buf[j] || '\t' == p->buf[j]) + if (p->tcol->buf[j] == ' ' || p->tcol->buf[j] == '\t') break; /* Back over the last printed character. */ - if (8 == p->buf[j]) { + if (p->tcol->buf[j] == '\b') { assert(j); - vend -= (*p->width)(p, p->buf[j - 1]); + vend -= (*p->width)(p, p->tcol->buf[j - 1]); continue; } /* Regular word. */ /* Break at the hyphen point if we overrun. */ if (vend > vis && vend < bp && - (ASCII_HYPH == p->buf[j] || - ASCII_BREAK == p->buf[j])) + (p->tcol->buf[j] == ASCII_HYPH|| + p->tcol->buf[j] == ASCII_BREAK)) jhy = j; /* * Hyphenation now decided, put back a real * hyphen such that we get the correct width. */ - if (ASCII_HYPH == p->buf[j]) - p->buf[j] = '-'; + if (p->tcol->buf[j] == ASCII_HYPH) + p->tcol->buf[j] = '-'; - vend += (*p->width)(p, p->buf[j]); + vend += (*p->width)(p, p->tcol->buf[j]); } /* @@ -182,10 +183,11 @@ term_flushln(struct termp *p) /* Re-establish indentation. */ if (p->flags & TERMP_BRIND) - vbl += p->rmargin; + vbl += p->tcol->rmargin; else - vbl += p->offset; - maxvis = p->rmargin > vbl ? p->rmargin - vbl : 0; + vbl += p->tcol->offset; + maxvis = p->tcol->rmargin > vbl ? + p->tcol->rmargin - vbl : 0; bp = !(p->flags & TERMP_NOBREAK) ? maxvis : p->maxrmargin > vbl ? p->maxrmargin - vbl : 0; } @@ -194,22 +196,23 @@ term_flushln(struct termp *p) for ( ; i < p->lastcol; i++) { if (vend > bp && jhy > 0 && i > jhy) break; - if ('\t' == p->buf[i]) + if (p->tcol->buf[i] == '\t') break; - if (' ' == p->buf[i]) { + if (p->tcol->buf[i] == ' ') { j = i; - while (i < p->lastcol && ' ' == p->buf[i]) + while (i < p->lastcol && + p->tcol->buf[i] == ' ') i++; dv = (i - j) * (*p->width)(p, ' '); vbl += dv; vend += dv; break; } - if (ASCII_NBRSP == p->buf[i]) { + if (p->tcol->buf[i] == ASCII_NBRSP) { vbl += (*p->width)(p, ' '); continue; } - if (ASCII_BREAK == p->buf[i]) + if (p->tcol->buf[i] == ASCII_BREAK) continue; /* @@ -223,11 +226,11 @@ term_flushln(struct termp *p) vbl = 0; } - (*p->letter)(p, p->buf[i]); - if (8 == p->buf[i]) - p->viscol -= (*p->width)(p, p->buf[i-1]); + (*p->letter)(p, p->tcol->buf[i]); + if (p->tcol->buf[i] == '\b') + p->viscol -= (*p->width)(p, p->tcol->buf[i-1]); else - p->viscol += (*p->width)(p, p->buf[i]); + p->viscol += (*p->width)(p, p->tcol->buf[i]); } vis = vend; } @@ -470,12 +473,12 @@ term_word(struct termp *p, const char *word) else { uc += p->col; p->col = 0; - if (p->offset > (size_t)(-uc)) { + if (p->tcol->offset > (size_t)(-uc)) { p->ti += uc; - p->offset += uc; + p->tcol->offset += uc; } else { - p->ti -= p->offset; - p->offset = 0; + p->ti -= p->tcol->offset; + p->tcol->offset = 0; } } continue; @@ -484,9 +487,9 @@ term_word(struct termp *p, const char *word) continue; uc = term_hspan(p, &su) / 24; if (uc <= 0) { - if (p->rmargin <= p->offset) + if (p->tcol->rmargin <= p->tcol->offset) continue; - lsz = p->rmargin - p->offset; + lsz = p->tcol->rmargin - p->tcol->offset; } else lsz = uc; while (sz && @@ -555,8 +558,8 @@ term_word(struct termp *p, const char *word) } /* Trim trailing backspace/blank pair. */ if (p->lastcol > 2 && - (p->buf[p->lastcol - 1] == ' ' || - p->buf[p->lastcol - 1] == '\t')) + (p->tcol->buf[p->lastcol - 1] == ' ' || + p->tcol->buf[p->lastcol - 1] == '\t')) p->lastcol -= 2; if (p->col > p->lastcol) p->col = p->lastcol; @@ -584,15 +587,13 @@ term_word(struct termp *p, const char *word) } static void -adjbuf(struct termp *p, size_t sz) +adjbuf(struct termp_col *c, size_t sz) { - - if (0 == p->maxcols) - p->maxcols = 1024; - while (sz >= p->maxcols) - p->maxcols <<= 2; - - p->buf = mandoc_reallocarray(p->buf, p->maxcols, sizeof(int)); + if (c->maxcols == 0) + c->maxcols = 1024; + while (c->maxcols <= sz) + c->maxcols <<= 2; + c->buf = mandoc_reallocarray(c->buf, c->maxcols, sizeof(*c->buf)); } static void @@ -602,10 +603,10 @@ bufferc(struct termp *p, char c) (*p->letter)(p, c); return; } - if (p->col + 1 >= p->maxcols) - adjbuf(p, p->col + 1); + if (p->col + 1 >= p->tcol->maxcols) + adjbuf(p->tcol, p->col + 1); if (p->lastcol <= p->col || (c != ' ' && c != ASCII_NBRSP)) - p->buf[p->col] = c; + p->tcol->buf[p->col] = c; if (p->lastcol < ++p->col) p->lastcol = p->col; } @@ -625,32 +626,33 @@ encode1(struct termp *p, int c) return; } - if (p->col + 7 >= p->maxcols) - adjbuf(p, p->col + 7); + if (p->col + 7 >= p->tcol->maxcols) + adjbuf(p->tcol, p->col + 7); f = (c == ASCII_HYPH || c > 127 || isgraph(c)) ? p->fontq[p->fonti] : TERMFONT_NONE; if (p->flags & TERMP_BACKBEFORE) { - if (p->buf[p->col - 1] == ' ' || p->buf[p->col - 1] == '\t') + if (p->tcol->buf[p->col - 1] == ' ' || + p->tcol->buf[p->col - 1] == '\t') p->col--; else - p->buf[p->col++] = 8; + p->tcol->buf[p->col++] = '\b'; p->flags &= ~TERMP_BACKBEFORE; } - if (TERMFONT_UNDER == f || TERMFONT_BI == f) { - p->buf[p->col++] = '_'; - p->buf[p->col++] = 8; + if (f == TERMFONT_UNDER || f == TERMFONT_BI) { + p->tcol->buf[p->col++] = '_'; + p->tcol->buf[p->col++] = '\b'; } - if (TERMFONT_BOLD == f || TERMFONT_BI == f) { - if (ASCII_HYPH == c) - p->buf[p->col++] = '-'; + if (f == TERMFONT_BOLD || f == TERMFONT_BI) { + if (c == ASCII_HYPH) + p->tcol->buf[p->col++] = '-'; else - p->buf[p->col++] = c; - p->buf[p->col++] = 8; + p->tcol->buf[p->col++] = c; + p->tcol->buf[p->col++] = '\b'; } if (p->lastcol <= p->col || (c != ' ' && c != ASCII_NBRSP)) - p->buf[p->col] = c; + p->tcol->buf[p->col] = c; if (p->lastcol < ++p->col) p->lastcol = p->col; if (p->flags & TERMP_BACKAFTER) { @@ -670,8 +672,8 @@ encode(struct termp *p, const char *word, size_t sz) return; } - if (p->col + 2 + (sz * 5) >= p->maxcols) - adjbuf(p, p->col + 2 + (sz * 5)); + if (p->col + 2 + (sz * 5) >= p->tcol->maxcols) + adjbuf(p->tcol, p->col + 2 + (sz * 5)); for (i = 0; i < sz; i++) { if (ASCII_HYPH == word[i] || @@ -680,7 +682,7 @@ encode(struct termp *p, const char *word, size_t sz) else { if (p->lastcol <= p->col || (word[i] != ' ' && word[i] != ASCII_NBRSP)) - p->buf[p->col] = word[i]; + p->tcol->buf[p->col] = word[i]; p->col++; /* diff --git a/usr.bin/mandoc/term.h b/usr.bin/mandoc/term.h index d9bd12809bb..68c0076670f 100644 --- a/usr.bin/mandoc/term.h +++ b/usr.bin/mandoc/term.h @@ -1,4 +1,4 @@ -/* $OpenBSD: term.h,v 1.68 2017/06/07 02:13:52 schwarze Exp $ */ +/* $OpenBSD: term.h,v 1.69 2017/06/07 17:38:08 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011-2015, 2017 Ingo Schwarze <schwarze@openbsd.org> @@ -49,24 +49,30 @@ struct termp_tbl { int decimal; /* decimal point position */ }; +struct termp_col { + int *buf; /* Output buffer. */ + size_t maxcols; /* Allocated bytes in buf. */ + size_t rmargin; /* Current right margin. */ + size_t offset; /* Current left margin. */ +}; + struct termp { - enum termtype type; - struct rofftbl tbl; /* table configuration */ - int synopsisonly; /* print the synopsis only */ - int mdocstyle; /* imitate mdoc(7) output */ + struct rofftbl tbl; /* Table configuration. */ + struct termp_col *tcols; /* Array of table columns. */ + struct termp_col *tcol; /* Current table column. */ + size_t maxtcol; /* Allocated table columns. */ size_t line; /* Current output line number. */ size_t defindent; /* Default indent for text. */ size_t defrmargin; /* Right margin of the device. */ size_t lastrmargin; /* Right margin before the last ll. */ - size_t rmargin; /* Current right margin. */ size_t maxrmargin; /* Max right margin. */ - size_t maxcols; /* Max size of buf. */ - size_t offset; /* Margin offest. */ size_t col; /* Byte position in buf. */ size_t lastcol; /* Bytes in buf. */ size_t viscol; /* Chars on current line. */ size_t trailspace; /* See termp_flushln(). */ size_t minbl; /* Minimum blanks before next field. */ + int synopsisonly; /* Print the synopsis only. */ + int mdocstyle; /* Imitate mdoc(7) output. */ int ti; /* Temporary indent for one line. */ int skipvsp; /* Vertical space to skip. */ int flags; @@ -90,7 +96,7 @@ struct termp { #define TERMP_NOBUF (1 << 17) /* Bypass output buffer. */ #define TERMP_NEWMC (1 << 18) /* No .mc printed yet. */ #define TERMP_ENDMC (1 << 19) /* Next break ends .mc mode. */ - int *buf; /* Output buffer. */ + enum termtype type; /* Terminal, PS, or PDF. */ enum termenc enc; /* Type of encoding. */ enum termfont fontl; /* Last font set. */ enum termfont *fontq; /* Symmetric fonts. */ diff --git a/usr.bin/mandoc/term_ascii.c b/usr.bin/mandoc/term_ascii.c index 7162db9a894..e66bbf752bf 100644 --- a/usr.bin/mandoc/term_ascii.c +++ b/usr.bin/mandoc/term_ascii.c @@ -1,4 +1,4 @@ -/* $OpenBSD: term_ascii.c,v 1.41 2017/05/08 15:33:43 schwarze Exp $ */ +/* $OpenBSD: term_ascii.c,v 1.42 2017/06/07 17:38:08 schwarze Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org> @@ -55,12 +55,14 @@ ascii_init(enum termenc enc, const struct manoutput *outopts) char *v; struct termp *p; - p = mandoc_calloc(1, sizeof(struct termp)); + p = mandoc_calloc(1, sizeof(*p)); + p->tcol = p->tcols = mandoc_calloc(1, sizeof(*p->tcol)); + p->maxtcol = 1; p->line = 1; p->defrmargin = p->lastrmargin = 78; p->fontq = mandoc_reallocarray(NULL, - (p->fontsz = 8), sizeof(enum termfont)); + (p->fontsz = 8), sizeof(*p->fontq)); p->fontq[0] = p->fontl = TERMFONT_NONE; p->begin = ascii_begin; @@ -136,7 +138,7 @@ ascii_setwidth(struct termp *p, int iop, int width) { width /= 24; - p->rmargin = p->defrmargin; + p->tcol->rmargin = p->defrmargin; if (iop > 0) p->defrmargin += width; else if (iop == 0) @@ -145,8 +147,8 @@ ascii_setwidth(struct termp *p, int iop, int width) p->defrmargin -= width; else p->defrmargin = 0; - p->lastrmargin = p->rmargin; - p->rmargin = p->maxrmargin = p->defrmargin; + p->lastrmargin = p->tcol->rmargin; + p->tcol->rmargin = p->maxrmargin = p->defrmargin; } void @@ -203,7 +205,7 @@ ascii_endline(struct termp *p) { p->line++; - p->offset -= p->ti; + p->tcol->offset -= p->ti; p->ti = 0; putchar('\n'); } @@ -358,7 +360,7 @@ locale_endline(struct termp *p) { p->line++; - p->offset -= p->ti; + p->tcol->offset -= p->ti; p->ti = 0; putwchar(L'\n'); } diff --git a/usr.bin/mandoc/term_ps.c b/usr.bin/mandoc/term_ps.c index ca19ff5cde8..f13c3ae1f2a 100644 --- a/usr.bin/mandoc/term_ps.c +++ b/usr.bin/mandoc/term_ps.c @@ -1,4 +1,4 @@ -/* $OpenBSD: term_ps.c,v 1.48 2017/05/08 15:33:43 schwarze Exp $ */ +/* $OpenBSD: term_ps.c,v 1.49 2017/06/07 17:38:08 schwarze Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2014, 2015, 2016, 2017 Ingo Schwarze <schwarze@openbsd.org> @@ -534,12 +534,15 @@ pspdf_alloc(const struct manoutput *outopts) size_t marginx, marginy, lineheight; const char *pp; - p = mandoc_calloc(1, sizeof(struct termp)); + p = mandoc_calloc(1, sizeof(*p)); + p->tcol = p->tcols = mandoc_calloc(1, sizeof(*p->tcol)); + p->maxtcol = 1; + p->enc = TERMENC_ASCII; p->fontq = mandoc_reallocarray(NULL, - (p->fontsz = 8), sizeof(enum termfont)); + (p->fontsz = 8), sizeof(*p->fontq)); p->fontq[0] = p->fontl = TERMFONT_NONE; - p->ps = mandoc_calloc(1, sizeof(struct termp_ps)); + p->ps = mandoc_calloc(1, sizeof(*p->ps)); p->advance = ps_advance; p->begin = ps_begin; @@ -1216,7 +1219,7 @@ ps_endline(struct termp *p) ps_closepage(p); - p->offset -= p->ti; + p->tcol->offset -= p->ti; p->ti = 0; } |