source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* texi2mdoc: Clarify the role of texiputchar() and texiputchars() and make
@ 2015-02-24 14:36 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2015-02-24 14:36 UTC (permalink / raw)
  To: source

Log Message:
-----------
Clarify the role of texiputchar() and texiputchars() and make sure both are
being correctly invoked.
While doing so, prune away the different places where mdoc(7) is being
escaped.

Modified Files:
--------------
    texi2mdoc:
        Makefile
        main.c
        util.c
        version_0_1_2.xml

Revision Data
-------------
Index: util.c
===================================================================
RCS file: /home/cvs/mdocml/texi2mdoc/util.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -Lutil.c -Lutil.c -u -p -r1.12 -r1.13
--- util.c
+++ util.c
@@ -160,9 +160,7 @@ texierr(struct texi *p, const char *fmt,
 
 /*
  * Put a single data character to the output if we're not ignoring.
- * Makes sure we don't spurriously start a macro.
- * Adjusts our output status.
- * This shouldn't be called for macros: just for ordinary text.
+ * Escape starting a line with a control character and slashes.
  */
 void
 texiputchar(struct texi *p, char c)
@@ -170,13 +168,14 @@ texiputchar(struct texi *p, char c)
 
 	if (p->ign)
 		return;
-
 	if ('.' == c && 0 == p->outcol)
 		fputs("\\&", stdout);
 	if ('\'' == c && 0 == p->outcol)
 		fputs("\\&", stdout);
 
 	putchar(c);
+	if ('\\' == c)
+		putchar('e');
 	p->seenvs = 0;
 	if ('\n' == c) {
 		p->outcol = 0;
@@ -186,15 +185,22 @@ texiputchar(struct texi *p, char c)
 }
 
 /*
- * Put multiple characters (see texiputchar()).
- * This shouldn't be called for macros: just for ordinary text.
+ * Put an opaque series of characters.
+ * Characters starting a line with a control character are escaped, but
+ * that's it, so don't use this for non-controlled sequences of text.
  */
 void
 texiputchars(struct texi *p, const char *s)
 {
 
-	while ('\0' != *s)
-		texiputchar(p, *s++);
+	if (p->ign)
+		return;
+	if ('.' == *s && 0 == p->outcol)
+		fputs("\\&", stdout);
+	if ('\'' == *s && 0 == p->outcol)
+		fputs("\\&", stdout);
+	p->outcol += fputs(s, stdout);
+	p->seenvs = 0;
 }
 
 /*
@@ -367,9 +373,6 @@ advancenext(struct texi *p, const char *
 	
 	if (p->literal) {
 		while (*pos < sz && ismspace(buf[*pos])) {
-			if (*pos && '\n' == buf[*pos] && 
-				'\\' == buf[*pos - 1])
-				texiputchar(p, 'e');
 			texiputchar(p, buf[*pos]);
 			advance(p, buf, pos);
 		}
@@ -551,9 +554,6 @@ texiword(struct texi *p, const char *buf
 			 '\'' == buf[*pos + 1]) {
 			texiputchars(p, "\\(rq");
 			advance(p, buf, pos);
-		} else if ('\\' == buf[*pos]) {
-			texiputchar(p, buf[*pos]);
-			texiputchar(p, 'e');
 		} else
 			texiputchar(p, buf[*pos]);
 		advance(p, buf, pos);
@@ -1036,20 +1036,10 @@ parsefile(struct texi *p, const char *fn
 
 	p->filepos++;
 	if ( ! parse) {
-		/*
-		 * We're printing verbatim output.
-		 * Make sure it doesn't get interpreted as mdoc by
-		 * escaping escapes and making sure leading dots don't
-		 * trigger mdoc(7) expansion.
-		 */
-		for (i = 0; i < f->mapsz; i++) {
-			if (i > 0 && '.' == f->map[i])
-				if ('\n' == f->map[i - 1])
-					fputs("\\&", stdout);
-			putchar(f->map[i]);
-			if ('\\' == f->map[i])
-				putchar('e');
-		}
+		for (i = 0; i < f->mapsz; i++)
+			texiputchar(p, f->map[i]);
+		if (p->outcol)
+			texiputchar(p, '\n');
 	} else
 		parseeof(p, f->map, f->mapsz);
 	texifilepop(p);
Index: Makefile
===================================================================
RCS file: /home/cvs/mdocml/texi2mdoc/Makefile,v
retrieving revision 1.7
retrieving revision 1.8
diff -LMakefile -LMakefile -u -p -r1.7 -r1.8
--- Makefile
+++ Makefile
@@ -1,7 +1,8 @@
 CFLAGS += -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings 
 OBJS = main.o util.o
 SRCS = main.c util.c
-VERSIONS = version_0_1_1.xml
+VERSIONS = version_0_1_1.xml \
+	   version_0_1_2.xml
 VERSION = 0.1.1
 PREFIX = /usr/local
 
Index: version_0_1_2.xml
===================================================================
RCS file: /home/cvs/mdocml/texi2mdoc/version_0_1_2.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lversion_0_1_2.xml -Lversion_0_1_2.xml -u -p -r1.1 -r1.2
--- version_0_1_2.xml
+++ version_0_1_2.xml
@@ -8,5 +8,6 @@
 		Ported for running on Linux.
 		Added a few macros for viewing <a href="https://gmplib.org/">GMP</a> manuals.
 		Also allow reading from standard input (instead of always from a file).
+		Consolidate mdoc(7)-escaping of opaque output.
 	</aside>
 </article>
Index: main.c
===================================================================
RCS file: /home/cvs/mdocml/texi2mdoc/main.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -Lmain.c -Lmain.c -u -p -r1.40 -r1.41
--- main.c
+++ main.c
@@ -17,12 +17,8 @@
 #if defined(__linux__) || defined(__MINT__)
 # define _GNU_SOURCE /* memmem */
 #endif
-#include <sys/mman.h>
-#include <sys/stat.h>
-
 #include <assert.h>
 #include <ctype.h>
-#include <fcntl.h>
 #include <getopt.h>
 #include <libgen.h>
 #include <limits.h>
@@ -31,7 +27,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
-#include <unistd.h>
 
 #include "extern.h"
 
@@ -674,16 +669,7 @@ doverbatim(struct texi *p, enum texicmd 
 	teximacro(p, "Bd -literal -offset indent");
 	assert(endpos <= sz);
 	while (*pos < endpos) {
-		if (buf[*pos] == '\n')
-			p->outcol = 0;
-		else
-			p->outcol++;
-		if (*pos > 0 && '.' == buf[*pos])
-			if ('\n' == buf[*pos - 1])
-				fputs("\\&", stdout);
-		putchar(buf[*pos]);
-		if ('\\' == buf[*pos])
-			putchar('e');
+		texiputchar(p, buf[*pos]);
 		advance(p, buf, pos);
 	}
 	teximacro(p, "Ed");
@@ -1400,11 +1386,15 @@ dotop(struct texi *p, enum texicmd cmd, 
 	teximacro(p, "Os");
 	teximacro(p, "Sh NAME");
 	teximacroopen(p, "Nm");
-	texiputchars(p, p->title);
+	for (cp = p->title; '\0' != *cp; cp++)
+		texiputchar(p, *cp);
 	teximacroclose(p);
 	teximacroopen(p, "Nd");
-	texiputchars(p, NULL != p->subtitle ?
-		p->subtitle : "Unknown description");
+	if (NULL != p->subtitle)
+		for (cp = p->subtitle; '\0' != *cp; cp++)
+			texiputchar(p, *cp);
+	else
+		texiputchars(p, "Unknown description");
 	teximacroclose(p);
 	p->seenvs = 1;
 	dosection(p, cmd, buf, sz, pos);
--
 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-02-24 14:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-24 14:36 texi2mdoc: Clarify the role of texiputchar() and texiputchars() and make kristaps

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).