gbranden pushed a commit to branch branden-2023-07-05 in repository groff. commit 104416148d07068a57a415106fa7722018f224b2 Author: G. Branden Robinson <g.branden.robin...@gmail.com> AuthorDate: Sun May 7 00:32:32 2023 -0500
[troff]: Fix Savannah #64104 (1/2). * src/roff/troff/input.cpp (set_escape_char): Rename this... (assign_escape_character): ...to this. Don't permit the escape character to be set to the same thing as the control or no-break control characters. * doc/groff.texi (Using Escape Sequences): Document restrictions. Tested with: $ cat ec.roff .ec . .ec ' .ec \- $ ./build/test-groff ec.roff troff:ec.roff:1: error: ignoring escape character change request; the control character is already '.' troff:ec.roff:2: error: ignoring escape character change request; the no-break control character is already "'" troff:ec.roff:3: error: cannot select invalid escape character; using '\' --- ChangeLog | 11 +++++++++++ doc/groff.texi | 4 +++- src/roff/troff/input.cpp | 36 +++++++++++++++++++++++++++++------- 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3e086a068..023be3714 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2023-05-07 G. Branden Robinson <g.branden.robin...@gmail.com> + + [troff]: Fix Savannah #64104. + + * src/roff/troff/input.cpp (set_escape_char): Rename this... + (assign_escape_character): ...to this. Don't permit the escape + character to be set to the same thing as the control or no-break + control characters. + * doc/groff.texi (Using Escape Sequences): Document + restrictions. + 2023-05-07 G. Branden Robinson <g.branden.robin...@gmail.com> [troff]: Don't quote a character with itself in diagnostics. diff --git a/doc/groff.texi b/doc/groff.texi index 764728678..12c732fe0 100644 --- a/doc/groff.texi +++ b/doc/groff.texi @@ -6994,7 +6994,9 @@ sequence in interpretation mode. @cindex character, escape, changing (@code{ec}) Recognize the ordinary character@tie{}@var{o} as the escape character. If@tie{}@var{o} is absent or invalid, the default escape character -@samp{\} is selected. +@samp{\} is selected. If @var{o} (or @samp{\} if @var{o} is invalid) is +already the control or no-break control character, an error is diagnosed +and the request ignored. @endDefreq Switching escape sequence interpretation off to define a macro and back diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp index ca8f71db1..f0538ec78 100644 --- a/src/roff/troff/input.cpp +++ b/src/roff/troff/input.cpp @@ -159,18 +159,40 @@ void process_input_stack(); void chop_macro(); // declare to avoid friend name injection -void set_escape_char() +static void assign_escape_character() { + char ec = '\0'; + bool is_invalid = false; if (has_arg()) { - if (tok.ch() == 0) { - error("cannot select invalid escape character; using '\\'"); - escape_char = '\\'; - } + if (tok.ch() == 0) + is_invalid = true; else - escape_char = tok.ch(); + ec = tok.ch(); } else + ec = '\\'; + bool do_nothing = false; + char already_cc[] = "the control character is already"; + char already_nbcc[] = "the no-break control character is already"; + char *already_message = 0 /* nullptr */; + if (ec == curenv->control_char) { + already_message = already_cc; + do_nothing = true; + } + else if (ec == curenv->no_break_control_char) { + already_message = already_nbcc; + do_nothing = true; + } + if (do_nothing) + error("ignoring escape character change request; %1%2 %3", + is_invalid ? "cannot select invalid escape character, and" + : "", already_message, input_char_description(ec)); + else if (is_invalid) { + error("cannot select invalid escape character; using '\\'"); escape_char = '\\'; + } + else + escape_char = ec; skip_line(); } @@ -8386,7 +8408,7 @@ void init_input_requests() init_request("do", do_request); init_request("ds", define_string); init_request("ds1", define_nocomp_string); - init_request("ec", set_escape_char); + init_request("ec", assign_escape_character); init_request("ecr", restore_escape_char); init_request("ecs", save_escape_char); init_request("el", else_request); _______________________________________________ Groff-commit mailing list Groff-commit@gnu.org https://lists.gnu.org/mailman/listinfo/groff-commit