source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: In quoted macro arguments, double quotes can be quoted by
@ 2013-12-15 23:56 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2013-12-15 23:56 UTC (permalink / raw)
  To: source

Log Message:
-----------
In quoted macro arguments, double quotes can be quoted by doubling them.
For a long time, we handle this in roff(7) and man(7) macros.
Now add correct handling for the mdoc(7) case, too.

Closely based on a patch by Tsugutomo dot ENAMI at jp dot sony dot com,
see http://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=48438 
received via Thomas Klausner (wiz@), slightly tweaked by me.

Modified Files:
--------------
    mdocml:
        mdoc_argv.c
        TODO

Revision Data
-------------
Index: TODO
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/TODO,v
retrieving revision 1.160
retrieving revision 1.161
diff -LTODO -LTODO -u -p -r1.160 -r1.161
--- TODO
+++ TODO
@@ -203,11 +203,6 @@ None known.
 - a column list with blank `Ta' cells triggers a spurrious
   start-with-whitespace printing of a newline
 
-- double quotes inside double quotes are escaped by doubling them
-  implement this in mdoc(7), too
-  so far, we only have it in roff(7) and man(7)
-  reminded by millert@  Thu, 09 Dec 2010 17:29:52 -0500
-
 - In .Bl -column,
   .It Em Authentication<tab>Key Length
   ought to render "Key Length" with emphasis, too,
Index: mdoc_argv.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_argv.c,v
retrieving revision 1.86
retrieving revision 1.87
diff -Lmdoc_argv.c -Lmdoc_argv.c -u -p -r1.86 -r1.87
--- mdoc_argv.c
+++ mdoc_argv.c
@@ -447,6 +447,7 @@ args(struct mdoc *mdoc, int line, int *p
 		char *buf, enum argsflag fl, char **v)
 {
 	char		*p, *pp;
+	int		 pairs;
 	enum margserr	 rc;
 
 	if ('\0' == buf[*pos]) {
@@ -540,6 +541,8 @@ args(struct mdoc *mdoc, int line, int *p
 	/* 
 	 * Process a quoted literal.  A quote begins with a double-quote
 	 * and ends with a double-quote NOT preceded by a double-quote.
+	 * Null-terminate the literal in place.
+	 * Collapse pairs of quotes inside quoted literals.
 	 * Whitespace is NOT involved in literal termination.
 	 */
 
@@ -550,13 +553,22 @@ args(struct mdoc *mdoc, int line, int *p
 		if (MDOC_PPHRASE & mdoc->flags)
 			mdoc->flags |= MDOC_PHRASELIT;
 
+		pairs = 0;
 		for ( ; buf[*pos]; (*pos)++) {
+			/* Move following text left after quoted quotes. */
+			if (pairs)
+				buf[*pos - pairs] = buf[*pos];
 			if ('\"' != buf[*pos])
 				continue;
+			/* Unquoted quotes end quoted args. */
 			if ('\"' != buf[*pos + 1])
 				break;
+			/* Quoted quotes collapse. */
+			pairs++;
 			(*pos)++;
 		}
+		if (pairs)
+			buf[*pos - pairs] = '\0';
 
 		if ('\0' == buf[*pos]) {
 			if (MDOC_PPHRASE & mdoc->flags)
--
 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:[~2013-12-15 23:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-15 23:56 mdocml: In quoted macro arguments, double quotes can be quoted by 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).