The Tcl/Tk manual pages use this extensively.
Delete the TERM_MAXMARGIN hack, it breaks .mc inside .nf;
instead, implement a proper TERMP_BRNEVER flag.
-.\" $OpenBSD: roff.7,v 1.63 2017/06/04 00:08:56 schwarze Exp $
+.\" $OpenBSD: roff.7,v 1.64 2017/06/04 22:43:50 schwarze Exp $
.\"
.\" Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
.\" Copyright (c) 2010,2011,2013-2015,2017 Ingo Schwarze <schwarze@openbsd.org>
Currently ignored.
.It Ic \&mc Ar glyph Op Ar dist
Print margin character in the right margin.
-Currently ignored.
+The
+.Ar dist
+is currently ignored; instead, 1n is used.
.It Ic \&mediasize Ar media
Set the device media size.
This is a Heirloom extension and currently ignored.
-/* $OpenBSD: man_term.c,v 1.154 2017/06/04 18:48:09 schwarze Exp $ */
+/* $OpenBSD: man_term.c,v 1.155 2017/06/04 22:43:50 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
static void
print_man_node(DECL_ARGS)
{
- size_t rm, rmax;
int c;
switch (n->type) {
if (mt->fl & MANT_LITERAL &&
! (p->flags & (TERMP_NOBREAK | TERMP_NONEWLINE)) &&
(n->next == NULL || n->next->flags & NODE_LINE)) {
- rm = p->rmargin;
- rmax = p->maxrmargin;
- p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
- p->flags |= TERMP_NOSPACE;
+ p->flags |= TERMP_BRNEVER | TERMP_NOSPACE;
if (n->string != NULL && *n->string != '\0')
term_flushln(p);
else
term_newln(p);
- if (rm < rmax && n->parent->tok == MAN_HP) {
- p->offset = rm;
- p->rmargin = rmax;
- } else
- p->rmargin = rm;
- p->maxrmargin = rmax;
+ p->flags &= ~TERMP_BRNEVER;
+ if (p->rmargin < p->maxrmargin && n->parent->tok == MAN_HP) {
+ p->offset = p->rmargin;
+ p->rmargin = p->maxrmargin;
+ }
}
if (NODE_EOS & n->flags)
p->flags |= TERMP_SENTENCE;
-/* $OpenBSD: mdoc_man.c,v 1.114 2017/05/30 16:31:25 schwarze Exp $ */
+/* $OpenBSD: mdoc_man.c,v 1.115 2017/06/04 22:43:50 schwarze Exp $ */
/*
* Copyright (c) 2011-2017 Ingo Schwarze <schwarze@openbsd.org>
*
pre_br,
pre_ft,
pre_onearg,
+ pre_onearg,
pre_sp,
pre_ta,
pre_onearg,
-/* $OpenBSD: mdoc_term.c,v 1.259 2017/06/04 18:48:09 schwarze Exp $ */
+/* $OpenBSD: mdoc_term.c,v 1.260 2017/06/04 22:43:50 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2017 Ingo Schwarze <schwarze@openbsd.org>
static int
termp_bd_pre(DECL_ARGS)
{
- size_t lm, len, rm, rmax;
+ size_t lm, len;
struct roff_node *nn;
int offset;
}
lm = p->offset;
- rm = p->rmargin;
- rmax = p->maxrmargin;
- p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
-
+ p->flags |= TERMP_BRNEVER;
for (nn = n->child; nn; nn = nn->next) {
if (DISP_centered == n->norm->Bd.type) {
if (nn->type == ROFFT_TEXT) {
len = term_strlen(p, nn->string);
- p->offset = len >= rm ? 0 :
- lm + len >= rm ? rm - len :
- (lm + rm - len) / 2;
+ p->offset = len >= p->rmargin ? 0 :
+ lm + len >= p->rmargin ? p->rmargin - len :
+ (lm + p->rmargin - len) / 2;
} else
p->offset = lm;
}
term_flushln(p);
p->flags |= TERMP_NOSPACE;
}
-
- p->rmargin = rm;
- p->maxrmargin = rmax;
+ p->flags &= ~TERMP_BRNEVER;
return 0;
}
static void
termp_bd_post(DECL_ARGS)
{
- size_t rm, rmax;
-
if (n->type != ROFFT_BODY)
return;
-
- rm = p->rmargin;
- rmax = p->maxrmargin;
-
if (DISP_literal == n->norm->Bd.type ||
DISP_unfilled == n->norm->Bd.type)
- p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
-
+ p->flags |= TERMP_BRNEVER;
p->flags |= TERMP_NOSPACE;
term_newln(p);
-
- p->rmargin = rm;
- p->maxrmargin = rmax;
+ p->flags &= ~TERMP_BRNEVER;
}
static int
-/* $OpenBSD: roff.c,v 1.175 2017/06/04 00:08:56 schwarze Exp $ */
+/* $OpenBSD: roff.c,v 1.176 2017/06/04 22:43:50 schwarze Exp $ */
/*
* Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
#define ROFFNUM_WHITE (1 << 1) /* Skip whitespace in roff_evalnum(). */
const char *__roff_name[MAN_MAX + 1] = {
- "br", "ft", "ll", "sp",
- "ta", "ti", NULL,
+ "br", "ft", "ll", "mc",
+ "sp", "ta", "ti", NULL,
"ab", "ad", "af", "aln",
"als", "am", "am1", "ami",
"ami1", "as", "as1", "asciify",
"lc", "lc_ctype", "lds", "length",
"letadj", "lf", "lg", "lhang",
"linetabs", "lnr", "lnrf", "lpfx",
- "ls", "lsm", "lt", "mc",
+ "ls", "lsm", "lt",
"mediasize", "minss", "mk", "mso",
"na", "ne", "nh", "nhychar",
"nm", "nn", "nop", "nr",
{ roff_br, NULL, NULL, 0 }, /* br */
{ roff_onearg, NULL, NULL, 0 }, /* ft */
{ roff_onearg, NULL, NULL, 0 }, /* ll */
+ { roff_onearg, NULL, NULL, 0 }, /* mc */
{ roff_onearg, NULL, NULL, 0 }, /* sp */
{ roff_manyarg, NULL, NULL, 0 }, /* ta */
{ roff_onearg, NULL, NULL, 0 }, /* ti */
{ roff_line_ignore, NULL, NULL, 0 }, /* ls */
{ roff_unsupp, NULL, NULL, 0 }, /* lsm */
{ roff_line_ignore, NULL, NULL, 0 }, /* lt */
- { roff_line_ignore, NULL, NULL, 0 }, /* mc */
{ roff_line_ignore, NULL, NULL, 0 }, /* mediasize */
{ roff_line_ignore, NULL, NULL, 0 }, /* minss */
{ roff_line_ignore, NULL, NULL, 0 }, /* mk */
-/* $OpenBSD: roff.h,v 1.30 2017/05/08 15:33:43 schwarze Exp $ */
+/* $OpenBSD: roff.h,v 1.31 2017/06/04 22:43:50 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
ROFF_br = 0,
ROFF_ft,
ROFF_ll,
+ ROFF_mc,
ROFF_sp,
ROFF_ta,
ROFF_ti,
ROFF_ls,
ROFF_lsm,
ROFF_lt,
- ROFF_mc,
ROFF_mediasize,
ROFF_minss,
ROFF_mk,
-/* $OpenBSD: roff_html.c,v 1.5 2017/05/08 15:33:43 schwarze Exp $ */
+/* $OpenBSD: roff_html.c,v 1.6 2017/06/04 22:43:50 schwarze Exp $ */
/*
* Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2017 Ingo Schwarze <schwarze@openbsd.org>
roff_html_pre_br, /* br */
NULL, /* ft */
NULL, /* ll */
+ NULL, /* mc */
roff_html_pre_sp, /* sp */
NULL, /* ta */
NULL, /* ti */
-/* $OpenBSD: roff_term.c,v 1.6 2017/05/08 15:33:43 schwarze Exp $ */
+/* $OpenBSD: roff_term.c,v 1.7 2017/06/04 22:43:50 schwarze Exp $ */
/*
* Copyright (c) 2010, 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
*
static void roff_term_pre_br(ROFF_TERM_ARGS);
static void roff_term_pre_ft(ROFF_TERM_ARGS);
static void roff_term_pre_ll(ROFF_TERM_ARGS);
+static void roff_term_pre_mc(ROFF_TERM_ARGS);
static void roff_term_pre_sp(ROFF_TERM_ARGS);
static void roff_term_pre_ta(ROFF_TERM_ARGS);
static void roff_term_pre_ti(ROFF_TERM_ARGS);
static const roff_term_pre_fp roff_term_pre_acts[ROFF_MAX] = {
roff_term_pre_br, /* br */
roff_term_pre_ft, /* ft */
- roff_term_pre_ll, /* ft */
+ roff_term_pre_ll, /* ll */
+ roff_term_pre_mc, /* mc */
roff_term_pre_sp, /* sp */
roff_term_pre_ta, /* ta */
roff_term_pre_ti, /* ti */
term_setwidth(p, n->child != NULL ? n->child->string : NULL);
}
+static void
+roff_term_pre_mc(ROFF_TERM_ARGS)
+{
+ if (p->col) {
+ p->flags |= TERMP_NOBREAK;
+ term_flushln(p);
+ p->flags &= ~(TERMP_NOBREAK | TERMP_NOSPACE);
+ }
+ if (n->child != NULL) {
+ p->mc = n->child->string;
+ p->flags |= TERMP_NEWMC;
+ } else
+ p->flags |= TERMP_ENDMC;
+}
+
static void
roff_term_pre_sp(ROFF_TERM_ARGS)
{
-/* $OpenBSD: roff_validate.c,v 1.5 2017/05/08 15:33:43 schwarze Exp $ */
+/* $OpenBSD: roff_validate.c,v 1.6 2017/06/04 22:43:50 schwarze Exp $ */
/*
* Copyright (c) 2010, 2017 Ingo Schwarze <schwarze@openbsd.org>
*
NULL, /* br */
roff_valid_ft, /* ft */
NULL, /* ll */
+ NULL, /* mc */
NULL, /* sp */
NULL, /* ta */
NULL, /* ti */
-/* $OpenBSD: tbl_term.c,v 1.31 2015/10/12 00:07:27 schwarze Exp $ */
+/* $OpenBSD: tbl_term.c,v 1.32 2017/06/04 22:43:50 schwarze Exp $ */
/*
* Copyright (c) 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2011, 2012, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2011,2012,2014,2015,2017 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
const struct tbl_cell *cp;
const struct tbl_dat *dp;
static size_t offset;
- size_t rmargin, maxrmargin, tsz;
+ size_t tsz;
int ic, horiz, spans, vert;
- rmargin = tp->rmargin;
- maxrmargin = tp->maxrmargin;
-
- tp->rmargin = tp->maxrmargin = TERM_MAXMARGIN;
-
/* Inhibit printing of spaces: we do padding ourselves. */
- tp->flags |= TERMP_NONOSPACE;
- tp->flags |= TERMP_NOSPACE;
+ tp->flags |= TERMP_NOSPACE | TERMP_NONOSPACE | TERMP_BRNEVER;
/*
* The first time we're invoked for a given table block,
tp->tbl.slen = term_tbl_strlen;
tp->tbl.arg = tp;
- tblcalc(&tp->tbl, sp, rmargin - tp->offset);
+ tblcalc(&tp->tbl, sp, tp->rmargin - tp->offset);
/* Center the table as a whole. */
for (ic = 0; ic < sp->opts->cols; ic++)
tsz += tp->tbl.cols[ic].width + 3;
tsz -= 3;
- if (offset + tsz > rmargin)
+ if (offset + tsz > tp->rmargin)
tsz -= 1;
- tp->offset = (offset + rmargin > tsz) ?
- (offset + rmargin - tsz) / 2 : 0;
+ tp->offset = (offset + tp->rmargin > tsz) ?
+ (offset + tp->rmargin - tsz) / 2 : 0;
}
/* Horizontal frame at the start of boxed tables. */
tp->tbl.cols = NULL;
tp->offset = offset;
}
-
- tp->flags &= ~TERMP_NONOSPACE;
- tp->rmargin = rmargin;
- tp->maxrmargin = maxrmargin;
+ tp->flags &= ~(TERMP_NONOSPACE | TERMP_BRNEVER);
}
/*
-/* $OpenBSD: term.c,v 1.123 2017/06/04 18:48:09 schwarze Exp $ */
+/* $OpenBSD: term.c,v 1.124 2017/06/04 22:43:50 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org>
static void bufferc(struct termp *, char);
static void encode(struct termp *, const char *, size_t);
static void encode1(struct termp *, int);
+static void endline(struct termp *);
void
* Find out whether we would exceed the right margin.
* If so, break to the next line.
*/
- if (vend > bp && 0 == jhy && vis > 0) {
+ if (vend > bp && 0 == jhy && vis > 0 &&
+ (p->flags & TERMP_BRNEVER) == 0) {
vend -= vis;
- (*p->endline)(p);
- p->viscol = 0;
+ endline(p);
/* Use pending tabs on the new line. */
vis = 0;
p->col = 0;
+ p->minbl = p->trailspace;
p->flags &= ~(TERMP_BACKAFTER | TERMP_BACKBEFORE | TERMP_NOPAD);
- if ( ! (TERMP_NOBREAK & p->flags)) {
- p->viscol = 0;
- p->minbl = 0;
- (*p->endline)(p);
- return;
- }
-
- if (TERMP_HANG & p->flags) {
- p->minbl = p->trailspace;
- return;
- }
-
/* Trailing whitespace is significant in some columns. */
if (vis && vbl && (TERMP_BRTRSP & p->flags))
vis += vbl;
/* If the column was overrun, break the line. */
- if (maxvis < vis + p->trailspace * (*p->width)(p, ' ')) {
- (*p->endline)(p);
- p->viscol = 0;
- p->minbl = 0;
- } else
- p->minbl = p->trailspace;
+ if ((p->flags & TERMP_NOBREAK) == 0 ||
+ ((p->flags & TERMP_HANG) == 0 &&
+ vis + p->trailspace * (*p->width)(p, ' ') > maxvis))
+ endline(p);
+}
+
+static void
+endline(struct termp *p)
+{
+ if ((p->flags & (TERMP_NEWMC | TERMP_ENDMC)) == TERMP_ENDMC) {
+ p->mc = NULL;
+ p->flags &= ~TERMP_ENDMC;
+ }
+ if (p->mc != NULL) {
+ if (p->viscol && p->maxrmargin >= p->viscol)
+ (*p->advance)(p, p->maxrmargin - p->viscol + 1);
+ p->flags |= TERMP_NOBUF | TERMP_NOSPACE;
+ term_word(p, p->mc);
+ p->flags &= ~(TERMP_NOBUF | TERMP_NEWMC);
+ }
+ p->viscol = 0;
+ p->minbl = 0;
+ (*p->endline)(p);
}
/*
term_newln(p);
p->viscol = 0;
+ p->minbl = 0;
if (0 < p->skipvsp)
p->skipvsp--;
else
size_t csz, lsz, ssz;
enum mandoc_esc esc;
- if ( ! (TERMP_NOSPACE & p->flags)) {
- if ( ! (TERMP_KEEP & p->flags)) {
- bufferc(p, ' ');
- if (TERMP_SENTENCE & p->flags)
+ if ((p->flags & TERMP_NOBUF) == 0) {
+ if ((p->flags & TERMP_NOSPACE) == 0) {
+ if ((p->flags & TERMP_KEEP) == 0) {
bufferc(p, ' ');
- } else
- bufferc(p, ASCII_NBRSP);
+ if (p->flags & TERMP_SENTENCE)
+ bufferc(p, ' ');
+ } else
+ bufferc(p, ASCII_NBRSP);
+ }
+ if (p->flags & TERMP_PREKEEP)
+ p->flags |= TERMP_KEEP;
+ if (p->flags & TERMP_NONOSPACE)
+ p->flags |= TERMP_NOSPACE;
+ else
+ p->flags &= ~TERMP_NOSPACE;
+ p->flags &= ~(TERMP_SENTENCE | TERMP_NONEWLINE);
+ p->skipvsp = 0;
}
- if (TERMP_PREKEEP & p->flags)
- p->flags |= TERMP_KEEP;
-
- if ( ! (p->flags & TERMP_NONOSPACE))
- p->flags &= ~TERMP_NOSPACE;
- else
- p->flags |= TERMP_NOSPACE;
-
- p->flags &= ~(TERMP_SENTENCE | TERMP_NONEWLINE);
- p->skipvsp = 0;
while ('\0' != *word) {
if ('\\' != *word) {
static void
bufferc(struct termp *p, char c)
{
-
+ if (p->flags & TERMP_NOBUF) {
+ (*p->letter)(p, c);
+ return;
+ }
if (p->col + 1 >= p->maxcols)
adjbuf(p, p->col + 1);
-
p->buf[p->col++] = c;
}
{
enum termfont f;
+ if (p->flags & TERMP_NOBUF) {
+ (*p->letter)(p, c);
+ return;
+ }
+
if (p->col + 7 >= p->maxcols)
adjbuf(p, p->col + 7);
{
size_t i;
+ if (p->flags & TERMP_NOBUF) {
+ for (i = 0; i < sz; i++)
+ (*p->letter)(p, word[i]);
+ return;
+ }
+
if (p->col + 2 + (sz * 5) >= p->maxcols)
adjbuf(p, p->col + 2 + (sz * 5));
-/* $OpenBSD: term.h,v 1.66 2017/06/04 18:48:09 schwarze Exp $ */
+/* $OpenBSD: term.h,v 1.67 2017/06/04 22:43:50 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011-2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
TERMFONT__MAX
};
-#define TERM_MAXMARGIN 100000 /* FIXME */
-
struct eqn;
struct roff_meta;
struct roff_node;
#define TERMP_NOSPLIT (1 << 13) /* Do not break line before .An. */
#define TERMP_SPLIT (1 << 14) /* Break line before .An. */
#define TERMP_NONEWLINE (1 << 15) /* No line break in nofill mode. */
+#define TERMP_BRNEVER (1 << 16) /* Don't even break at maxrmargin. */
+#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 termenc enc; /* Type of encoding. */
enum termfont fontl; /* Last font set. */
int (*hspan)(const struct termp *,
const struct roffsu *);
const void *argf; /* arg for headf/footf */
+ const char *mc; /* Margin character. */
struct termp_ps *ps;
};