groff-commit
[Top][All Lists]
Advanced

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

[groff] 90/115: [troff]: Don't quote a character with itself.


From: G. Branden Robinson
Subject: [groff] 90/115: [troff]: Don't quote a character with itself.
Date: Thu, 1 Jun 2023 10:46:15 -0400 (EDT)

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

commit 608ab18a0d6414b75e83bd3da044df9fa8ccb11c
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 0c8b225b7..c96de8e43 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 adfbf0bef..9f5759c04 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]