aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2017-06-01 19:05:37 +0000
committerIngo Schwarze <schwarze@openbsd.org>2017-06-01 19:05:37 +0000
commit41ca712e6e6b6ad1b09c0abcbe87b01ea039b2be (patch)
treeec9d7acf6d3d88ba8497512fa6e9deea45745d4b
parent5325cd99ac197268bd26af0ee01d0539cb78cb61 (diff)
downloadmandoc-41ca712e6e6b6ad1b09c0abcbe87b01ea039b2be.tar.gz
mandoc-41ca712e6e6b6ad1b09c0abcbe87b01ea039b2be.tar.zst
mandoc-41ca712e6e6b6ad1b09c0abcbe87b01ea039b2be.zip
Minimal implementation of the \h (horizontal motion) escape sequence.
Good enough to cope with the average DocBook insanity.
-rw-r--r--mandoc.c4
-rw-r--r--mandoc.h3
-rw-r--r--mdoc_term.c5
-rw-r--r--regress/roff/esc/h.in4
-rw-r--r--roff.711
-rw-r--r--term.c24
6 files changed, 38 insertions, 13 deletions
diff --git a/mandoc.c b/mandoc.c
index d265463b..2ff4e186 100644
--- a/mandoc.c
+++ b/mandoc.c
@@ -1,4 +1,4 @@
-/* $Id: mandoc.c,v 1.98 2015/11/12 22:44:27 schwarze Exp $ */
+/* $Id: mandoc.c,v 1.99 2017/06/01 19:05:37 schwarze Exp $ */
/*
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011-2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -175,7 +175,7 @@ mandoc_escape(const char **end, const char **start, int *sz)
++*end;
return ESCAPE_ERROR;
}
- gly = ESCAPE_IGNORE;
+ gly = (*start)[-1] == 'h' ? ESCAPE_HORIZ : ESCAPE_IGNORE;
term = **start;
*start = ++*end;
break;
diff --git a/mandoc.h b/mandoc.h
index f18d2d12..c15ed4d0 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -1,4 +1,4 @@
-/* $Id: mandoc.h,v 1.219 2017/06/01 15:25:39 schwarze Exp $ */
+/* $Id: mandoc.h,v 1.220 2017/06/01 19:05:37 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -411,6 +411,7 @@ enum mandoc_esc {
ESCAPE_NUMBERED, /* a numbered glyph */
ESCAPE_UNICODE, /* a unicode codepoint */
ESCAPE_NOSPACE, /* suppress space if the last on a line */
+ ESCAPE_HORIZ, /* horizontal movement */
ESCAPE_SKIPCHAR, /* skip the next character */
ESCAPE_OVERSTRIKE /* overstrike all chars in the argument */
};
diff --git a/mdoc_term.c b/mdoc_term.c
index 382804d5..77bb6be2 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_term.c,v 1.358 2017/05/30 16:31:29 schwarze Exp $ */
+/* $Id: mdoc_term.c,v 1.359 2017/06/01 19:05:37 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -407,7 +407,8 @@ print_mdoc_node(DECL_ARGS)
if (NODE_EOS & n->flags)
p->flags |= TERMP_SENTENCE;
- p->offset = offset;
+ if (n->type != ROFFT_TEXT)
+ p->offset = offset;
p->rmargin = rmargin;
}
diff --git a/regress/roff/esc/h.in b/regress/roff/esc/h.in
index 31fbb4e2..4bc1953e 100644
--- a/regress/roff/esc/h.in
+++ b/regress/roff/esc/h.in
@@ -7,11 +7,11 @@
.Sh DESCRIPTION
simple: >\h'0'<
.br
-escape only: >\h'\w'\&''<
+escape only: >\h'\w'\&'M'<
.br
escape at the end: >\h'0+\w'\&''<
.br
-escape at the beginning: >\h'\w'\&'+0'<
+escape at the beginning: >\h'\w'\&'M+0'<
.br
escape in the middle: >\h'0+\w'\&'+0'<
.br
diff --git a/roff.7 b/roff.7
index b6876e35..bfce9b16 100644
--- a/roff.7
+++ b/roff.7
@@ -1,4 +1,4 @@
-.\" $Id: roff.7,v 1.80 2017/05/08 15:34:54 schwarze Exp $
+.\" $Id: roff.7,v 1.81 2017/06/01 19:05:37 schwarze Exp $
.\"
.\" Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
.\" Copyright (c) 2010,2011,2013-2015,2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -15,7 +15,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: May 8 2017 $
+.Dd $Mdocdate: June 1 2017 $
.Dt ROFF 7
.Os
.Sh NAME
@@ -1925,9 +1925,10 @@ and
.Ss \eH\(aq Ns Oo +|- Oc Ns Ar number Ns \(aq
Set the height of the current font; ignored by
.Xr mandoc 1 .
-.Ss \eh\(aq Ns Ar number Ns \(aq
-Horizontal motion; ignored by
-.Xr mandoc 1 .
+.Ss \eh\(aq Ns Ar width Ns \(aq
+Horizontal motion relative to the current position.
+The default scaling unit is
+.Cm m .
.Ss \ek[ Ns Ar name ]
Mark horizontal input place in register; ignored by
.Xr mandoc 1 .
diff --git a/term.c b/term.c
index f2553d89..266c49e7 100644
--- a/term.c
+++ b/term.c
@@ -1,4 +1,4 @@
-/* $Id: term.c,v 1.260 2017/05/07 17:31:45 schwarze Exp $ */
+/* $Id: term.c,v 1.261 2017/06/01 19:05:37 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -400,6 +400,7 @@ term_fontpop(struct termp *p)
void
term_word(struct termp *p, const char *word)
{
+ struct roffsu su;
const char nbrsp[2] = { ASCII_NBRSP, 0 };
const char *seq, *cp;
int sz, uc;
@@ -488,6 +489,27 @@ term_word(struct termp *p, const char *word)
else if (*word == '\0')
p->flags |= (TERMP_NOSPACE | TERMP_NONEWLINE);
continue;
+ case ESCAPE_HORIZ:
+ if (a2roffsu(seq, &su, SCALE_EM) == 0)
+ continue;
+ uc = term_hspan(p, &su) / 24;
+ if (uc > 0)
+ while (uc-- > 0)
+ bufferc(p, ASCII_NBRSP);
+ else if (p->col > (size_t)(-uc))
+ p->col += uc;
+ else {
+ uc += p->col;
+ p->col = 0;
+ if (p->offset > (size_t)(-uc)) {
+ p->ti += uc;
+ p->offset += uc;
+ } else {
+ p->ti -= p->offset;
+ p->offset = 0;
+ }
+ }
+ continue;
case ESCAPE_SKIPCHAR:
p->flags |= TERMP_BACKAFTER;
continue;