source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Basic implementation of the roff(7) .ti (temporary indent)
@ 2017-05-08 15:35 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2017-05-08 15:35 UTC (permalink / raw)
  To: source

Log Message:
-----------
Basic implementation of the roff(7) .ti (temporary indent) request.
Needed by about four dozen ports (thanks to naddy@ for the research).

Modified Files:
--------------
    mdocml:
        mdoc_man.c
        roff.7
        roff.c
        roff.h
        roff_html.c
        roff_term.c
        roff_validate.c
        term.h
        term_ascii.c
        term_ps.c
    mdocml/regress/roff:
        Makefile

Added Files:
-----------
    mdocml/regress/roff/ti:
        Makefile
        basic-man.in
        basic-man.out_ascii
        basic-mdoc.in
        basic-mdoc.out_ascii

Revision Data
-------------
Index: Makefile
===================================================================
RCS file: /home/cvs/mdocml/mdocml/regress/roff/Makefile,v
retrieving revision 1.2
retrieving revision 1.3
diff -Lregress/roff/Makefile -Lregress/roff/Makefile -u -p -r1.2 -r1.3
--- regress/roff/Makefile
+++ 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>
Index: roff.7
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff.7,v
retrieving revision 1.79
retrieving revision 1.80
diff -Lroff.7 -Lroff.7 -u -p -r1.79 -r1.80
--- roff.7
+++ 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.
Index: term_ps.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/term_ps.c,v
retrieving revision 1.83
retrieving revision 1.84
diff -Lterm_ps.c -Lterm_ps.c -u -p -r1.83 -r1.84
--- term_ps.c
+++ 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
Index: roff.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff.c,v
retrieving revision 1.300
retrieving revision 1.301
diff -Lroff.c -Lroff.c -u -p -r1.300 -r1.301
--- roff.c
+++ roff.c
@@ -213,7 +213,7 @@ static	enum rofferr	 roff_userdef(ROFF_A
 
 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 */
Index: term_ascii.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/term_ascii.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -Lterm_ascii.c -Lterm_ascii.c -u -p -r1.55 -r1.56
--- term_ascii.c
+++ 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');
 }
 
Index: roff_html.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff_html.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -Lroff_html.c -Lroff_html.c -u -p -r1.4 -r1.5
--- roff_html.c
+++ roff_html.c
@@ -37,6 +37,7 @@ static	const roff_html_pre_fp roff_html_
 	NULL,  /* ll */
 	roff_html_pre_sp,  /* sp */
 	NULL,  /* ta */
+	NULL,  /* ti */
 };
 
 
Index: term.h
===================================================================
RCS file: /home/cvs/mdocml/mdocml/term.h,v
retrieving revision 1.120
retrieving revision 1.121
diff -Lterm.h -Lterm.h -u -p -r1.120 -r1.121
--- term.h
+++ 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. */
Index: mdoc_man.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_man.c,v
retrieving revision 1.114
retrieving revision 1.115
diff -Lmdoc_man.c -Lmdoc_man.c -u -p -r1.114 -r1.115
--- mdoc_man.c
+++ 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;
Index: roff_term.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff_term.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -Lroff_term.c -Lroff_term.c -u -p -r1.5 -r1.6
--- roff_term.c
+++ roff_term.c
@@ -32,6 +32,7 @@ static	void	  roff_term_pre_ft(ROFF_TERM
 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_
 	roff_term_pre_ll,  /* ft */
 	roff_term_pre_sp,  /* sp */
 	roff_term_pre_ta,  /* ta */
+	roff_term_pre_ti,  /* ti */
 };
 
 
@@ -120,4 +122,44 @@ roff_term_pre_ta(ROFF_TERM_ARGS)
 	term_tab_set(p, NULL);
 	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;
+	}
 }
Index: roff.h
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff.h,v
retrieving revision 1.47
retrieving revision 1.48
diff -Lroff.h -Lroff.h -u -p -r1.47 -r1.48
--- roff.h
+++ 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,
Index: roff_validate.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff_validate.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -Lroff_validate.c -Lroff_validate.c -u -p -r1.4 -r1.5
--- roff_validate.c
+++ roff_validate.c
@@ -36,6 +36,7 @@ static	const roff_valid_fp roff_valids[R
 	NULL,  /* ll */
 	NULL,  /* sp */
 	NULL,  /* ta */
+	NULL,  /* ti */
 };
 
 
--- /dev/null
+++ 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.
--- /dev/null
+++ 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>
--- /dev/null
+++ regress/roff/ti/basic-mdoc.out_ascii
@@ -0,0 +1,17 @@
+TI-BASIC-MDOC(1)            General Commands Manual           TI-BASIC-MDOC(1)
+
+N\bNA\bAM\bME\bE
+     t\bti\bi-\b-b\bba\bas\bsi\bic\bc-\b-m\bmd\bdo\boc\bc - temporary indent in mdoc(7)
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+     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
--- /dev/null
+++ regress/roff/ti/basic-man.out_ascii
@@ -0,0 +1,21 @@
+TI-BASIC-MAN(1)             General Commands Manual            TI-BASIC-MAN(1)
+
+
+
+N\bNA\bAM\bME\bE
+       ti-basic-man - temporary indentation in man(7)
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+       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)
--- /dev/null
+++ 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.
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-05-08 15:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-08 15:35 mdocml: Basic implementation of the roff(7) .ti (temporary indent) schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).