source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Naive implementation of the roff(7) .po (page offset) request.
@ 2017-06-14 22:51 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2017-06-14 22:51 UTC (permalink / raw)
  To: source

Log Message:
-----------
Naive implementation of the roff(7) .po (page offset) request.

This clearly works when .po is called on the top level, but might
not be sophisticated enough if people call .po inside indentation-changing
contexts, but i haven't seen that in manual pages (yet :).

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

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

Revision Data
-------------
Index: Makefile
===================================================================
RCS file: /home/cvs/mdocml/mdocml/regress/roff/Makefile,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lregress/roff/Makefile -Lregress/roff/Makefile -u -p -r1.3 -r1.4
--- 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 ti tr
+SUBDIR += br cc de ds ft ig it ll na nr po ps rm sp ta ti tr
 
 .include "../Makefile.sub"
 .include <bsd.subdir.mk>
Index: roff_validate.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff_validate.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -Lroff_validate.c -Lroff_validate.c -u -p -r1.8 -r1.9
--- roff_validate.c
+++ roff_validate.c
@@ -36,6 +36,7 @@ static	const roff_valid_fp roff_valids[R
 	roff_valid_ft,  /* ft */
 	NULL,  /* ll */
 	NULL,  /* mc */
+	NULL,  /* po */
 	NULL,  /* rj */
 	NULL,  /* sp */
 	NULL,  /* ta */
Index: roff.7
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff.7,v
retrieving revision 1.91
retrieving revision 1.92
diff -Lroff.7 -Lroff.7 -u -p -r1.91 -r1.92
--- roff.7
+++ roff.7
@@ -1441,8 +1441,15 @@ Currently ignored.
 Print all number registers on standard error output.
 Currently ignored.
 .It Ic \&po Op Oo Cm + Ns | Ns Cm - Oc Ns Ar offset
-Set horizontal page offset.
-Currently ignored.
+Set a horizontal page offset.
+If no argument is specified, the page offset is reverted to its
+previous value.
+If a sign is specified, the new page offset is calculated relative
+to the current one; otherwise, it is absolute.
+The argument follows the syntax of
+.Sx Scaling Widths
+and the default scaling unit is
+.Cm m .
 .It Ic \&ps Op Oo Cm + Ns | Ns Cm - Oc Ns size
 Change point size.
 Currently ignored.
Index: roff.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff.c,v
retrieving revision 1.311
retrieving revision 1.312
diff -Lroff.c -Lroff.c -u -p -r1.311 -r1.312
--- roff.c
+++ roff.c
@@ -223,8 +223,8 @@ static	enum rofferr	 roff_userdef(ROFF_A
 
 const char *__roff_name[MAN_MAX + 1] = {
 	"br",		"ce",		"ft",		"ll",
-	"mc",		"rj",		"sp",		"ta",
-	"ti",		NULL,
+	"mc",		"po",		"rj",		"sp",
+	"ta",		"ti",		NULL,
 	"ab",		"ad",		"af",		"aln",
 	"als",		"am",		"am1",		"ami",
 	"ami1",		"as",		"as1",		"asciify",
@@ -265,7 +265,7 @@ const char *__roff_name[MAN_MAX + 1] = {
 	"open",		"opena",	"os",		"output",
 	"padj",		"papersize",	"pc",		"pev",
 	"pi",		"PI",		"pl",		"pm",
-	"pn",		"pnr",		"po",		"ps",
+	"pn",		"pnr",		"ps",
 	"psbb",		"pshape",	"pso",		"ptr",
 	"pvs",		"rchar",	"rd",		"recursionlimit",
 	"return",	"rfschar",	"rhang",
@@ -335,6 +335,7 @@ static	struct roffmac	 roffs[TOKEN_NONE]
 	{ roff_onearg, NULL, NULL, 0 },  /* ft */
 	{ roff_onearg, NULL, NULL, 0 },  /* ll */
 	{ roff_onearg, NULL, NULL, 0 },  /* mc */
+	{ roff_onearg, NULL, NULL, 0 },  /* po */
 	{ roff_onearg, NULL, NULL, 0 },  /* rj */
 	{ roff_onearg, NULL, NULL, 0 },  /* sp */
 	{ roff_manyarg, NULL, NULL, 0 },  /* ta */
@@ -500,7 +501,6 @@ static	struct roffmac	 roffs[TOKEN_NONE]
 	{ roff_line_ignore, NULL, NULL, 0 },  /* pm */
 	{ roff_line_ignore, NULL, NULL, 0 },  /* pn */
 	{ roff_line_ignore, NULL, NULL, 0 },  /* pnr */
-	{ roff_line_ignore, NULL, NULL, 0 },  /* po */
 	{ roff_line_ignore, NULL, NULL, 0 },  /* ps */
 	{ roff_unsupp, NULL, NULL, 0 },  /* psbb */
 	{ roff_unsupp, NULL, NULL, 0 },  /* pshape */
Index: roff.h
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff.h,v
retrieving revision 1.53
retrieving revision 1.54
diff -Lroff.h -Lroff.h -u -p -r1.53 -r1.54
--- roff.h
+++ roff.h
@@ -77,6 +77,7 @@ enum	roff_tok {
 	ROFF_ft,
 	ROFF_ll,
 	ROFF_mc,
+	ROFF_po,
 	ROFF_rj,
 	ROFF_sp,
 	ROFF_ta,
@@ -245,7 +246,6 @@ enum	roff_tok {
 	ROFF_pm,
 	ROFF_pn,
 	ROFF_pnr,
-	ROFF_po,
 	ROFF_ps,
 	ROFF_psbb,
 	ROFF_pshape,
Index: roff_term.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff_term.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -Lroff_term.c -Lroff_term.c -u -p -r1.12 -r1.13
--- roff_term.c
+++ roff_term.c
@@ -32,6 +32,7 @@ static	void	  roff_term_pre_ce(ROFF_TERM
 static	void	  roff_term_pre_ft(ROFF_TERM_ARGS);
 static	void	  roff_term_pre_ll(ROFF_TERM_ARGS);
 static	void	  roff_term_pre_mc(ROFF_TERM_ARGS);
+static	void	  roff_term_pre_po(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);
@@ -42,6 +43,7 @@ static	const roff_term_pre_fp roff_term_
 	roff_term_pre_ft,  /* ft */
 	roff_term_pre_ll,  /* ll */
 	roff_term_pre_mc,  /* mc */
+	roff_term_pre_po,  /* po */
 	roff_term_pre_ce,  /* rj */
 	roff_term_pre_sp,  /* sp */
 	roff_term_pre_ta,  /* ta */
@@ -150,6 +152,28 @@ roff_term_pre_mc(ROFF_TERM_ARGS)
 		p->flags |= TERMP_NEWMC;
 	} else
 		p->flags |= TERMP_ENDMC;
+}
+
+static void
+roff_term_pre_po(ROFF_TERM_ARGS)
+{
+	struct roffsu	 su;
+	static int	 po, polast;
+	int		 ponew;
+
+	if (n->child != NULL &&
+	    a2roffsu(n->child->string, &su, SCALE_EM) != NULL) {
+		ponew = term_hen(p, &su);
+		if (*n->child->string == '+' ||
+		    *n->child->string == '-')
+			ponew += po;
+	} else
+		ponew = polast;
+	polast = po;
+	po = ponew;
+
+	ponew = po - polast + (int)p->tcol->offset;
+	p->tcol->offset = ponew > 0 ? ponew : 0;
 }
 
 static void
Index: roff_html.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff_html.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -Lroff_html.c -Lroff_html.c -u -p -r1.9 -r1.10
--- roff_html.c
+++ roff_html.c
@@ -38,6 +38,7 @@ static	const roff_html_pre_fp roff_html_
 	NULL,  /* ft */
 	NULL,  /* ll */
 	NULL,  /* mc */
+	NULL,  /* po */
 	roff_html_pre_ce,  /* rj */
 	roff_html_pre_sp,  /* sp */
 	NULL,  /* ta */
Index: mdoc_man.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_man.c,v
retrieving revision 1.121
retrieving revision 1.122
diff -Lmdoc_man.c -Lmdoc_man.c -u -p -r1.121 -r1.122
--- mdoc_man.c
+++ mdoc_man.c
@@ -130,6 +130,7 @@ static	const void_fp roff_manacts[ROFF_M
 	pre_ft,		/* ft */
 	pre_onearg,	/* ll */
 	pre_onearg,	/* mc */
+	pre_onearg,	/* po */
 	pre_onearg,	/* rj */
 	pre_sp,		/* sp */
 	pre_ta,		/* ta */
--- /dev/null
+++ regress/roff/po/basic-mdoc.out_ascii
@@ -0,0 +1,17 @@
+PO-BASIC-MDOC(1)            General Commands Manual           PO-BASIC-MDOC(1)
+
+N\bNA\bAM\bME\bE
+     p\bpo\bo-\b-b\bba\bas\bsi\bic\bc-\b-m\bmd\bdo\boc\bc - the roff page offset request
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+     initial text
+
+   shifted left
+
+        shifted right
+
+   shifted left
+
+     final text
+
+OpenBSD                          June 14, 2017                         OpenBSD
--- /dev/null
+++ regress/roff/po/basic-mdoc.in
@@ -0,0 +1,20 @@
+.Dd June 14, 2017
+.Dt PO-BASIC-MDOC 1
+.Os OpenBSD
+.Sh NAME
+.Nm po-basic-mdoc
+.Nd the roff page offset request
+.Sh DESCRIPTION
+initial text
+.Pp
+.po -2n
+shifted left
+.Pp
+.po +5n
+shifted right
+.Pp
+.po XXX
+shifted left
+.Pp
+.po 0
+final text
--- /dev/null
+++ regress/roff/po/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2017/05/08 15:33:43 schwarze Exp $
+
+REGRESS_TARGETS	= basic-mdoc
+
+.include <bsd.regress.mk>
--
 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-06-14 22:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-14 22:51 mdocml: Naive implementation of the roff(7) .po (page offset) request 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).