groff-commit
[Top][All Lists]
Advanced

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

[groff] 91/115: [troff]: Fix Savannah #64104 (1/2).


From: G. Branden Robinson
Subject: [groff] 91/115: [troff]: Fix Savannah #64104 (1/2).
Date: Thu, 1 Jun 2023 10:46:15 -0400 (EDT)

gbranden pushed a commit to branch branden-2022-06-01
in repository groff.

commit 09fd3f891998406d556ca904b4ff69d88495f4b1
Author: G. Branden Robinson <g.branden.robinson@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 c96de8e43..e01e074b5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2023-05-07  G. Branden Robinson <g.branden.robinson@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.robinson@gmail.com>
 
        [troff]: Don't quote a character with itself in diagnostics.
diff --git a/doc/groff.texi b/doc/groff.texi
index 6e80659c7..587938460 100644
--- a/doc/groff.texi
+++ b/doc/groff.texi
@@ -6978,7 +6978,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 9f5759c04..272abd480 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);



reply via email to

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