source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Partial support for the \n[an-margin] number register.
@ 2017-06-13 19:34 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2017-06-13 19:34 UTC (permalink / raw)
  To: source

Log Message:
-----------
Partial support for the \n[an-margin] number register.

Manuals autogenerated from reStructuredText are reckless enough
to peek at this non-portable, implementation-dependent, highly
groff-specific internal register - for no good reason, because the
man(7) language natively provides in a much simpler way what they
are trying to emulate here with much fragility.

A full implementation would be very hard because it would require
access to output-device-specific formatting data at the roff(7)
preprocessor stage, which mandoc doesn't support at all.   
So hardcode a few magic numbers as reStructuredText expects them
for terminal output.  For other output modes (like HTML), code using
this register is utterly broken anyway.

Modified Files:
--------------
    mdocml:
        man_macro.c
    mdocml/regress/man/RS:
        Makefile

Added Files:
-----------
    mdocml/regress/man/RS:
        an-margin.in
        an-margin.out_ascii

Revision Data
-------------
Index: man_macro.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/man_macro.c,v
retrieving revision 1.120
retrieving revision 1.121
diff -Lman_macro.c -Lman_macro.c -u -p -r1.120 -r1.121
--- man_macro.c
+++ man_macro.c
@@ -235,6 +235,10 @@ blk_close(MACRO_PROT_ARGS)
 		ntok = man->last->tok;
 		man_unscope(man, nn);
 
+		if (tok == MAN_RE && nn->head->aux > 0)
+			roff_setreg(man->roff, "an-margin",
+			    nn->head->aux, '-');
+
 		/* Move a trailing paragraph behind the block. */
 
 		if (ntok == MAN_LP || ntok == MAN_PP || ntok == MAN_P) {
@@ -256,8 +260,17 @@ blk_exp(MACRO_PROT_ARGS)
 	head = roff_head_alloc(man, line, ppos, tok);
 
 	la = *pos;
-	if (man_args(man, line, pos, buf, &p))
+	if (man_args(man, line, pos, buf, &p)) {
 		roff_word_alloc(man, line, la, p);
+		if (tok == MAN_RS) {
+			if (roff_getreg(man->roff, "an-margin") == 0)
+				roff_setreg(man->roff, "an-margin",
+				    7 * 24, '=');
+			if ((head->aux = strtod(p, NULL) * 24.0) > 0)
+				roff_setreg(man->roff, "an-margin",
+				    head->aux, '+');
+		}
+	}
 
 	if (buf[*pos] != '\0')
 		mandoc_vmsg(MANDOCERR_ARG_EXCESS, man->parse, line,
--- /dev/null
+++ regress/man/RS/an-margin.in
@@ -0,0 +1,24 @@
+.TH RS-AN-MARGIN 1 "June 13, 2017" OpenBSD
+.SH NAME
+RS-an-margin \- reStructuredText peeks at an internal register
+.SH DESCRIPTION
+regular
+text
+.RS 0.0
+zero
+indent
+\n[an-margin]
+.RS 3.5
+non-zero
+indent
+\n[an-margin]
+.RE
+back to
+zero
+indent
+\n[an-margin]
+.RE
+back to
+regular
+text
+\n[an-margin]
--- /dev/null
+++ regress/man/RS/an-margin.out_ascii
@@ -0,0 +1,17 @@
+RS-AN-MARGIN(1)             General Commands Manual            RS-AN-MARGIN(1)
+
+
+
+N\bNA\bAM\bME\bE
+       RS-an-margin - reStructuredText peeks at an internal register
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+       regular text
+       zero indent 168
+          non-zero indent 252
+       back to zero indent 168
+       back to regular text 168
+
+
+
+OpenBSD                          June 13, 2017                 RS-AN-MARGIN(1)
Index: Makefile
===================================================================
RCS file: /home/cvs/mdocml/mdocml/regress/man/RS/Makefile,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lregress/man/RS/Makefile -Lregress/man/RS/Makefile -u -p -r1.1 -r1.2
--- regress/man/RS/Makefile
+++ regress/man/RS/Makefile
@@ -1,6 +1,6 @@
 # $OpenBSD: Makefile,v 1.11 2015/04/06 13:34:54 schwarze Exp $
 
-REGRESS_TARGETS	 = breaking broken empty literal lonelyRE
+REGRESS_TARGETS	 = an-margin breaking broken empty literal lonelyRE
 REGRESS_TARGETS	+= nested noRE nowidth REarg width
 LINT_TARGETS	 = empty lonelyRE noRE REarg
 
--
 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-13 19:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-13 19:34 mdocml: Partial support for the \n[an-margin] number register 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).