summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2017-05-08 15:34:54 +0000
committerIngo Schwarze <schwarze@openbsd.org>2017-05-08 15:34:54 +0000
commit743d8976911a7ef031de0fe12ef9ba67c3e7e5d4 (patch)
tree932d68bc5071b433591243f7ea70c4f9f7af959a
parent3d6c85a4e22160f04975c142bcdf4c4a12f39cbd (diff)
downloadmandoc-743d8976911a7ef031de0fe12ef9ba67c3e7e5d4.tar.gz
Basic implementation of the roff(7) .ti (temporary indent) request.
Needed by about four dozen ports (thanks to naddy@ for the research).
-rw-r--r--mdoc_man.c12
-rw-r--r--regress/roff/Makefile2
-rw-r--r--regress/roff/ti/Makefile5
-rw-r--r--regress/roff/ti/basic-man.in18
-rw-r--r--regress/roff/ti/basic-man.out_ascii21
-rw-r--r--regress/roff/ti/basic-mdoc.in21
-rw-r--r--regress/roff/ti/basic-mdoc.out_ascii17
-rw-r--r--roff.714
-rw-r--r--roff.c6
-rw-r--r--roff.h2
-rw-r--r--roff_html.c1
-rw-r--r--roff_term.c42
-rw-r--r--roff_validate.c1
-rw-r--r--term.h1
-rw-r--r--term_ascii.c6
-rw-r--r--term_ps.c5
16 files changed, 159 insertions, 15 deletions
diff --git a/mdoc_man.c b/mdoc_man.c
index fb4d17e1..cf97b1a2 100644
--- a/mdoc_man.c
+++ b/mdoc_man.c
@@ -101,10 +101,10 @@ static int pre_in(DECL_ARGS);
static int pre_it(DECL_ARGS);
static int pre_lk(DECL_ARGS);
static int pre_li(DECL_ARGS);
-static void pre_ll(DECL_ARGS);
static int pre_nm(DECL_ARGS);
static int pre_no(DECL_ARGS);
static int pre_ns(DECL_ARGS);
+static void pre_onearg(DECL_ARGS);
static int pre_pp(DECL_ARGS);
static int pre_rs(DECL_ARGS);
static int pre_sm(DECL_ARGS);
@@ -127,9 +127,10 @@ static void print_node(DECL_ARGS);
static const void_fp roff_manacts[ROFF_MAX] = {
pre_br,
pre_ft,
- pre_ll,
+ pre_onearg,
pre_sp,
pre_ta,
+ pre_onearg,
};
static const struct manact __manacts[MDOC_MAX - MDOC_Dd] = {
@@ -1565,9 +1566,12 @@ pre_lk(DECL_ARGS)
}
static void
-pre_ll(DECL_ARGS)
+pre_onearg(DECL_ARGS)
{
- print_line(".ll", 0);
+ outflags |= MMAN_nl;
+ print_word(".");
+ outflags &= ~MMAN_spc;
+ print_word(roff_name[n->tok]);
if (n->child != NULL)
print_word(n->child->string);
outflags |= MMAN_nl;
diff --git a/regress/roff/Makefile b/regress/roff/Makefile
index c97b99b1..0a464197 100644
--- a/regress/roff/Makefile
+++ b/regress/roff/Makefile
@@ -1,7 +1,7 @@
# $OpenBSD: Makefile,v 1.20 2015/02/06 16:05:51 schwarze Exp $
SUBDIR = args cond esc scale string
-SUBDIR += br cc de ds ft ig it ll na nr ps rm sp ta tr
+SUBDIR += br cc de ds ft ig it ll na nr ps rm sp ta ti tr
.include "../Makefile.sub"
.include <bsd.subdir.mk>
diff --git a/regress/roff/ti/Makefile b/regress/roff/ti/Makefile
new file mode 100644
index 00000000..4ac4cde0
--- /dev/null
+++ b/regress/roff/ti/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2017/05/07 17:30:58 schwarze Exp $
+
+REGRESS_TARGETS = basic-mdoc basic-man
+
+.include <bsd.regress.mk>
diff --git a/regress/roff/ti/basic-man.in b/regress/roff/ti/basic-man.in
new file mode 100644
index 00000000..deb1542f
--- /dev/null
+++ b/regress/roff/ti/basic-man.in
@@ -0,0 +1,18 @@
+.TH TI-BASIC-MAN 1 "May 8, 2014" OpenBSD
+.SH NAME
+ti-basic-man \- temporary indentation in man(7)
+.SH DESCRIPTION
+initial text
+.ti 10n
+This text is indented.
+However, the indent is temporary,
+so as soon as the line wraps, it is gone.
+.ti +10n
+The temporary indent can be relative.
+All the same, it will expire in the usual way.
+.ti -3n
+It is also possible to temporarily reduce the indentation,
+but that will also last until the next line break only.
+.ti -10n
+Reducing by more than the current offset
+starts the next line at the physical left margin.
diff --git a/regress/roff/ti/basic-man.out_ascii b/regress/roff/ti/basic-man.out_ascii
new file mode 100644
index 00000000..acc53f45
--- /dev/null
+++ b/regress/roff/ti/basic-man.out_ascii
@@ -0,0 +1,21 @@
+TI-BASIC-MAN(1) General Commands Manual TI-BASIC-MAN(1)
+
+
+
+NNAAMMEE
+ ti-basic-man - temporary indentation in man(7)
+
+DDEESSCCRRIIPPTTIIOONN
+ initial text
+ This text is indented. However, the indent is temporary, so as soon
+ as the line wraps, it is gone.
+ The temporary indent can be relative. All the same, it will
+ expire in the usual way.
+ It is also possible to temporarily reduce the indentation, but that will
+ also last until the next line break only.
+Reducing by more than the current offset starts the next line at the physical
+ left margin.
+
+
+
+OpenBSD May 8, 2014 TI-BASIC-MAN(1)
diff --git a/regress/roff/ti/basic-mdoc.in b/regress/roff/ti/basic-mdoc.in
new file mode 100644
index 00000000..0b165bc1
--- /dev/null
+++ b/regress/roff/ti/basic-mdoc.in
@@ -0,0 +1,21 @@
+.Dd May 8, 2017
+.Dt TI-BASIC-MDOC 1
+.Os OpenBSD
+.Sh NAME
+.Nm ti-basic-mdoc
+.Nd temporary indent in mdoc(7)
+.Sh DESCRIPTION
+initial text
+.ti 10n
+This text is indented.
+However, the indent is temporary,
+so as soon as the line wraps, it is gone.
+.ti +10n
+The temporary indent can be relative.
+All the same, it will expire in the usual way.
+.ti -3n
+It is also possible to temporarily reduce the indentation,
+but that will also last until the next line break only.
+.ti -10n
+Reducing by more than the current offset
+starts the next line at the physical left margin.
diff --git a/regress/roff/ti/basic-mdoc.out_ascii b/regress/roff/ti/basic-mdoc.out_ascii
new file mode 100644
index 00000000..a115b02d
--- /dev/null
+++ b/regress/roff/ti/basic-mdoc.out_ascii
@@ -0,0 +1,17 @@
+TI-BASIC-MDOC(1) General Commands Manual TI-BASIC-MDOC(1)
+
+NNAAMMEE
+ ttii--bbaassiicc--mmddoocc - temporary indent in mdoc(7)
+
+DDEESSCCRRIIPPTTIIOONN
+ initial text
+ This text is indented. However, the indent is temporary, so as soon
+ as the line wraps, it is gone.
+ The temporary indent can be relative. All the same, it will
+ expire in the usual way.
+ It is also possible to temporarily reduce the indentation, but that will
+ also last until the next line break only.
+Reducing by more than the current offset starts the next line at the physical
+ left margin.
+
+OpenBSD May 8, 2017 OpenBSD
diff --git a/roff.7 b/roff.7
index 265f7c7e..6dc1c1de 100644
--- a/roff.7
+++ b/roff.7
@@ -1,7 +1,7 @@
.\" $Id$
.\"
.\" Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
-.\" Copyright (c) 2010, 2011, 2013-2015 Ingo Schwarze <schwarze@openbsd.org>
+.\" Copyright (c) 2010,2011,2013-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
@@ -1585,9 +1585,15 @@ Currently unsupported.
End a table context.
See
.Sx \&TS .
-.It Ic \&tii Oo Cm + Ns | Ns Cm - Oc Ns Ar width
-Temporary indent.
-Currently unsupported.
+.It Ic \&ti Oo Cm + Ns | Ns Cm - Oc Ns Ar width
+Break the output line and indent the next output line by
+.Ar width .
+If a sign is specified, the temporary indentation is calculated
+relative to the current indentation; otherwise, it is absolute.
+The argument follows the syntax of
+.Sx Scaling Widths
+and the default scaling unit is
+.Cm m .
.It Ic \&tkf Ar font minps width1 maxps width2
Enable track kerning for a font.
Currently ignored.
diff --git a/roff.c b/roff.c
index 6c387e5e..763d78a7 100644
--- a/roff.c
+++ b/roff.c
@@ -213,7 +213,7 @@ static enum rofferr roff_userdef(ROFF_ARGS);
const char *__roff_name[MAN_MAX + 1] = {
"br", "ft", "ll", "sp",
- "ta", NULL,
+ "ta", "ti", NULL,
"ab", "ad", "af", "aln",
"als", "am", "am1", "ami",
"ami1", "as", "as1", "asciify",
@@ -264,7 +264,7 @@ const char *__roff_name[MAN_MAX + 1] = {
"spacewidth", "special", "spreadwarn", "ss",
"sty", "substring", "sv", "sy",
"T&", "tc", "TE",
- "TH", "ti", "tkf", "tl",
+ "TH", "tkf", "tl",
"tm", "tm1", "tmc", "tr",
"track", "transchar", "trf", "trimat",
"trin", "trnt", "troff", "TS",
@@ -324,6 +324,7 @@ static struct roffmac roffs[TOKEN_NONE] = {
{ roff_onearg, NULL, NULL, 0 }, /* ll */
{ roff_onearg, NULL, NULL, 0 }, /* sp */
{ roff_manyarg, NULL, NULL, 0 }, /* ta */
+ { roff_onearg, NULL, NULL, 0 }, /* ti */
{ NULL, NULL, NULL, 0 }, /* ROFF_MAX */
{ roff_unsupp, NULL, NULL, 0 }, /* ab */
{ roff_line_ignore, NULL, NULL, 0 }, /* ad */
@@ -525,7 +526,6 @@ static struct roffmac roffs[TOKEN_NONE] = {
{ roff_unsupp, NULL, NULL, 0 }, /* tc */
{ roff_TE, NULL, NULL, 0 }, /* TE */
{ roff_TH, NULL, NULL, 0 }, /* TH */
- { roff_unsupp, NULL, NULL, 0 }, /* ti */
{ roff_line_ignore, NULL, NULL, 0 }, /* tkf */
{ roff_unsupp, NULL, NULL, 0 }, /* tl */
{ roff_line_ignore, NULL, NULL, 0 }, /* tm */
diff --git a/roff.h b/roff.h
index ee701a75..4fd0fa42 100644
--- a/roff.h
+++ b/roff.h
@@ -71,6 +71,7 @@ enum roff_tok {
ROFF_ll,
ROFF_sp,
ROFF_ta,
+ ROFF_ti,
ROFF_MAX,
ROFF_ab,
ROFF_ad,
@@ -275,7 +276,6 @@ enum roff_tok {
ROFF_tc,
ROFF_TE,
ROFF_TH,
- ROFF_ti,
ROFF_tkf,
ROFF_tl,
ROFF_tm,
diff --git a/roff_html.c b/roff_html.c
index 5fd65d9f..e76ca544 100644
--- a/roff_html.c
+++ b/roff_html.c
@@ -37,6 +37,7 @@ static const roff_html_pre_fp roff_html_pre_acts[ROFF_MAX] = {
NULL, /* ll */
roff_html_pre_sp, /* sp */
NULL, /* ta */
+ NULL, /* ti */
};
diff --git a/roff_term.c b/roff_term.c
index 9786e0a6..3c2f24a9 100644
--- a/roff_term.c
+++ b/roff_term.c
@@ -32,6 +32,7 @@ static void roff_term_pre_ft(ROFF_TERM_ARGS);
static void roff_term_pre_ll(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 */
@@ -39,6 +40,7 @@ static const roff_term_pre_fp roff_term_pre_acts[ROFF_MAX] = {
roff_term_pre_ll, /* ft */
roff_term_pre_sp, /* sp */
roff_term_pre_ta, /* ta */
+ roff_term_pre_ti, /* ti */
};
@@ -121,3 +123,43 @@ roff_term_pre_ta(ROFF_TERM_ARGS)
for (n = n->child; n != NULL; n = n->next)
term_tab_set(p, n->string);
}
+
+static void
+roff_term_pre_ti(ROFF_TERM_ARGS)
+{
+ struct roffsu su;
+ const char *cp;
+ int len, sign;
+
+ roff_term_pre_br(p, n);
+
+ if (n->child == NULL)
+ return;
+ cp = n->child->string;
+ if (*cp == '+') {
+ sign = 1;
+ cp++;
+ } else if (*cp == '-') {
+ sign = -1;
+ cp++;
+ } else
+ sign = 0;
+
+ if (a2roffsu(cp, &su, SCALE_EM) == 0)
+ return;
+ len = term_hspan(p, &su) / 24;
+
+ if (sign == 0) {
+ p->ti = len - p->offset;
+ p->offset = len;
+ } else if (sign == 1) {
+ p->ti = len;
+ p->offset += len;
+ } else if ((size_t)len < p->offset) {
+ p->ti = -len;
+ p->offset -= len;
+ } else {
+ p->ti = -p->offset;
+ p->offset = 0;
+ }
+}
diff --git a/roff_validate.c b/roff_validate.c
index 05df6cb6..e1ee0ea9 100644
--- a/roff_validate.c
+++ b/roff_validate.c
@@ -36,6 +36,7 @@ static const roff_valid_fp roff_valids[ROFF_MAX] = {
NULL, /* ll */
NULL, /* sp */
NULL, /* ta */
+ NULL, /* ti */
};
diff --git a/term.h b/term.h
index f7f54428..e525f671 100644
--- a/term.h
+++ b/term.h
@@ -68,6 +68,7 @@ struct termp {
size_t viscol; /* Chars on current line. */
size_t trailspace; /* See termp_flushln(). */
int overstep; /* See termp_flushln(). */
+ int ti; /* Temporary indent for one line. */
int skipvsp; /* Vertical space to skip. */
int flags;
#define TERMP_SENTENCE (1 << 0) /* Space before a sentence. */
diff --git a/term_ascii.c b/term_ascii.c
index 1007ed28..60e8b5c8 100644
--- a/term_ascii.c
+++ b/term_ascii.c
@@ -1,7 +1,7 @@
/* $Id$ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 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
@@ -215,6 +215,8 @@ ascii_endline(struct termp *p)
{
p->line++;
+ p->offset -= p->ti;
+ p->ti = 0;
putchar('\n');
}
@@ -369,6 +371,8 @@ locale_endline(struct termp *p)
{
p->line++;
+ p->offset -= p->ti;
+ p->ti = 0;
putwchar(L'\n');
}
diff --git a/term_ps.c b/term_ps.c
index 4f5fef61..26e117e0 100644
--- a/term_ps.c
+++ b/term_ps.c
@@ -1,7 +1,7 @@
/* $Id$ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2014, 2015, 2016 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2014, 2015, 2016, 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
@@ -1219,6 +1219,9 @@ ps_endline(struct termp *p)
}
ps_closepage(p);
+
+ p->offset -= p->ti;
+ p->ti = 0;
}
static void