source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Rudimentary implementation of the roff(7) \o escape sequence
@ 2015-01-21 20:33 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2015-01-21 20:33 UTC (permalink / raw)
  To: source

Log Message:
-----------
Rudimentary implementation of the roff(7) \o escape sequence (overstrike).
This is of some relevance because the pod2man(1) preamble abuses it
for the icelandic letter Thorn, instead of simply using \(TP and \(Tp.
Missing feature found by sthen@ in DateTime::Locale::is_IS(3p).

Modified Files:
--------------
    mdocml:
        html.c
        mandoc.c
        mandoc.h
        mandoc_escape.3
        roff.7
        term.c

Revision Data
-------------
Index: roff.7
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff.7,v
retrieving revision 1.64
retrieving revision 1.65
diff -Lroff.7 -Lroff.7 -u -p -r1.64 -r1.65
--- roff.7
+++ roff.7
@@ -1948,10 +1948,11 @@ For short names, there are variants
 and
 .No \en( Ns Ar cc .
 .Ss \eo\(aq Ns Ar string Ns \(aq
-Overstrike
-.Ar string ;
-ignored by
-.Xr mandoc 1 .
+Overstrike, that is, write all the characters contained in the
+.Ar string
+to the same output position.
+In terminal and HTML output modes,
+only the last one of the characters is visible.
 .Ss \eR\(aq Ns Ar name Oo +|- Oc Ns Ar number Ns \(aq
 Set number register; ignored by
 .Xr mandoc 1 .
Index: html.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/html.c,v
retrieving revision 1.184
retrieving revision 1.185
diff -Lhtml.c -Lhtml.c -u -p -r1.184 -r1.185
--- html.c
+++ html.c
@@ -1,7 +1,7 @@
 /*	$Id$ */
 /*
  * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2011-2015 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
@@ -307,6 +307,8 @@ html_strlen(const char *cp)
 		case ESCAPE_NUMBERED:
 			/* FALLTHROUGH */
 		case ESCAPE_SPECIAL:
+			/* FALLTHROUGH */
+		case ESCAPE_OVERSTRIKE:
 			if (skip)
 				skip = 0;
 			else
@@ -433,6 +435,11 @@ print_encode(struct html *h, const char 
 			if ('\0' == *p)
 				nospace = 1;
 			continue;
+		case ESCAPE_OVERSTRIKE:
+			if (len == 0)
+				continue;
+			c = seq[len - 1];
+			break;
 		default:
 			continue;
 		}
Index: mandoc.h
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mandoc.h,v
retrieving revision 1.183
retrieving revision 1.184
diff -Lmandoc.h -Lmandoc.h -u -p -r1.183 -r1.184
--- mandoc.h
+++ mandoc.h
@@ -399,7 +399,8 @@ enum	mandoc_esc {
 	ESCAPE_NUMBERED, /* a numbered glyph */
 	ESCAPE_UNICODE, /* a unicode codepoint */
 	ESCAPE_NOSPACE, /* suppress space if the last on a line */
-	ESCAPE_SKIPCHAR /* skip the next character */
+	ESCAPE_SKIPCHAR, /* skip the next character */
+	ESCAPE_OVERSTRIKE /* overstrike all chars in the argument */
 };
 
 typedef	void	(*mandocmsg)(enum mandocerr, enum mandoclevel,
Index: mandoc_escape.3
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mandoc_escape.3,v
retrieving revision 1.2
retrieving revision 1.3
diff -Lmandoc_escape.3 -Lmandoc_escape.3 -u -p -r1.2 -r1.3
--- mandoc_escape.3
+++ mandoc_escape.3
@@ -20,8 +20,6 @@
 .Sh NAME
 .Nm mandoc_escape
 .Nd parse roff escape sequences
-.Sh LIBRARY
-.Lb libmandoc
 .Sh SYNOPSIS
 .In sys/types.h
 .In mandoc.h
@@ -119,8 +117,8 @@ in turn contain other escape sequences,
 for error detection internally by the
 .Xr roff 7
 parser part of the
-.Lb libmandoc ,
-see the file
+.Xr mandoc 3
+library, see the file
 .Pa roff.c ,
 .It
 above all externally by the
@@ -256,6 +254,10 @@ Such ASCII character escape sequences ca
 described in the
 .Xr mchars_alloc 3
 manual.
+.It Dv ESCAPE_OVERSTRIKE
+The escape sequence
+.Ic \eo
+followed by an argument delimited by an arbitrary character.
 .It Dv ESCAPE_IGNORE
 .Bl -bullet -width 2n
 .It
@@ -288,7 +290,6 @@ The escape sequences
 .Ic \eA ,
 .Ic \eb ,
 .Ic \eD ,
-.Ic \eo ,
 .Ic \eR ,
 .Ic \eX ,
 and
Index: term.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/term.c,v
retrieving revision 1.242
retrieving revision 1.243
diff -Lterm.c -Lterm.c -u -p -r1.242 -r1.243
--- term.c
+++ term.c
@@ -1,7 +1,7 @@
 /*	$Id$ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010-2015 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
@@ -495,6 +495,17 @@ term_word(struct termp *p, const char *w
 		case ESCAPE_SKIPCHAR:
 			p->flags |= TERMP_SKIPCHAR;
 			continue;
+		case ESCAPE_OVERSTRIKE:
+			cp = seq + sz;
+			while (seq < cp) {
+				if (*seq == '\\') {
+					mandoc_escape(&seq, NULL, NULL);
+					continue;
+				}
+				encode1(p, *seq++);
+				if (seq < cp)
+					encode(p, "\b", 1);
+			}
 		default:
 			continue;
 		}
@@ -715,6 +726,20 @@ term_strlen(const struct termp *p, const
 				continue;
 			case ESCAPE_SKIPCHAR:
 				skip = 1;
+				continue;
+			case ESCAPE_OVERSTRIKE:
+				rsz = 0;
+				rhs = seq + ssz;
+				while (seq < rhs) {
+					if (*seq == '\\') {
+						mandoc_escape(&seq, NULL, NULL);
+						continue;
+					}
+					i = (*p->width)(p, *seq++);
+					if (rsz < i)
+						rsz = i;
+				}
+				sz += rsz;
 				continue;
 			default:
 				continue;
Index: mandoc.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mandoc.c,v
retrieving revision 1.90
retrieving revision 1.91
diff -Lmandoc.c -Lmandoc.c -u -p -r1.90 -r1.91
--- mandoc.c
+++ mandoc.c
@@ -156,16 +156,18 @@ mandoc_escape(const char **end, const ch
 		/* FALLTHROUGH */
 	case 'D':
 		/* FALLTHROUGH */
-	case 'o':
-		/* FALLTHROUGH */
 	case 'R':
 		/* FALLTHROUGH */
 	case 'X':
 		/* FALLTHROUGH */
 	case 'Z':
-		if ('\0' == **start)
-			return(ESCAPE_ERROR);
 		gly = ESCAPE_IGNORE;
+		/* FALLTHROUGH */
+	case 'o':
+		if (**start == '\0')
+			return(ESCAPE_ERROR);
+		if (gly == ESCAPE_ERROR)
+			gly = ESCAPE_OVERSTRIKE;
 		term = **start;
 		*start = ++*end;
 		break;
--
 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:[~2015-01-21 20:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-21 20:33 mdocml: Rudimentary implementation of the roff(7) \o escape sequence 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).