groff-commit
[Top][All Lists]
Advanced

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

[groff] 97/127: [troff]: Don't quote a character with itself.


From: G. Branden Robinson
Subject: [groff] 97/127: [troff]: Don't quote a character with itself.
Date: Mon, 10 Jul 2023 04:31:02 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 2d89e22329901a07512ffa8e2ae715f537e35f4d
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sun May 7 00:26:11 2023 -0500

    [troff]: Don't quote a character with itself.
    
    ...in diagnostics.
    
    * src/roff/troff/input.cpp (token::description, input_char_description):
      When quoting the ' character in diagnostics, use double-quotes, not
      apostrophes.
    
    Also swap order of a comparison to avoid inadvertent lvalue assignment.
---
 ChangeLog                |  8 ++++++++
 src/roff/troff/input.cpp | 19 +++++++++++++++----
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 881015ec7..e46c83c34 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-05-07  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       [troff]: Don't quote a character with itself in diagnostics.
+
+       * src/roff/troff/input.cpp (token::description)
+       (input_char_description): When quoting the ' character in
+       diagnostics, use double-quotes, not apostrophes.
+
 2023-05-06  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        [troff]: Trivially refactor.
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index a51e1a545..ca8f71db1 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -2404,8 +2404,12 @@ const char *token::description()
   case TOKEN_BACKSPACE:
     return "a backspace character";
   case TOKEN_CHAR:
-    if (c == INPUT_DELETE)
+    if (INPUT_DELETE == c)
       return "a delete character";
+    else if ('\'' == c) {
+      (void) snprintf(buf, bufsz, "character \"%c\"", c);
+      return buf;
+    }
     else {
       (void) snprintf(buf, bufsz, "character '%c'", c);
       return buf;
@@ -6682,9 +6686,16 @@ const char *input_char_description(int c)
     return buf;
   }
   if (csprint(c)) {
-    buf[0] = '\'';
-    buf[1] = c;
-    buf[2] = '\'';
+    if ('\'' == c) {
+      buf[0] = '"';
+      buf[1] = c;
+      buf[2] = '"';
+    }
+    else {
+      buf[0] = '\'';
+      buf[1] = c;
+      buf[2] = '\'';
+    }
     return buf;
   }
   sprintf(buf, "character code %d", c);



reply via email to

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