source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: kristaps@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: texi2mdoc: Be more careful when we emit newlines before tables.
Date: Sat, 7 Mar 2015 06:50:02 -0500 (EST)	[thread overview]
Message-ID: <10538101184207899635.enqueue@fantadrom.bsd.lv> (raw)

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

                 reply	other threads:[~2015-03-07 11:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=10538101184207899635.enqueue@fantadrom.bsd.lv \
    --to=kristaps@mdocml.bsd.lv \
    --cc=source@mdocml.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).