gbranden pushed a commit to branch master
in repository groff.
commit d02c13130f4ed8f66d1f16e27a7da4c818d1698a
Author: G. Branden Robinson <[email protected]>
AuthorDate: Tue Oct 21 10:59:04 2025 -0500
[troff]: Refactor recent change.
...to diagnose ignored characters on input lines after `\c` escape
sequence) to catch the problem earlier in processing and report more
information (before it is lost by calling into member functions of the
`environment` class.
* src/roff/troff/env.cpp (environment::add_char): Drop just-added logic
to handle case when `was_line_interrupted` is true. Add initial
`assert()` to check desired invariant: we shouldn't reach this member
function when a line has been interrupted.
* src/roff/troff/env.h (class environment): Add accessor member function
`get_was_line_interrupted()` for private Boolean member variable
`was_line_interrupted`.
* src/roff/troff/input.cpp (process_input_stack): Check line
interruption status of current environment when processing tokens of
type `TOKEN_CHAR`, `TOKEN_INDEXED_CHAR`, and `TOKEN_SPECIAL_CHAR`;
skip the usual actions taken if that status is true, and throw a
warning in category "syntax" instead.
Illustration:
$ printf 'foo\\cA\\(aq\\[dq]\\C"rs"\\N"45"\n' | ./build/test-groff -a -ww
<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 special character "aq" on input
line after output line continuation escape sequence
troff:<standard input>:1: warning: ignoring special character "dq" on input
line after output line continuation escape sequence
troff:<standard input>:1: warning: ignoring special character "rs" on input
line after output line continuation escape sequence
troff:<standard input>:1: warning: ignoring an escaped 'N' on input line
after output line continuation escape sequence
foo
---
ChangeLog | 23 +++++++++++++++++++++++
src/roff/troff/env.cpp | 15 +++------------
src/roff/troff/env.h | 1 +
src/roff/troff/input.cpp | 18 +++++++++++++++++-
4 files changed, 44 insertions(+), 13 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e5a37c931..45072b656 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2025-10-21 G. Branden Robinson <[email protected]>
+
+ [troff]: Refactor recent change (to diagnose ignored characters
+ on input lines after `\c` escape sequence) to catch the problem
+ earlier in processing and report more information (before it is
+ lost by calling into member functions of the `environment`
+ class).
+
+ * src/roff/troff/env.cpp (environment::add_char): Drop
+ just-added logic to handle case when `was_line_interrupted` is
+ true. Add initial `assert()` to check desired invariant: we
+ shouldn't reach this member function when a line has been
+ interrupted.
+ * src/roff/troff/env.h (class environment): Add accessor member
+ function `get_was_line_interrupted()` for private Boolean member
+ variable `was_line_interrupted`.
+ * src/roff/troff/input.cpp (process_input_stack): Check line
+ interruption status of current environment when processing
+ tokens of type `TOKEN_CHAR`, `TOKEN_INDEXED_CHAR`, and
+ `TOKEN_SPECIAL_CHAR`; skip the usual actions taken if that
+ status is true, and throw a warning in category "syntax"
+ instead.
+
2025-10-21 G. Branden Robinson <[email protected]>
* src/roff/troff/input.cpp (process_input_stack): Rename
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index 174562a86..d4ac8108b 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -342,19 +342,10 @@ void leader_character_request()
void environment::add_char(charinfo *ci)
{
+ assert(!was_line_interrupted);
node *gc_np = 0 /* nullptr */;
- if (was_line_interrupted) {
- unsigned char cc = ci->get_ascii_code();
- if (0 == cc)
- warning(WARN_SYNTAX, "ignoring special character on input line"
- " after output line continuation escape sequence");
- else if (cc != '\'' )
- warning(WARN_SYNTAX, "ignoring character '%1' on input line after"
- " output line continuation escape sequence", cc);
- else
- warning(WARN_SYNTAX, "ignoring character \"%1\" on input line"
- " after output line continuation escape sequence", cc);
- }
+ if (was_line_interrupted)
+ ;
// don't allow fields in dummy environments
else if (ci == field_delimiter_char && !is_dummy_env) {
if (has_current_field)
diff --git a/src/roff/troff/env.h b/src/roff/troff/env.h
index 418163b02..e99eb3eee 100644
--- a/src/roff/troff/env.h
+++ b/src/roff/troff/env.h
@@ -329,6 +329,7 @@ public:
const char *get_input_trap_macro();
int get_right_aligned_line_count();
int get_no_number_count();
+ bool get_was_line_interrupted() { return was_line_interrupted; }
int get_was_previous_line_interrupted() { return
was_previous_line_interrupted; }
color *get_fill_color();
color *get_stroke_color();
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 0f82c5a0b..2532f1706 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -3178,7 +3178,12 @@ void process_input_stack()
fprintf(stderr, "found [%c]\n", ch); fflush(stderr);
}
#endif
- curenv->add_char(charset_table[ch]);
+ if (curenv->get_was_line_interrupted())
+ warning(WARN_SYNTAX, "ignoring %1 on input line after"
+ " output line continuation escape sequence",
+ tok.description());
+ else
+ curenv->add_char(charset_table[ch]);
tok.next();
if (tok.type != token::TOKEN_CHAR)
break;
@@ -3354,6 +3359,17 @@ void process_input_stack()
curenv->output_pending_lines();
break;
}
+ case token::TOKEN_INDEXED_CHAR:
+ case token::TOKEN_SPECIAL_CHAR:
+ if (curenv->get_was_line_interrupted())
+ warning(WARN_SYNTAX, "ignoring %1 on input line after output"
+ " line continuation escape sequence",
+ tok.description());
+ else {
+ reading_beginning_of_input_line = false;
+ tok.process();
+ }
+ break;
default:
{
reading_beginning_of_input_line = false;
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit