source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Add flags to insert a .sp or .br request before the next output,
Date: Sun, 8 Jul 2012 11:48:13 -0400 (EDT)	[thread overview]
Message-ID: <201207081548.q68FmDFw032421@krisdoz.my.domain> (raw)

Log Message:
-----------
Add flags to insert a .sp or .br request before the next output,
shortening some frequent idioms and preparing for better vertical
spacing in the SYNOPSIS; no functional change intended.
OpenBSD rev. 1.19

Modified Files:
--------------
    mdocml:
        mdoc_man.c

Revision Data
-------------
Index: mdoc_man.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_man.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -Lmdoc_man.c -Lmdoc_man.c -u -p -r1.20 -r1.21
--- mdoc_man.c
+++ mdoc_man.c
@@ -216,19 +216,26 @@ static	const struct manact manacts[MDOC_
 static	int		outflags;
 #define	MMAN_spc	(1 << 0)
 #define	MMAN_nl		(1 << 1)
-#define	MMAN_Sm		(1 << 2)
-#define	MMAN_Bk		(1 << 3)
+#define	MMAN_br		(1 << 2)
+#define	MMAN_sp		(1 << 3)
+#define	MMAN_Sm		(1 << 4)
+#define	MMAN_Bk		(1 << 5)
 
 static void
 print_word(const char *s)
 {
 
-	if (MMAN_nl & outflags) {
+	if ((MMAN_sp | MMAN_br | MMAN_nl) & outflags) {
 		/* 
 		 * If we need a newline, print it now and start afresh.
 		 */
-		putchar('\n');
-		outflags &= ~(MMAN_nl|MMAN_spc);
+		if (MMAN_sp & outflags)
+			printf("\n.sp\n");
+		else if (MMAN_br & outflags)
+			printf("\n.br\n");
+		else if (MMAN_nl & outflags)
+			putchar('\n');
+		outflags &= ~(MMAN_sp|MMAN_br|MMAN_nl|MMAN_spc);
 	} else if (MMAN_spc & outflags && '\0' != s[0])
 		/*
 		 * If we need a space, only print it before
@@ -490,10 +497,8 @@ static int
 pre_bd(DECL_ARGS)
 {
 
-	if (0 == n->norm->Bd.comp) {
-		outflags |= MMAN_nl;
-		print_word(".sp");
-	}
+	if (0 == n->norm->Bd.comp)
+		outflags |= MMAN_sp;
 	if (DISP_unfilled == n->norm->Bd.type ||
 	    DISP_literal  == n->norm->Bd.type) {
 		outflags |= MMAN_nl;
@@ -547,9 +552,7 @@ static int
 pre_br(DECL_ARGS)
 {
 
-	outflags |= MMAN_nl;
-	print_word(".br");
-	outflags |= MMAN_nl;
+	outflags |= MMAN_br;
 	return(0);
 }
 
@@ -627,11 +630,8 @@ pre_fn(DECL_ARGS)
 	if (NULL == n)
 		return(0);
 
-	if (MDOC_SYNPRETTY & n->flags) {
-		outflags |= MMAN_nl;
-		print_word(".br");
-		outflags |= MMAN_nl;
-	}
+	if (MDOC_SYNPRETTY & n->flags)
+		outflags |= MMAN_br;
 	print_word("\\fB");
 	outflags &= ~MMAN_spc;
 	print_node(m, n);
@@ -648,9 +648,7 @@ post_fn(DECL_ARGS)
 	print_word(")");
 	if (MDOC_SYNPRETTY & n->flags) {
 		print_word(";");
-		outflags |= MMAN_nl;
-		print_word(".br");
-		outflags |= MMAN_nl;
+		outflags |= MMAN_br;
 	}
 }
 
@@ -660,11 +658,8 @@ pre_fo(DECL_ARGS)
 
 	switch (n->type) {
 	case (MDOC_HEAD):
-		if (MDOC_SYNPRETTY & n->flags) {
-			outflags |= MMAN_nl;
-			print_word(".br");
-			outflags |= MMAN_nl;
-		}
+		if (MDOC_SYNPRETTY & n->flags)
+			outflags |= MMAN_br;
 		print_word("\\fB");
 		outflags &= ~MMAN_spc;
 		break;
@@ -701,9 +696,7 @@ pre_in(DECL_ARGS)
 {
 
 	if (MDOC_SYNPRETTY & n->flags) {
-		outflags |= MMAN_nl;
-		print_word(".br");
-		outflags |= MMAN_nl;
+		outflags |= MMAN_br;
 		print_word("\\fB#include <");
 	} else
 		print_word("<\\fI");
@@ -718,9 +711,7 @@ post_in(DECL_ARGS)
 	outflags &= ~MMAN_spc;
 	if (MDOC_SYNPRETTY & n->flags) {
 		print_word(">\\fP");
-		outflags |= MMAN_nl;
-		print_word(".br");
-		outflags |= MMAN_nl;
+		outflags |= MMAN_br;
 	} else
 		print_word("\\fP>");
 }
@@ -754,11 +745,8 @@ static void
 post_lb(DECL_ARGS)
 {
 
-	if (SEC_LIBRARY == n->sec) {
-		outflags |= MMAN_nl;
-		print_word(".br");
-		outflags |= MMAN_nl;
-	}
+	if (SEC_LIBRARY == n->sec)
+		outflags |= MMAN_br;
 }
 
 static int
@@ -767,11 +755,8 @@ pre_nm(DECL_ARGS)
 
 	if (MDOC_ELEM != n->type && MDOC_HEAD != n->type)
 		return(1);
-	if (MDOC_SYNPRETTY & n->flags) {
-		outflags |= MMAN_nl;
-		print_word(".br");
-		outflags |= MMAN_nl;
-	}
+	if (MDOC_SYNPRETTY & n->flags)
+		outflags |= MMAN_br;
 	print_word("\\fB");
 	outflags &= ~MMAN_spc;
 	if (NULL == n->child)
@@ -858,9 +843,7 @@ pre_vt(DECL_ARGS)
 		default:
 			return(0);
 		}
-		outflags |= MMAN_nl;
-		print_word(".br");
-		outflags |= MMAN_nl;
+		outflags |= MMAN_br;
 	}
 	print_word("\\fI");
 	outflags &= ~MMAN_spc;
@@ -876,11 +859,8 @@ post_vt(DECL_ARGS)
 
 	outflags &= ~MMAN_spc;
 	print_word("\\fP");
-	if (MDOC_SYNPRETTY & n->flags) {
-		outflags |= MMAN_nl;
-		print_word(".br");
-		outflags |= MMAN_nl;
-	}
+	if (MDOC_SYNPRETTY & n->flags)
+		outflags |= MMAN_br;
 }
 
 static int
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2012-07-08 15:48 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=201207081548.q68FmDFw032421@krisdoz.my.domain \
    --to=schwarze@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).