gbranden pushed a commit to branch master
in repository groff.

commit 730e773696c21c0d06e913206acf39b041982af4
Author: G. Branden Robinson <[email protected]>
AuthorDate: Thu Jul 2 10:43:31 2026 -0500

    [troff]: Refactor to kill off `ESCAPE_NEWLINE`.
    
    There appears to be no advantage to encoding escaped newlines in macro
    definitions.  Its purpose cannot be to restore or pretty-print a macro
    definition exactly as it was input, as no mechanism for doing so exists,
    and comments are already discarded upon reading.
    
    * src/roff/troff/input.h: Delete definition of `ESCAPE_NEWLINE`
      constant.
    
    * src/roff/troff/input.cpp (read_character_in_copy_mode)
      (token::next)
      (string_iterator::fill)
      (do_define_macro): Stop handling constant.
    
    Fixes <https://savannah.gnu.org/bugs/?66987>.
    
    Before:
    $ printf '.de XX\n.  nop foo\\\n bar\n..\n.XX\n.pm XX\n' \
      | ~/groff-1.24.1/bin/groff -a 2>/dev/null
    <beginning of page>
    foo bar
    $ printf '.de XX\n.  nop foo\\\n bar\n..\n.XX\n.pm XX\n' \
      | ~/groff-1.24.1/bin/groff -z 2>&1 | jq
    {
      "name": "XX",
      "file name": "<standard input>",
      "starting line number": 2,
      "length": 14,
      "contents": ".nop foo\u0011 bar\n",
      "node list": []
    }
    
    After:
    $ printf '.de XX\n.  nop foo\\\n bar\n..\n.XX\n.pm XX\n' \
      | ./build/test-groff -a 2>/dev/null
    <beginning of page>
    foo bar
    $ printf '.de XX\n.  nop foo\\\n bar\n..\n.XX\n.pm XX\n' \
      | ./build/test-groff -z 2>&1 | jq
    {
      "name": "XX",
      "file name": "<standard input>",
      "starting line number": 2,
      "length": 13,
      "contents": ".nop foo bar\n",
      "node list": []
    }
---
 ChangeLog                | 18 ++++++++++++++++++
 src/roff/troff/input.cpp | 20 +-------------------
 src/roff/troff/input.h   |  2 +-
 3 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 19f4700ce..7fc4c320d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2026-07-02  G. Branden Robinson <[email protected]>
+
+       [troff]: Refactor to kill off `ESCAPE_NEWLINE`.  There appears
+       to be no advantage to encoding escaped newlines in macro
+       definitions.  Its purpose cannot be to restore or pretty-print a
+       macro definition exactly as it was input, as no mechanism for
+       doing so exists, and comments are already discarded upon
+       reading.
+
+       * src/roff/troff/input.h: Delete definition of `ESCAPE_NEWLINE`
+       constant.
+       * src/roff/troff/input.cpp (read_character_in_copy_mode)
+       (token::next)
+       (string_iterator::fill)
+       (do_define_macro): Stop handling constant.
+
+       Fixes <https://savannah.gnu.org/bugs/?66987>.
+
 2026-06-24  G. Branden Robinson <[email protected]>
 
        * src/preproc/pic/object.cpp (graphic_object::add_text): Add new
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 31aa3aa6d..2741df64e 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -1237,13 +1237,6 @@ static int read_character_in_copy_mode(node **nd,
       continue;
     if ((ESCAPE_E == c) && handle_escaped_E)
       c = escape_char;
-    if (ESCAPE_NEWLINE == c) {
-      if (is_defining_macro)
-       return c;
-      do {
-       c = input_stack::get(nd);
-      } while (ESCAPE_NEWLINE == c);
-    }
     if ((c != escape_char) || (0U == escape_char))
       return c;
   again:
@@ -1326,8 +1319,6 @@ static int read_character_in_copy_mode(node **nd,
       }
     case '\n':
       (void) input_stack::get(0 /* nullptr */);
-      if (is_defining_macro)
-       return ESCAPE_NEWLINE;
       break;
     case ' ':
       (void) input_stack::get(0 /* nullptr */);
@@ -2324,9 +2315,6 @@ void token::next()
        nd = new hmotion_node(curenv->get_half_narrow_space_width(),
                              curenv->get_fill_color());
        return;
-      case ESCAPE_NEWLINE:
-       have_formattable_input = false;
-       break;
       case ESCAPE_LEFT_BRACE:
       ESCAPE_LEFT_BRACE:
        type = TOKEN_LEFT_BRACE;
@@ -4471,7 +4459,7 @@ int string_iterator::fill(node **np)
   ptr = p;
   while (p < e) {
     unsigned char c = *p;
-    if (('\n' == c) || (ESCAPE_NEWLINE == c)) {
+    if ('\n' == c) {
       seen_newline = true;
       p++;
       break;
@@ -5640,12 +5628,6 @@ static void do_define_macro(define_mode mode, 
calling_mode calling,
   for (;;) {
     if ('\n' == c)
       mac.clear_string_flag();
-    while (ESCAPE_NEWLINE == c) {
-      if ((DEFINE_NORMAL == mode) || (DEFINE_APPEND == mode))
-       // TODO: grochar; may need NFD decomposition and UTF-8 encoding
-       mac.append(static_cast<unsigned char>(c));
-      c = read_character_in_copy_mode(&n, true /* is_defining_macro */);
-    }
     if (can_terminate_definition_with_dot && ('.' == c)) {
       const char *s = term.contents();
       int d = '\0';
diff --git a/src/roff/troff/input.h b/src/roff/troff/input.h
index 44e47f91e..367bac42b 100644
--- a/src/roff/troff/input.h
+++ b/src/roff/troff/input.h
@@ -26,7 +26,7 @@ const int ESCAPE_QUESTION = 015;      // \u000d
 const int BEGIN_TRAP = 016;            // \u000e
 const int END_TRAP = 017;              // \u000f
 const int PAGE_EJECTOR = 020;          // \u0010
-const int ESCAPE_NEWLINE = 021;                // \u0011
+// 021, \u0011 unused
 const int ESCAPE_AMPERSAND = 022;      // \u0012
 const int ESCAPE_UNDERSCORE = 023;     // \u0013
 const int ESCAPE_BAR = 024;            // \u0014

_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to