summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2014-03-30 21:27:59 +0000
committerschwarze <schwarze@openbsd.org>2014-03-30 21:27:59 +0000
commit10111bf6ab9fc9007f57a5cb3f24b65ac7e68c86 (patch)
tree9f65ac0b9c128d1ea9dcbd638fd864e44d819e9f
parentClose the kernel fd before attempting to load /etc/random.seed, and reopen it (diff)
downloadwireguard-openbsd-10111bf6ab9fc9007f57a5cb3f24b65ac7e68c86.tar.xz
wireguard-openbsd-10111bf6ab9fc9007f57a5cb3f24b65ac7e68c86.zip
Support relative arguments to .ll (increase or decrease line length).
-rw-r--r--regress/usr.bin/mandoc/roff/ll/basic.in6
-rw-r--r--regress/usr.bin/mandoc/roff/ll/basic.out_ascii4
-rw-r--r--share/man/man7/roff.76
-rw-r--r--usr.bin/mandoc/man_term.c4
-rw-r--r--usr.bin/mandoc/mdoc_term.c4
-rw-r--r--usr.bin/mandoc/term.c32
-rw-r--r--usr.bin/mandoc/term.h6
-rw-r--r--usr.bin/mandoc/term_ascii.c20
-rw-r--r--usr.bin/mandoc/term_ps.c13
9 files changed, 68 insertions, 27 deletions
diff --git a/regress/usr.bin/mandoc/roff/ll/basic.in b/regress/usr.bin/mandoc/roff/ll/basic.in
index 15c7efaf933..9f03a5171b1 100644
--- a/regress/usr.bin/mandoc/roff/ll/basic.in
+++ b/regress/usr.bin/mandoc/roff/ll/basic.in
@@ -16,10 +16,10 @@ In ASCII mode, it is expected to break at column 38.
This is a longer text after switching back to the default line length.
In ASCII mode, it is expected to break at column 78.
.Pp
-.ll 200n
+.ll +100n
This is another long text to demonstrate longer lines.
In ASCII mode, it is not expected to break at all.
.Pp
-.ll
-This is a longer text after switching back to the default line length.
+.ll FOO
+This is a longer text after switching to an invalid line length.
In ASCII mode, it is expected to break at column 78.
diff --git a/regress/usr.bin/mandoc/roff/ll/basic.out_ascii b/regress/usr.bin/mandoc/roff/ll/basic.out_ascii
index bbf2a034322..47567bf5710 100644
--- a/regress/usr.bin/mandoc/roff/ll/basic.out_ascii
+++ b/regress/usr.bin/mandoc/roff/ll/basic.out_ascii
@@ -17,7 +17,7 @@ DDEESSCCRRIIPPTTIIOONN
This is another long text to demonstrate longer lines. In ASCII mode, it is not expected to break at all.
- This is a longer text after switching back to the default line length.
- In ASCII mode, it is expected to break at column 78.
+ This is a longer text after switching to an invalid line length. In
+ ASCII mode, it is expected to break at column 78.
OpenBSD February 5, 2014 OpenBSD
diff --git a/share/man/man7/roff.7 b/share/man/man7/roff.7
index ce6fbcb82e2..79f1748a074 100644
--- a/share/man/man7/roff.7
+++ b/share/man/man7/roff.7
@@ -1,4 +1,4 @@
-.\" $OpenBSD: roff.7,v 1.29 2014/03/30 19:47:32 schwarze Exp $
+.\" $OpenBSD: roff.7,v 1.30 2014/03/30 21:27:59 schwarze Exp $
.\"
.\" Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
.\" Copyright (c) 2010, 2011, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -876,12 +876,14 @@ request are discarded.
Change the output line length.
Its syntax is as follows:
.Pp
-.D1 Pf . Cm \&ll Op Ar width
+.D1 Pf . Cm \&ll Op Oo +|- Oc Ns Ar width
.Pp
If the
.Ar width
argument is omitted, the line length is reset to its previous value.
The default setting for terminal output is 78n.
+If a sign is given, the line length is added to or subtracted from;
+otherwise, it is set to the provided value.
Using this request in new manuals is discouraged for several reasons,
among others because it overrides the
.Xr mandoc 1
diff --git a/usr.bin/mandoc/man_term.c b/usr.bin/mandoc/man_term.c
index 5849fecd7eb..1028eabd5c7 100644
--- a/usr.bin/mandoc/man_term.c
+++ b/usr.bin/mandoc/man_term.c
@@ -1,4 +1,4 @@
-/* $Id: man_term.c,v 1.97 2014/03/30 19:47:32 schwarze Exp $ */
+/* $Id: man_term.c,v 1.98 2014/03/30 21:27:59 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -238,7 +238,7 @@ static int
pre_ll(DECL_ARGS)
{
- (*p->setwidth)(p, n->nchild ? a2width(p, n->child->string) : 0);
+ term_setwidth(p, n->nchild ? n->child->string : NULL);
return(0);
}
diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c
index 9c72d0762a2..de7080cc629 100644
--- a/usr.bin/mandoc/mdoc_term.c
+++ b/usr.bin/mandoc/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_term.c,v 1.162 2014/03/30 19:47:32 schwarze Exp $ */
+/* $Id: mdoc_term.c,v 1.163 2014/03/30 21:27:59 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -618,7 +618,7 @@ static int
termp_ll_pre(DECL_ARGS)
{
- (*p->setwidth)(p, n->nchild ? a2width(p, n->child->string) : 0);
+ term_setwidth(p, n->nchild ? n->child->string : NULL);
return(0);
}
diff --git a/usr.bin/mandoc/term.c b/usr.bin/mandoc/term.c
index 3da0c8fe710..f1809195e9d 100644
--- a/usr.bin/mandoc/term.c
+++ b/usr.bin/mandoc/term.c
@@ -1,4 +1,4 @@
-/* $Id: term.c,v 1.79 2014/03/21 22:17:01 schwarze Exp $ */
+/* $Id: term.c,v 1.80 2014/03/30 21:27:59 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -619,6 +619,36 @@ encode(struct termp *p, const char *word, size_t sz)
}
}
+void
+term_setwidth(struct termp *p, const char *wstr)
+{
+ struct roffsu su;
+ size_t width;
+ int iop;
+
+ if (NULL != wstr) {
+ switch (*wstr) {
+ case ('+'):
+ iop = 1;
+ wstr++;
+ break;
+ case ('-'):
+ iop = -1;
+ wstr++;
+ break;
+ default:
+ iop = 0;
+ break;
+ }
+ if ( ! a2roffsu(wstr, &su, SCALE_MAX)) {
+ wstr = NULL;
+ iop = 0;
+ }
+ }
+ width = (NULL != wstr) ? term_hspan(p, &su) : 0;
+ (*p->setwidth)(p, iop, width);
+}
+
size_t
term_len(const struct termp *p, size_t sz)
{
diff --git a/usr.bin/mandoc/term.h b/usr.bin/mandoc/term.h
index f57a201fcf4..6a63dd084e7 100644
--- a/usr.bin/mandoc/term.h
+++ b/usr.bin/mandoc/term.h
@@ -1,4 +1,4 @@
-/* $Id: term.h,v 1.42 2014/03/30 19:47:32 schwarze Exp $ */
+/* $Id: term.h,v 1.43 2014/03/30 21:27:59 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -95,7 +95,7 @@ struct termp {
void (*end)(struct termp *);
void (*endline)(struct termp *);
void (*advance)(struct termp *, size_t);
- void (*setwidth)(struct termp *, size_t);
+ void (*setwidth)(struct termp *, int, size_t);
size_t (*width)(const struct termp *, int);
double (*hspan)(const struct termp *,
const struct roffsu *);
@@ -114,7 +114,7 @@ void term_begin(struct termp *, term_margin,
term_margin, const void *);
void term_end(struct termp *);
-void term_setwidth(struct termp *, size_t);
+void term_setwidth(struct termp *, const char *);
size_t term_hspan(const struct termp *,
const struct roffsu *);
size_t term_vspan(const struct termp *,
diff --git a/usr.bin/mandoc/term_ascii.c b/usr.bin/mandoc/term_ascii.c
index dc08112d7fb..7deeb630cb6 100644
--- a/usr.bin/mandoc/term_ascii.c
+++ b/usr.bin/mandoc/term_ascii.c
@@ -1,4 +1,4 @@
-/* $Id: term_ascii.c,v 1.12 2014/03/30 19:47:32 schwarze Exp $ */
+/* $Id: term_ascii.c,v 1.13 2014/03/30 21:27:59 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -39,7 +39,7 @@ static void ascii_begin(struct termp *);
static void ascii_end(struct termp *);
static void ascii_endline(struct termp *);
static void ascii_letter(struct termp *, int);
-static void ascii_setwidth(struct termp *, size_t);
+static void ascii_setwidth(struct termp *, int, size_t);
static void locale_advance(struct termp *, size_t);
static void locale_endline(struct termp *);
@@ -138,14 +138,18 @@ locale_alloc(char *outopts)
}
static void
-ascii_setwidth(struct termp *p, size_t width)
+ascii_setwidth(struct termp *p, int iop, size_t width)
{
- size_t lastwidth;
- lastwidth = p->defrmargin;
- p->rmargin = p->maxrmargin = p->defrmargin =
- width ? width : p->lastrmargin;
- p->lastrmargin = lastwidth;
+ p->rmargin = p->defrmargin;
+ if (0 < iop)
+ p->defrmargin += width;
+ else if (0 > iop)
+ p->defrmargin -= width;
+ else
+ p->defrmargin = width ? width : p->lastrmargin;
+ p->lastrmargin = p->rmargin;
+ p->rmargin = p->maxrmargin = p->defrmargin;
}
/* ARGSUSED */
diff --git a/usr.bin/mandoc/term_ps.c b/usr.bin/mandoc/term_ps.c
index 64876299ddd..83ba17bc738 100644
--- a/usr.bin/mandoc/term_ps.c
+++ b/usr.bin/mandoc/term_ps.c
@@ -1,4 +1,4 @@
-/* $Id: term_ps.c,v 1.22 2014/03/30 19:47:32 schwarze Exp $ */
+/* $Id: term_ps.c,v 1.23 2014/03/30 21:27:59 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -99,7 +99,7 @@ static void ps_pletter(struct termp *, int);
static void ps_printf(struct termp *, const char *, ...);
static void ps_putchar(struct termp *, char);
static void ps_setfont(struct termp *, enum termfont);
-static void ps_setwidth(struct termp *, size_t);
+static void ps_setwidth(struct termp *, int, size_t);
static struct termp *pspdf_alloc(char *);
static void pdf_obj(struct termp *, size_t);
@@ -529,12 +529,17 @@ pspdf_alloc(char *outopts)
static void
-ps_setwidth(struct termp *p, size_t width)
+ps_setwidth(struct termp *p, int iop, size_t width)
{
size_t lastwidth;
lastwidth = p->ps->width;
- p->ps->width = width ? width : p->ps->lastwidth;
+ if (0 < iop)
+ p->ps->width += width;
+ else if (0 > iop)
+ p->ps->width -= width;
+ else
+ p->ps->width = width ? width : p->ps->lastwidth;
p->ps->lastwidth = lastwidth;
}