summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--man_term.c118
-rw-r--r--mdoc_term.c148
-rw-r--r--roff_term.c28
-rw-r--r--tbl_term.c12
-rw-r--r--term.c134
-rw-r--r--term.h22
-rw-r--r--term_ascii.c16
-rw-r--r--term_ps.c11
8 files changed, 253 insertions, 236 deletions
diff --git a/man_term.c b/man_term.c
index 8a047d8b..749f342b 100644
--- a/man_term.c
+++ b/man_term.c
@@ -141,7 +141,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");
@@ -228,7 +228,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;
@@ -238,9 +238,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;
@@ -359,8 +359,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;
}
@@ -380,13 +380,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;
}
@@ -435,8 +435,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;
}
@@ -460,8 +460,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;
@@ -478,7 +478,7 @@ pre_PP(DECL_ARGS)
print_bvspace(p, n, mt->pardist);
break;
default:
- p->offset = mt->offset;
+ p->tcol->offset = mt->offset;
break;
}
@@ -522,8 +522,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;
@@ -536,8 +536,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;
@@ -555,11 +555,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;
@@ -604,8 +604,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;
@@ -624,8 +624,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;
@@ -646,7 +646,7 @@ post_TP(DECL_ARGS)
break;
case ROFFT_BODY:
term_newln(p);
- p->offset = mt->offset;
+ p->tcol->offset = mt->offset;
break;
default:
break;
@@ -681,14 +681,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;
@@ -743,14 +743,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;
@@ -804,8 +804,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;
@@ -829,7 +829,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;
@@ -935,9 +935,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)
@@ -994,8 +995,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)
@@ -1004,9 +1005,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);
@@ -1017,8 +1019,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);
@@ -1045,8 +1047,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;
@@ -1056,9 +1058,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);
@@ -1067,17 +1069,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/mdoc_term.c b/mdoc_term.c
index ed462d61..fd7dd53a 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -259,7 +259,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");
@@ -316,8 +316,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;
@@ -407,8 +407,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
@@ -428,9 +428,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;
@@ -438,16 +438,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;
@@ -455,8 +455,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;
}
@@ -496,8 +496,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;
@@ -505,26 +505,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);
}
@@ -649,8 +649,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;
}
@@ -714,8 +714,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;
@@ -815,7 +815,7 @@ termp_it_pre(DECL_ARGS)
* necessarily lengthened. Everybody gets the offset.
*/
- p->offset += offset;
+ p->tcol->offset += offset;
switch (type) {
case LIST_bullet:
@@ -825,21 +825,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;
@@ -945,7 +945,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;
@@ -954,9 +954,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;
}
@@ -967,18 +968,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;
}
}
@@ -1250,7 +1251,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");
@@ -1281,7 +1282,7 @@ termp_sh_post(DECL_ARGS)
break;
case ROFFT_BODY:
term_newln(p);
- p->offset = 0;
+ p->tcol->offset = 0;
break;
default:
break;
@@ -1303,7 +1304,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");
@@ -1334,8 +1335,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;
}
@@ -1351,8 +1352,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;
@@ -1429,15 +1430,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;
}
/*
@@ -1448,9 +1449,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) {
@@ -1459,17 +1460,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);
/*
@@ -1553,10 +1555,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");
@@ -1803,8 +1805,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;
}
@@ -1816,8 +1818,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;
}
@@ -1965,7 +1967,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/roff_term.c b/roff_term.c
index 2eb72dcc..17c1f043 100644
--- a/roff_term.c
+++ b/roff_term.c
@@ -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/tbl_term.c b/tbl_term.c
index c436481b..c6e58b4c 100644
--- a/tbl_term.c
+++ b/tbl_term.c
@@ -80,21 +80,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. */
@@ -193,7 +193,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/term.c b/term.c
index 26c93a79..4b8502fc 100644
--- a/term.c
+++ b/term.c
@@ -32,7 +32,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);
@@ -42,8 +42,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);
}
@@ -94,23 +95,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;
@@ -123,7 +124,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;
@@ -139,31 +140,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]);
}
/*
@@ -184,10 +185,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;
}
@@ -196,22 +198,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;
/*
@@ -225,11 +228,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;
}
@@ -472,12 +475,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;
@@ -486,9 +489,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 &&
@@ -557,8 +560,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;
@@ -586,15 +589,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
@@ -604,10 +605,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;
}
@@ -627,32 +628,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) {
@@ -672,8 +674,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] ||
@@ -682,7 +684,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/term.h b/term.h
index fa51d633..f13ad2ea 100644
--- a/term.h
+++ b/term.h
@@ -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/term_ascii.c b/term_ascii.c
index 60e8b5c8..155fdc3a 100644
--- a/term_ascii.c
+++ b/term_ascii.c
@@ -65,12 +65,14 @@ ascii_init(enum termenc enc, const struct manoutput *outopts)
#endif
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;
@@ -148,7 +150,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)
@@ -157,8 +159,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
@@ -215,7 +217,7 @@ ascii_endline(struct termp *p)
{
p->line++;
- p->offset -= p->ti;
+ p->tcol->offset -= p->ti;
p->ti = 0;
putchar('\n');
}
@@ -371,7 +373,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/term_ps.c b/term_ps.c
index 26e117e0..f66a8cbd 100644
--- a/term_ps.c
+++ b/term_ps.c
@@ -538,12 +538,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;
@@ -1220,7 +1223,7 @@ ps_endline(struct termp *p)
ps_closepage(p);
- p->offset -= p->ti;
+ p->tcol->offset -= p->ti;
p->ti = 0;
}