gbranden pushed a commit to branch master
in repository groff.

commit 79e4a2c51103d3d7dd80ed66497b2c23da6241b3
Author: G. Branden Robinson <[email protected]>
AuthorDate: Wed Oct 22 14:46:41 2025 -0500

    [troff]: Diagnose spaces after `\c` on a line.
    
    * src/roff/troff/input.cpp (process_input_stack <token::TOKEN_SPACE>):
      Diagnose ignored spaces after an output line continuation escape
      sequence (`\c`) on an input line.
    
    * src/roff/troff/env.cpp (environment::space_newline): Add assertion on
      falsity of `was_line_interrupted` since this member function should
      now be unreachable when that condition obtains.
    
    * doc/groff.texi (Warnings) <syntax>:
    * src/roff/troff/troff.1.man (Warnings) <syntax>: Document it.
    
    Illustration:
    
    $ printf 'foo\\cA Z\n' | ./build/test-groff -aww
    <beginning of page>
    troff:<standard input>:1: warning: ignoring character 'A' on input line 
after output line continuation escape sequence
    troff:<standard input>:1: warning: ignoring a space on input line after 
output line continuation escape sequence
    troff:<standard input>:1: warning: ignoring character 'Z' on input line 
after output line continuation escape sequence
    foo
---
 ChangeLog                  | 12 ++++++++++++
 doc/groff.texi.in          |  2 +-
 src/roff/troff/env.cpp     |  1 +
 src/roff/troff/input.cpp   |  6 +++++-
 src/roff/troff/troff.1.man |  2 +-
 5 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 34cb51a02..a287d6986 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2025-10-22  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/input.cpp (process_input_stack
+       <token::TOKEN_SPACE>): Diagnose ignored spaces after an output
+       line continuation escape sequence (`\c`) on an input line.
+       * src/roff/troff/env.cpp (environment::space_newline): Add
+       assertion on falsity of `was_line_interrupted` since this member
+       function should now be unreachable when that condition obtains.
+
+       * doc/groff.texi (Warnings) <syntax>:
+       * src/roff/troff/troff.1.man (Warnings) <syntax>: Document it.
+
 2025-10-22  G. Branden Robinson <[email protected]>
 
        [gropdf]: Add negative testing to new unit tests; check that
diff --git a/doc/groff.texi.in b/doc/groff.texi.in
index bcafeff66..1a96b4a31 100644
--- a/doc/groff.texi.in
+++ b/doc/groff.texi.in
@@ -19303,7 +19303,7 @@ A numeric expression was out of range for its context.
 A self-contradictory hyphenation mode or character flags were requested;
 an empty or incomplete numeric expression was encountered;
 an operand to a numeric operator was missing;
-an attempt was made to format characters on an input line
+an attempt was made to format characters or spaces on an input line
 after an output line continuation escape sequence;
 a recognized but inapposite escape sequence
 or unprintable character code
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index d4ac8108b..1f0533229 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -514,6 +514,7 @@ void environment::add_italic_correction()
 
 void environment::space_newline()
 {
+  assert(!was_line_interrupted);
   assert((current_tab == TAB_NONE) && !has_current_field);
   if (was_line_interrupted)
     return;
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 2532f1706..49c7a5217 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -3258,7 +3258,11 @@ void process_input_stack()
       }
     case token::TOKEN_SPACE:
       {
-       if (possibly_handle_first_page_transition())
+       if (curenv->get_was_line_interrupted())
+         warning(WARN_SYNTAX, "ignoring %1 on input line after"
+                 " output line continuation escape sequence",
+                 tok.description());
+       else if (possibly_handle_first_page_transition())
          ;
        else if (reading_beginning_of_input_line
                 && !curenv->get_was_previous_line_interrupted()) {
diff --git a/src/roff/troff/troff.1.man b/src/roff/troff/troff.1.man
index c327234b4..6a79d82dc 100644
--- a/src/roff/troff/troff.1.man
+++ b/src/roff/troff/troff.1.man
@@ -796,7 +796,7 @@ It never occurs in compatibility mode.
 A self-contradictory hyphenation mode or character flags were requested;
 an empty or incomplete numeric expression was encountered;
 an operand to a numeric operator was missing;
-an attempt was made to format characters on an input line
+an attempt was made to format characters or spaces on an input line
 after an output line continuation escape sequence;
 a recognized but inapposite escape sequence
 or unprintable character code

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

Reply via email to