]> thyrsus.com Git - mad.git/commitdiff
Handle printer control codes in multi-line strings.
authorEric S. Raymond <esr@thyrsus,com>
Tue, 24 Feb 2004 10:40:19 +0000 (10:40 +0000)
committerEric S. Raymond <esr@thyrsus,com>
Tue, 24 Feb 2004 10:40:19 +0000 (10:40 +0000)
mad

diff --git a/mad b/mad
index 8b54b14f5ac21e4514089192487c39fe119db62b..c5774714a8253a3e2395347a5b9c7be315ed0071 100755 (executable)
--- a/mad
+++ b/mad
@@ -899,23 +899,19 @@ def deduce_types(str):
     return types
 
 def lptcodes(res):
-    "Interpret line-printer control character at start of format string."
-    if res[0] == ' ':          # Single space
-        res = res[1:]
-    elif res[0] == '0':                # Double space
-        res = r"\n" + res[1:]
-    elif res[0] == '+':                # No space
-        res = res[1:]
-    elif res[0] == '1':                # Skip to next page
-        res = r"\f" + res[1:]
-    elif res[0] == '2':                # Skip to next half page
-        res = r"\v\v" + res[1:]
-    elif res[0] == '4':                # Skip to next quarter page
-        res = r"\v" + res[1:]
-    else:                              # Anything else falls through 
-        nonfatal('unknown print code %s ignored\n' % res[0])
-        res = res[1:]
-    res = res + '\\n'
+    "Interpret line-printer control characters in (translated) format strings."
+    # The Jordan-method example in the MAD manual shows that a printer control
+    # code is required after each /.
+    res = r"\n" + res
+    res = res.replace(r'\n ', r'\n')           # Single space
+    res = res.replace(r'\n0', r'\n\n')         # Double space
+    res = res.replace(r'\n+', r'')             # No space
+    res = res.replace(r'\n1', r'\n\f')         # Skip to next page
+    res = res.replace(r'\n2', r'\v\v')         # Skip to next half page
+    res = res.replace(r'\n4', r'\n')           # Skip to next quarter page
+    re = res[:-1]
+    # This is not, strictly speaking, correct
+    res = res + r'\n'
     return res
 
 def print_C_statement(statement):