source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mandoc: Implement the \*(.T predefined string (interpolate device name)
@ 2018-08-16 13:54 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2018-08-16 13:54 UTC (permalink / raw)
  To: source

Log Message:
-----------
Implement the \*(.T predefined string (interpolate device name) 
by allowing the preprocessor to pass it through to the formatters.
Used for example by the groff_char(7) manual page.

Modified Files:
--------------
    mandoc:
        TODO
        html.c
        mandoc.c
        mandoc.h
        mdoc_markdown.c
        roff.c
        term.c
    mandoc/regress/roff/string:
        Makefile

Added Files:
-----------
    mandoc/regress/roff/string:
        dotT.in
        dotT.out_ascii
        dotT.out_html
        dotT.out_markdown
        dotT.out_utf8

Revision Data
-------------
Index: roff.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/roff.c,v
retrieving revision 1.330
retrieving revision 1.331
diff -Lroff.c -Lroff.c -u -p -r1.330 -r1.331
--- roff.c
+++ roff.c
@@ -1367,6 +1367,19 @@ roff_res(struct roff *r, struct buf *buf
 			if (arg_complete) {
 				deftype = ROFFDEF_USER | ROFFDEF_PRE;
 				res = roff_getstrn(r, stnam, naml, &deftype);
+
+				/*
+				 * If not overriden, let \*(.T
+				 * through to the formatters.
+				 */
+
+				if (res == NULL && naml == 2 &&
+				    stnam[0] == '.' && stnam[1] == 'T') {
+					roff_setstrn(&r->strtab,
+					    ".T", 2, NULL, 0, 0);
+					stesc--;
+					continue;
+				}
 			}
 			break;
 		case 'B':
Index: term.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/term.c,v
retrieving revision 1.274
retrieving revision 1.275
diff -Lterm.c -Lterm.c -u -p -r1.274 -r1.275
--- term.c
+++ term.c
@@ -1,7 +1,7 @@
 /*	$Id$ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010-2018 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
@@ -525,6 +525,16 @@ term_word(struct termp *p, const char *w
 			else if (*word == '\0')
 				p->flags |= (TERMP_NOSPACE | TERMP_NONEWLINE);
 			continue;
+		case ESCAPE_DEVICE:
+			if (p->type == TERMTYPE_PDF)
+				encode(p, "pdf", 3);
+			else if (p->type == TERMTYPE_PS)
+				encode(p, "ps", 2);
+			else if (p->enc == TERMENC_ASCII)
+				encode(p, "ascii", 5);
+			else
+				encode(p, "utf8", 4);
+			continue;
 		case ESCAPE_HORIZ:
 			if (*seq == '|') {
 				seq++;
@@ -860,6 +870,21 @@ term_strlen(const struct termp *p, const
 						sz += cond_width(p, uc, &skip);
 				}
 				continue;
+			case ESCAPE_DEVICE:
+				if (p->type == TERMTYPE_PDF) {
+					rhs = "pdf";
+					rsz = 3;
+				} else if (p->type == TERMTYPE_PS) {
+					rhs = "ps";
+					rsz = 2;
+				} else if (p->enc == TERMENC_ASCII) {
+					rhs = "ascii";
+					rsz = 5;
+				} else {
+					rhs = "utf8";
+					rsz = 4;
+				}
+				break;
 			case ESCAPE_SKIPCHAR:
 				skip = 1;
 				continue;
Index: TODO
===================================================================
RCS file: /home/cvs/mandoc/mandoc/TODO,v
retrieving revision 1.263
retrieving revision 1.264
diff -LTODO -LTODO -u -p -r1.263 -r1.264
--- TODO
+++ TODO
@@ -38,13 +38,6 @@ are mere guesses, and some may be wrong.
 
 --- missing roff features ----------------------------------------------
 
-- \*(.T prints the device being used,
-  see groff_char(7) for an example
-  This is slightly hard because -Tlocale only decides to use ascii or
-  utf8 when initializing the formatter, so the information is not
-  yet available to the preprocessor at the parsing stage.
-  loc **  exist **  algo *  size *  imp *
-
 - .ad (adjust margins)
   .ad l -- adjust left margin only (flush left)
   .ad r -- adjust right margin only (flush right)
Index: mandoc.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mandoc.h,v
retrieving revision 1.248
retrieving revision 1.249
diff -Lmandoc.h -Lmandoc.h -u -p -r1.248 -r1.249
--- mandoc.h
+++ mandoc.h
@@ -431,6 +431,7 @@ enum	mandoc_esc {
 	ESCAPE_FONTPREV, /* previous font mode */
 	ESCAPE_NUMBERED, /* a numbered glyph */
 	ESCAPE_UNICODE, /* a unicode codepoint */
+	ESCAPE_DEVICE, /* print the output device name */
 	ESCAPE_BREAK, /* break the output line */
 	ESCAPE_NOSPACE, /* suppress space if the last on a line */
 	ESCAPE_HORIZ, /* horizontal movement */
Index: html.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/html.c,v
retrieving revision 1.238
retrieving revision 1.239
diff -Lhtml.c -Lhtml.c -u -p -r1.238 -r1.239
--- html.c
+++ html.c
@@ -433,6 +433,9 @@ print_encode(struct html *h, const char 
 			if (c <= 0)
 				continue;
 			break;
+		case ESCAPE_DEVICE:
+			print_word(h, "html");
+			continue;
 		case ESCAPE_BREAK:
 			breakline = 1;
 			continue;
Index: mdoc_markdown.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc_markdown.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -Lmdoc_markdown.c -Lmdoc_markdown.c -u -p -r1.24 -r1.25
--- mdoc_markdown.c
+++ mdoc_markdown.c
@@ -1,6 +1,6 @@
 /*	$Id$ */
 /*
- * Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2017, 2018 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
@@ -580,6 +580,9 @@ md_word(const char *s)
 			case ESCAPE_SPECIAL:
 				uc = mchars_spec2cp(seq, sz);
 				break;
+			case ESCAPE_DEVICE:
+				md_rawword("markdown");
+				continue;
 			case ESCAPE_FONTBOLD:
 				nextfont = "**";
 				break;
Index: mandoc.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mandoc.c,v
retrieving revision 1.105
retrieving revision 1.106
diff -Lmandoc.c -Lmandoc.c -u -p -r1.105 -r1.106
--- mandoc.c
+++ mandoc.c
@@ -139,6 +139,13 @@ mandoc_escape(const char **end, const ch
 			break;
 		}
 		break;
+	case '*':
+		if (strncmp(*start, "(.T", 3) != 0)
+			abort();
+		gly = ESCAPE_DEVICE;
+		*start = ++*end;
+		*sz = 2;
+		break;
 
 	/*
 	 * These escapes are of the form \X'Y', where 'X' is the trigger
--- /dev/null
+++ regress/roff/string/dotT.out_markdown
@@ -0,0 +1,21 @@
+STRING-DOTT(1) - General Commands Manual
+
+# NAME
+
+**string-dotT** - interpolating the device name
+
+# DESCRIPTION
+
+initial text
+
+BEGINTEST
+
+We are using the  markdown device.
+
+The device name can be overridden.
+
+ENDTEST
+
+final text
+
+OpenBSD - August 16, 2018
--- /dev/null
+++ regress/roff/string/dotT.out_ascii
@@ -0,0 +1,19 @@
+STRING-DOTT(1)              General Commands Manual             STRING-DOTT(1)
+
+N\bNA\bAM\bME\bE
+     s\bst\btr\bri\bin\bng\bg-\b-d\bdo\bot\btT\bT - interpolating the device name
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+     initial text
+
+     BEGINTEST
+
+     We are using the ascii device.
+
+     The device name can be overridden.
+
+     ENDTEST
+
+     final text
+
+OpenBSD                         August 16, 2018                        OpenBSD
--- /dev/null
+++ regress/roff/string/dotT.out_html
@@ -0,0 +1,7 @@
+BEGINTEST
+<div class="Pp"></div>
+We are using the html device.
+<div class="Pp"></div>
+The device name can be overridden.
+<div class="Pp"></div>
+ENDTEST
--- /dev/null
+++ regress/roff/string/dotT.out_utf8
@@ -0,0 +1,19 @@
+STRING-DOTT(1)              General Commands Manual             STRING-DOTT(1)
+
+N\bNA\bAM\bME\bE
+     s\bst\btr\bri\bin\bng\bg-\b-d\bdo\bot\btT\bT – interpolating the device name
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+     initial text
+
+     BEGINTEST
+
+     We are using the utf8 device.
+
+     The device name can be overridden.
+
+     ENDTEST
+
+     final text
+
+OpenBSD                         August 16, 2018                        OpenBSD
--- /dev/null
+++ regress/roff/string/dotT.in
@@ -0,0 +1,20 @@
+.\" $OpenBSD: dotT.in,v 1.1 2018/08/16 13:49:40 schwarze Exp $
+.Dd $Mdocdate: August 16 2018 $
+.Dt STRING-DOTT 1
+.Os
+.Sh NAME
+.Nm string-dotT
+.Nd interpolating the device name
+.Sh DESCRIPTION
+initial text
+.Pp
+BEGINTEST
+.Pp
+We are using the \*(.T device.
+.Pp
+.ds .T name
+The device \*(.T can be overridden.
+.Pp
+ENDTEST
+.Pp
+final text
Index: Makefile
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/roff/string/Makefile,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lregress/roff/string/Makefile -Lregress/roff/string/Makefile -u -p -r1.3 -r1.4
--- regress/roff/string/Makefile
+++ regress/roff/string/Makefile
@@ -1,7 +1,10 @@
 # $OpenBSD: Makefile,v 1.6 2014/07/06 19:08:57 schwarze Exp $
 
-REGRESS_TARGETS	 = escape infinite name std undef zerolength
+REGRESS_TARGETS	 = dotT escape infinite name std undef zerolength
 LINT_TARGETS	 = name std undef
+UTF8_TARGETS	 = dotT
+HTML_TARGETS	 = dotT
+SKIP_MARKDOWN	 = escape infinite name std undef zerolength
 
 # The infinite test fails badly with groff-1.20.1:
 # It fails to print the following text.
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv

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

only message in thread, other threads:[~2018-08-16 13:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-16 13:54 mandoc: Implement the \*(.T predefined string (interpolate device name) 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).