source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: kristaps@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: texi2mdoc: When using @def style commands, indent the "explanation"
Date: Sat, 28 Feb 2015 08:17:14 -0500 (EST)	[thread overview]
Message-ID: <14943697991492359906.enqueue@fantadrom.bsd.lv> (raw)

Log Message:
-----------
When using @def style commands, indent the "explanation" block as it's
supposed to be, where subsequent @defx commands aren't indented.

Modified Files:
--------------
    texi2mdoc:
        extern.h
        main.c
        util.c

Revision Data
-------------
Index: main.c
===================================================================
RCS file: /home/cvs/mdocml/texi2mdoc/main.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -Lmain.c -Lmain.c -u -p -r1.53 -r1.54
--- main.c
+++ main.c
@@ -498,9 +498,45 @@ dodefn(struct texi *p, enum texicmd cmd,
 		abort();
 	}
 
-	texivspace(p);
-	if (NULL != blk)
-		parseto(p, pos, blk);
+	if (NULL == blk)
+		return;
+
+	/*
+	 * All "block" definitions have their block bodies indented
+	 * unless they have the "x" form of the command following.
+	 * E.g.,
+	 *   @deffn some function
+	 *   @deffnx another
+	 *   An explanation.
+	 *   @end deffn
+	 * With this loop, we delay opening the indented block until we
+	 * skipped past conformant macros.
+	 */
+	for (;;) {
+		switch (peekcmd(p, *pos)) {
+		case (TEXICMD_DEFFNX):
+		case (TEXICMD_DEFMACX):
+		case (TEXICMD_DEFTPX):
+		case (TEXICMD_DEFTYPEFNX):
+		case (TEXICMD_DEFTYPEFUNX):
+		case (TEXICMD_DEFTYPEMETHODX):
+		case (TEXICMD_DEFTYPEVARX):
+		case (TEXICMD_DEFTYPEVRX):
+		case (TEXICMD_DEFUNX):
+		case (TEXICMD_DEFVARX):
+		case (TEXICMD_DEFVRX):
+			texivspace(p);
+			parseeoln(p, pos);
+			continue;
+		default:
+			break;
+		}
+		break;
+	}
+	teximacro(p, "Bd -filled -offset indent");
+	p->seenvs = 1;
+	parseto(p, pos, blk);
+	teximacro(p, "Ed");
 }
 
 static void
Index: extern.h
===================================================================
RCS file: /home/cvs/mdocml/texi2mdoc/extern.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -Lextern.h -Lextern.h -u -p -r1.19 -r1.20
--- extern.h
+++ extern.h
@@ -427,7 +427,9 @@ void	parseto(struct texi *, size_t *, co
 void	texiabort(struct texi *, const char *)
 		__attribute__((noreturn));
 enum texicmd
-	texicmd(struct texi *, size_t, size_t *, struct teximacro **);
+	texicmd(const struct texi *, size_t, size_t *, struct teximacro **);
+enum texicmd
+	peekcmd(const struct texi *, size_t);
 void	texierr(struct texi *, const char *, ...)
 		__attribute__((format(printf, 2, 3)))
 		__attribute__((noreturn));
Index: util.c
===================================================================
RCS file: /home/cvs/mdocml/texi2mdoc/util.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -Lutil.c -Lutil.c -u -p -r1.18 -r1.19
--- util.c
+++ util.c
@@ -591,7 +591,7 @@ parseword(struct texi *p, size_t *pos, c
  * index after the command name.
  */
 enum texicmd
-texicmd(struct texi *p, size_t pos, size_t *end, struct teximacro **macro)
+texicmd(const struct texi *p, size_t pos, size_t *end, struct teximacro **macro)
 {
 	size_t	 i, len, toksz;
 
@@ -824,6 +824,23 @@ parseeoln(struct texi *p, size_t *pos)
 
 	if (*pos < BUFSZ(p) && '\n' == BUF(p)[*pos])
 		advance(p, pos);
+}
+
+/*
+ * Peek to see if there's a command after subsequent whitespace.
+ * If so, return the macro identifier.
+ * This DOES NOT work with user-defined macros.
+ */
+enum texicmd
+peekcmd(const struct texi *p, size_t pos)
+{
+	size_t		end;
+
+	while (pos < BUFSZ(p) && ismspace(BUF(p)[pos]))
+		pos++;
+	if (pos == BUFSZ(p) || '@' != BUF(p)[pos])
+		return(TEXICMD__MAX);
+	return(texicmd(p, pos, &end, NULL));
 }
 
 /*
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2015-02-28 13:17 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=14943697991492359906.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).