-/* $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>
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");
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;
* 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;
term_newln(p);
- if (NULL == n->child) {
- p->offset = mt->offset;
+ if (n->child == NULL) {
+ p->tcol->offset = mt->offset;
return 0;
}
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;
}
} 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;
}
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;
print_bvspace(p, n, mt->pardist);
break;
default:
- p->offset = mt->offset;
+ p->tcol->offset = mt->offset;
break;
}
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;
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;
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;
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;
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;
break;
case ROFFT_BODY:
term_newln(p);
- p->offset = mt->offset;
+ p->tcol->offset = mt->offset;
break;
default:
break;
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;
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;
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;
}
mt->offset -= n->parent->head->aux;
- p->offset = mt->offset;
+ p->tcol->offset = mt->offset;
if (--mt->lmarginsz < MAXMARGINS)
mt->lmargincur = mt->lmarginsz;
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)
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)
/* 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);
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);
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;
/* 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);
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.
-/* $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>
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");
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;
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
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;
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;
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;
}
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;
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);
}
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;
}
* 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;
* necessarily lengthened. Everybody gets the offset.
*/
- p->offset += offset;
+ p->tcol->offset += offset;
switch (type) {
case LIST_bullet:
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;
}
if (n->type == ROFFT_BODY) {
- if (NULL == n->child)
+ if (n->child == NULL)
return 0;
p->flags |= TERMP_NOSPACE;
cp = NULL;
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;
}
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;
}
}
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");
break;
case ROFFT_BODY:
term_newln(p);
- p->offset = 0;
+ p->tcol->offset = 0;
break;
default:
break;
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");
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;
}
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;
! 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;
}
/*
* 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) {
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);
/*
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");
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;
}
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;
}
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);
-/* $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>
*
{
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);
}
}
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;
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);
p->flags |= TERMP_NOSPACE;
term_flushln(p);
}
- p->offset = lm;
+ p->tcol->offset = lm;
}
static void
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;
}
}
-/* $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>
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. */
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);
}
-/* $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>
#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);
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);
}
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;
* 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;
*/
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]);
}
/*
/* 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;
}
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;
/*
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;
}
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;
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 &&
}
/* 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;
}
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
(*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;
}
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) {
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] ||
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++;
/*
-/* $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>
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;
#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. */
-/* $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>
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;
{
width /= 24;
- p->rmargin = p->defrmargin;
+ p->tcol->rmargin = p->defrmargin;
if (iop > 0)
p->defrmargin += width;
else if (iop == 0)
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
{
p->line++;
- p->offset -= p->ti;
+ p->tcol->offset -= p->ti;
p->ti = 0;
putchar('\n');
}
{
p->line++;
- p->offset -= p->ti;
+ p->tcol->offset -= p->ti;
p->ti = 0;
putwchar(L'\n');
}
-/* $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>
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;
ps_closepage(p);
- p->offset -= p->ti;
+ p->tcol->offset -= p->ti;
p->ti = 0;
}