groff-commit
[Top][All Lists]
Advanced

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

[groff] 51/63: [troff]: \A and \B interpolate nothing if invalid.


From: G. Branden Robinson
Subject: [groff] 51/63: [troff]: \A and \B interpolate nothing if invalid.
Date: Mon, 19 Aug 2024 20:06:41 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit f3906d80811fd480adfd23c82719b39c9ece22f1
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Mon Aug 19 16:50:40 2024 -0500

    [troff]: \A and \B interpolate nothing if invalid.
    
    * src/roff/troff/input.cpp: Revise `\A` and `\B` escape sequences to no
      longer interpolate anything (not even "0" for "false") if they
      lexically don't even get as far as an opening delimiter; in such a
      case they are invalid.
    
      (do_name_test, do_expr_test): Do it.  Change return type from `bool`
      to a pointer to a constant `char`.  Return null pointer if there is no
      delimiter.  Otherwise return string instead of Boolean literals.
    
      (token::next): Handle null pointer returns from these functions.
---
 ChangeLog                | 12 ++++++++++++
 src/roff/troff/input.cpp | 32 +++++++++++++++++++++-----------
 2 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 225b9c3be..5577979b0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2024-08-19  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       * src/roff/troff/input.cpp: Revise `\A` and `\B` escape
+       sequences to no longer interpolate anything (not even "0" for
+       "false") if they lexically don't even get as far as an opening
+       delimiter; in such a case they are invalid.
+       (do_name_test, do_expr_test): Do it.  Change return type from
+       `bool` to a pointer to a constant `char`.  Return null pointer
+       if there is no delimiter.  Otherwise return string instead of
+       Boolean literals.
+       (token::next): Handle null pointer returns from these functions.
+
 2024-08-19  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * src/roff/troff/input.cpp (do_overstrike, do_bracket)
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index b06d1a897..ddc8c8e00 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -1645,13 +1645,13 @@ static node *do_bracket() // \b
   return bracketnode;
 }
 
-static bool do_name_test() // \A
+static const char *do_name_test() // \A
 {
   int start_level = input_stack::get_level();
   token start_token;
   start_token.next();
   if (!start_token.is_usable_as_delimiter(true /* report error */))
-    return false;
+    return 0 /* nullptr */;
   bool got_bad_char = false;
   bool got_some_char = false;
   for (;;) {
@@ -1674,16 +1674,16 @@ static bool do_name_test() // \A
       got_bad_char = true;
     got_some_char = true;
   }
-  return (got_some_char && !got_bad_char);
+  return (got_some_char && !got_bad_char) ? "1" : "0";
 }
 
-static bool do_expr_test() // \B
+static const char *do_expr_test() // \B
 {
   token start_token;
   start_token.next();
   int start_level = input_stack::get_level();
   if (!start_token.is_usable_as_delimiter(true /* report error */))
-    return false;
+    return 0 /* nullptr */;
   tok.next();
   // disable all warning and error messages temporarily
   int saved_warning_mask = warning_mask;
@@ -1697,7 +1697,7 @@ static bool do_expr_test() // \B
   // get_number_rigidly() has left `token` pointing at the input
   // character after the end of the expression.
   if (tok == start_token && input_stack::get_level() == start_level)
-    return result;
+    return (result ? "1" : "0");
   // There may be garbage after the expression but before the closing
   // delimiter.  Eat it.
   for (;;) {
@@ -1713,7 +1713,7 @@ static bool do_expr_test() // \B
     if (tok == start_token && input_stack::get_level() == start_level)
       break;
   }
-  return false;
+  return "0";
 }
 
 #if 0
@@ -2195,8 +2195,13 @@ void token::next()
        type = TOKEN_NODE;
        return;
       case 'A':
-       c = '0' + do_name_test();
-       type = TOKEN_CHAR;
+       {
+         const char *res = do_name_test();
+         if (0 /* nullptr */ == res)
+           break;
+         c = *res;
+         type = TOKEN_CHAR;
+       }
        return;
       case 'b':
        nd = do_bracket();
@@ -2205,8 +2210,13 @@ void token::next()
        type = TOKEN_NODE;
        return;
       case 'B':
-       c = '0' + do_expr_test();
-       type = TOKEN_CHAR;
+       {
+         const char *res = do_expr_test();
+         if (0 /* nullptr */ == res)
+           break;
+         c = *res;
+         type = TOKEN_CHAR;
+       }
        return;
       case 'c':
        goto ESCAPE_c;



reply via email to

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