From aa8151b1157e8486bce7cb08deeb4c78df1d9669 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Mon, 8 May 2017 15:34:54 +0000 Subject: Basic implementation of the roff(7) .ti (temporary indent) request. Needed by about four dozen ports (thanks to naddy@ for the research). --- mdoc_man.c | 14 +++++++----- regress/roff/Makefile | 2 +- regress/roff/ti/Makefile | 5 +++++ regress/roff/ti/basic-man.in | 18 ++++++++++++++++ regress/roff/ti/basic-man.out_ascii | 21 ++++++++++++++++++ regress/roff/ti/basic-mdoc.in | 21 ++++++++++++++++++ regress/roff/ti/basic-mdoc.out_ascii | 17 +++++++++++++++ roff.7 | 16 +++++++++----- roff.c | 8 +++---- roff.h | 4 ++-- roff_html.c | 1 + roff_term.c | 42 ++++++++++++++++++++++++++++++++++++ roff_validate.c | 1 + term.h | 3 ++- term_ascii.c | 8 +++++-- term_ps.c | 7 ++++-- 16 files changed, 166 insertions(+), 22 deletions(-) create mode 100644 regress/roff/ti/Makefile create mode 100644 regress/roff/ti/basic-man.in create mode 100644 regress/roff/ti/basic-man.out_ascii create mode 100644 regress/roff/ti/basic-mdoc.in create mode 100644 regress/roff/ti/basic-mdoc.out_ascii diff --git a/mdoc_man.c b/mdoc_man.c index d926e386..4b792524 100644 --- a/mdoc_man.c +++ b/mdoc_man.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_man.c,v 1.114 2017/05/07 17:31:45 schwarze Exp $ */ +/* $Id: mdoc_man.c,v 1.115 2017/05/08 15:34:54 schwarze Exp $ */ /* * Copyright (c) 2011-2017 Ingo Schwarze * @@ -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 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 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 3c70a7e2..b6876e35 100644 --- a/roff.7 +++ b/roff.7 @@ -1,7 +1,7 @@ -.\" $Id: roff.7,v 1.79 2017/05/08 03:55:25 schwarze Exp $ +.\" $Id: roff.7,v 1.80 2017/05/08 15:34:54 schwarze Exp $ .\" .\" Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons -.\" Copyright (c) 2010, 2011, 2013-2015 Ingo Schwarze +.\" Copyright (c) 2010,2011,2013-2015,2017 Ingo Schwarze .\" .\" 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 8078fb99..8870d0c6 100644 --- a/roff.c +++ b/roff.c @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.300 2017/05/07 17:31:45 schwarze Exp $ */ +/* $Id: roff.c,v 1.301 2017/05/08 15:34:54 schwarze Exp $ */ /* * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons * Copyright (c) 2010-2015, 2017 Ingo Schwarze @@ -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 c4448b9f..f0c2bf44 100644 --- a/roff.h +++ b/roff.h @@ -1,4 +1,4 @@ -/* $Id: roff.h,v 1.47 2017/05/07 17:31:45 schwarze Exp $ */ +/* $Id: roff.h,v 1.48 2017/05/08 15:34:54 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze @@ -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 b69e6715..25600d42 100644 --- a/term.h +++ b/term.h @@ -1,4 +1,4 @@ -/* $Id: term.h,v 1.120 2017/05/07 17:31:45 schwarze Exp $ */ +/* $Id: term.h,v 1.121 2017/05/08 15:34:54 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2011-2015, 2017 Ingo Schwarze @@ -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 d0afafc4..97041619 100644 --- a/term_ascii.c +++ b/term_ascii.c @@ -1,7 +1,7 @@ -/* $Id: term_ascii.c,v 1.55 2017/05/07 17:31:45 schwarze Exp $ */ +/* $Id: term_ascii.c,v 1.56 2017/05/08 15:34:54 schwarze Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2014, 2015 Ingo Schwarze + * Copyright (c) 2014, 2015, 2017 Ingo Schwarze * * 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 696ff224..55d476e2 100644 --- a/term_ps.c +++ b/term_ps.c @@ -1,7 +1,7 @@ -/* $Id: term_ps.c,v 1.83 2017/02/17 14:31:52 schwarze Exp $ */ +/* $Id: term_ps.c,v 1.84 2017/05/08 15:34:54 schwarze Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2014, 2015, 2016 Ingo Schwarze + * Copyright (c) 2014, 2015, 2016, 2017 Ingo Schwarze * * 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 -- cgit v1.2.3-56-ge451