From ca4f08da1afe3dbae32fe342d9cb113171352dfb Mon Sep 17 00:00:00 2001 From: Andres Mejia Date: Fri, 3 Feb 2012 21:13:53 -0500 Subject: [PATCH] Use states to determine if writing literal text for
 tags.

---
 doc/mdoc2mediawiki.awk | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/doc/mdoc2mediawiki.awk b/doc/mdoc2mediawiki.awk
index 9d5852995..16649dae8 100755
--- a/doc/mdoc2mediawiki.awk
+++ b/doc/mdoc2mediawiki.awk
@@ -26,6 +26,10 @@ BEGIN {
   sep = ""
   nextsep = " "
   spaces = "                    "
+
+  NORMAL_STATE = 0
+  PRETAG_STATE = 1
+  STATE = NORMAL_STATE
 }
 
 # Add a word with appropriate preceding whitespace
@@ -63,7 +67,11 @@ function endline() {
   addclose(trailer)
   trailer = ""
   if(length(out) > 0) {
-    print out " "
+    if (STATE == PRETAG_STATE) {
+      print out
+    } else {
+      print out " "
+    }
     out=""
   }
   if(displaylines > 0) {
@@ -159,6 +167,7 @@ function splitwords(l, dest, n, o, w) {
       dispstart()
       displaylines = 1
     } else if(match(words[w],"^Bd$")) { # Begin display
+      STATE = PRETAG_STATE
       if(match(words[w+1],"-literal")) {
         dispstart()
 	displaylines=10000
@@ -167,6 +176,7 @@ function splitwords(l, dest, n, o, w) {
     } else if(match(words[w],"^Ed$")) { # End display
       displaylines = 0
       dispend()
+      STATE = NORMAL_STATE
     } else if(match(words[w],"^Ns$")) { # Suppress space before next word
       sep=""
     } else if(match(words[w],"^No$")) { # Normal text
-- 
2.47.3