groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 21/28: [troff]: Discard garbage from `\X` contents.


From: G. Branden Robinson
Subject: [groff] 21/28: [troff]: Discard garbage from `\X` contents.
Date: Mon, 4 Mar 2024 07:42:39 -0500 (EST)

gbranden pushed a commit to branch master
in repository groff.

commit df12c8592ee11a72d0aeace378cf4300d1a89186
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Mon Mar 4 01:51:13 2024 -0600

    [troff]: Discard garbage from `\X` contents.
    
    [troff]: Improve encoding of *roff string contents when interpolated
    into device control escape sequences.
    
    * src/roff/troff/input.cpp (encode_char_for_troff_output): Discard
      several escape sequences from `\X` contents when interpolated: `\%`,
      `\:`, `\&`, `\)`.  Interpolate the escape character into
      device-independent output as `\` no matter what the *roff escape
      character is defined to be.
    
    * src/roff/groff/tests/device-control-special-character-handling.sh:
      Update test expectations.  Comment out some tests that depended on a
      reverted commit of a half-baked idea.  (See Savannah #64484.)
---
 ChangeLog                                          | 16 +++++++++++
 .../device-control-special-character-handling.sh   | 33 +++++++++++-----------
 src/roff/troff/input.cpp                           | 22 ++++++++-------
 3 files changed, 45 insertions(+), 26 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index af982750a..507309c8f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2024-03-04  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       [troff]: Improve encoding of *roff string contents when
+       interpolated into device control escape sequences.
+
+       * src/roff/troff/input.cpp (encode_char_for_troff_output):
+       Discard several escape sequences from `\X` contents when
+       interpolated: `\%`, `\:`, `\&`, `\)`.  Interpolate the escape
+       character into device-independent output as `\` no matter what
+       the *roff escape character is defined to be.
+
+       * src/roff/groff/tests/\
+       device-control-special-character-handling.sh: Update test
+       expectations.  Comment out some tests that depended on a
+       reverted commit of a half-baked idea.  (See Savannah #64484.)
+
 2024-03-03  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * tmac/an.tmac: Add experimental feature to support increasing
diff --git a/src/roff/groff/tests/device-control-special-character-handling.sh 
b/src/roff/groff/tests/device-control-special-character-handling.sh
index 5ad3713d7..661125b76 100755
--- a/src/roff/groff/tests/device-control-special-character-handling.sh
+++ b/src/roff/groff/tests/device-control-special-character-handling.sh
@@ -39,6 +39,7 @@ output=$(printf '%s\n' "$input" | "$groff" -T ps -Z 2> 
/dev/null \
 error=$(printf '%s\n' "$input" | "$groff" -T ps -Z 2>&1 > /dev/null)
 
 echo "$output"
+echo "$error"
 
 echo "checking X escape sequence, default escape character" >&2
 # x X bogus1: esc man-beast\[u1F00] -'"`^\~
@@ -46,11 +47,11 @@ echo "$output" \
   | grep -qx 'x X bogus1: esc man-beast\\\[u1F00\] -'"'"'"`^\\~' \
   || wail
 
-echo "checking device request, default escape character" >&2
-# x X bogus1: req man-beast\[u1F00] -'"`^\~
-echo "$output" \
-  | grep -qx 'x X bogus1: req man-beast\\\[u1F00\] -'"'"'"`^\\~' \
-  || wail
+#echo "checking device request, default escape character" >&2
+## x X bogus1: req man-beast\[u1F00] -'"`^\~
+#echo "$output" \
+#  | grep -qx 'x X bogus1: req man-beast\\\[u1F00\] -'"'"'"`^\\~' \
+#  || wail
 
 echo "checking X escape sequence, alternate escape character" >&2
 # x X bogus2: esc man-beast\[u1F00] -'"`^\~
@@ -58,19 +59,19 @@ echo "$output" \
   | grep -qx 'x X bogus2: esc man-beast\\\[u1F00\] -'"'"'"`^\\~' \
   || wail
 
-echo "checking device request, alternate escape character" >&2
-# x X bogus2: req man-beast\[u1F00] -'"`^\~
-echo "$output" \
-  | grep -qx 'x X bogus2: req man-beast\\\[u1F00\] -'"'"'"`^\\~' \
-  || wail
+#echo "checking device request, alternate escape character" >&2
+## x X bogus2: req man-beast\[u1F00] -'"`^\~
+#echo "$output" \
+#  | grep -qx 'x X bogus2: req man-beast\\\[u1F00\] -'"'"'"`^\\~' \
+#  || wail
 
 echo "checking for errors on unsupported special character escapes" >&2
-for lineno in 2 3 5 6
-do
-  echo "$error" \
-    | grep -q 'troff:.*:'$lineno':.* invalid.*device control command' \
-    || wail
-done
+#for lineno in 2 3 5 6
+#do
+#  echo "$error" \
+#    | grep -q 'troff:.*:'$lineno':.* invalid.*device control command' \
+#    || wail
+#done
 
 test -z "$fail"
 
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index fdf14d0f1..2c7ce5439 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -5616,12 +5616,20 @@ static node *do_non_interpreted()
   return new non_interpreted_node(mac);
 }
 
+// In troff output, we translate the escape character to '\', but it is
+// up to the postprocessor to interpret it as such.  (This mostly
+// matters for device control commands.)
 static void encode_char_for_troff_output(macro *mac, const char c)
 {
   if ('\0' == c) {
     if (tok.is_stretchable_space()
             || tok.is_unstretchable_space())
       mac->append(' ');
+    else if ((tok.is_hyphen_indicator())
+            || tok.is_zero_width_break()
+            || tok.is_dummy()
+            || tok.is_transparent_dummy())
+      /* do nothing */;
     else if (tok.is_special()) {
       const char *sc;
       if (font::use_charnames_in_special) {
@@ -5665,21 +5673,15 @@ static void encode_char_for_troff_output(macro *mac, 
const char c)
                " control escape sequence", sc);
       }
     }
-    else if (tok.is_hyphen_indicator()
-              || tok.is_dummy()
-              || tok.is_transparent_dummy()
-              || tok.is_zero_width_break())
+    else
       error("%1 is invalid within device control escape sequence",
            tok.description());
   }
   else {
-    if ((font::use_charnames_in_special) && ('\\' == c)) {
-      /*
-       * add escape escape sequence
-       */
+    if (c == escape_char)
+      mac->append('\\');
+    else
       mac->append(c);
-    }
-    mac->append(c);
   }
 }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]