source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* texi2mdoc: Be more careful when we emit newlines before tables.
@ 2015-03-07 11:50 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2015-03-07 11:50 UTC (permalink / raw)
  To: source

Log Message:
-----------
Be more careful when we emit newlines before tables.
Also adds an ifdef'd initial @menu implementation, which still requires
some careful thought.

Modified Files:
--------------
    texi2mdoc:
        main.c

Revision Data
-------------
Index: main.c
===================================================================
RCS file: /home/cvs/mdocml/texi2mdoc/main.c,v
retrieving revision 1.63
retrieving revision 1.64
diff -Lmain.c -Lmain.c -u -p -r1.63 -r1.64
--- main.c
+++ main.c
@@ -61,6 +61,9 @@ static	void doitemize(struct texi *, enu
 static	void dolink(struct texi *, enum texicmd, size_t *);
 static	void domacro(struct texi *, enum texicmd, size_t *);
 static	void domath(struct texi *, enum texicmd, size_t *);
+#if 0
+static	void domenu(struct texi *, enum texicmd, size_t *);
+#endif
 static	void domultitable(struct texi *, enum texicmd, size_t *);
 static	void doquotation(struct texi *, enum texicmd, size_t *);
 static	void dotable(struct texi *, enum texicmd, size_t *);
@@ -1451,6 +1454,117 @@ doquotation(struct texi *p, enum texicmd
 	teximacro(p, "Qc");
 }
 
+#if 0
+static void
+domenu(struct texi *p, enum texicmd cmd, size_t *pos)
+{
+	size_t	 start;
+
+	if (NULL != p->chapters) {
+		doignblock(p, cmd, pos);
+		return;
+	}
+
+	advanceeoln(p, pos, 1);
+
+	teximacro(p, "Bl -tag -width Ds");
+	while (*pos < BUFSZ(p)) {
+		/* Read to next menu item. */
+		while (*pos < BUFSZ(p) && ismspace(BUF(p)[*pos]))
+			advance(p, pos);
+		if ('*' != BUF(p)[*pos])
+			break;
+
+		assert('*' == BUF(p)[*pos]);
+		advance(p, pos);
+		while (*pos < BUFSZ(p) && ismspace(BUF(p)[*pos]))
+			advance(p, pos);
+		start = *pos;
+		while (*pos < BUFSZ(p) && ':' != BUF(p)[*pos])
+			advance(p, pos);
+		if (*pos == BUFSZ(p) || *pos == start) {
+			texiwarn(p, "empty menu name");
+			break;
+		}
+		teximacroopen(p, "It");
+		teximacroopen(p, "Sx");
+		for ( ; start < *pos; start++)
+			texiputchar(p, BUF(p)[start]);
+		teximacroclose(p);
+		teximacroclose(p);
+
+		advance(p, pos);
+		if (*pos == BUFSZ(p)) {
+			texiwarn(p, "bad menu syntax");
+			break;
+		} else if (':' != BUF(p)[*pos]) {
+			while (*pos < BUFSZ(p) && isws(BUF(p)[*pos]))
+				advance(p, pos);
+			start = *pos;
+			while (*pos < BUFSZ(p)) {
+				switch (BUF(p)[*pos]) {
+				case ('\t'):
+				case ('\n'):
+				case (','):
+					break;
+				case ('.'):
+					if (*pos + 1 == BUFSZ(p)) {
+						advance(p, pos);
+						continue;
+					} 
+					if (' ' == BUF(p)[*pos + 1]) {
+						advance(p, pos);
+						break;
+					}
+					/* FALLTHROUGH */
+				default:
+					advance(p, pos);
+					continue;
+				}
+				advance(p, pos);
+				break;
+			}
+		} else
+			advance(p, pos);
+
+		while (*pos < BUFSZ(p) && isws(BUF(p)[*pos]))
+			advance(p, pos);
+
+		if (*pos == BUFSZ(p)) {
+			texiwarn(p, "bad menu syntax");
+			break;
+		}
+
+		while (*pos < BUFSZ(p)) {
+			if ('*' == BUF(p)[*pos])
+				break;
+			if ('\n' != BUF(p)[*pos]) {
+				texiputchar(p, BUF(p)[*pos]);
+				advance(p, pos);
+				continue;
+			}
+			advance(p, pos);
+			while (*pos == BUFSZ(p)) {
+				texiwarn(p, "bad menu syntax");
+				break;
+			} 
+			if ('\n' == BUF(p)[*pos]) {
+				advance(p, pos);
+				break;
+			} else if ('*' == BUF(p)[*pos]) {
+				continue;
+			} else if ('@' == BUF(p)[*pos]) 
+				break;
+			texiputchar(p, ' ');
+		}
+	}
+
+	teximacro(p, "El");
+
+	doignblock(p, cmd, pos);
+}
+#endif
+
 static void
 domath(struct texi *p, enum texicmd cmd, size_t *pos)
 {
@@ -1705,7 +1819,8 @@ doitem(struct texi *p, enum texicmd cmd,
 
 	/* Multitable is using raw tbl(7). */
 	if (TEXILIST_TABLE == p->list) {
-		texiputchar(p, '\n');
+		if (p->outcol > 0)
+			texiputchar(p, '\n');
 		return;
 	} 
 	
@@ -1740,7 +1855,7 @@ dotab(struct texi *p, enum texicmd cmd, 
 {
 
 	/* This command is only useful in @multitable. */
-	if (TEXILIST_TABLE == p->list)
+	if (TEXILIST_TABLE == p->list && p->outcol)
 		texiputchar(p, '\t');
 }
 
@@ -1752,6 +1867,7 @@ domultitable(struct texi *p, enum texicm
 	enum texicmd	type;
 	size_t		i, end, columns;
 
+	texivspace(p);
 	p->list = TEXILIST_TABLE;
 	/* 
 	 * TS/TE blocks aren't "in mdoc(7)", so we can disregard the
@@ -1805,7 +1921,9 @@ domultitable(struct texi *p, enum texicm
 			texiputchar(p, ' ');
 		texiputchar(p, 'l');
 	}
-	texiputchars(p, ".\n");
+
+	texiputchar(p, '.');
+	texiputchar(p, '\n');
 	p->outmacro++;
 	parseto(p, pos, texitoks[cmd].tok);
 	p->outmacro--;
--
 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-03-07 11:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-07 11:50 texi2mdoc: Be more careful when we emit newlines before tables 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).