coreutils
[Top][All Lists]
Advanced

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

[PATCH 2/2] maint: rename octhexdigits macros


From: Nikolay Nechaev
Subject: [PATCH 2/2] maint: rename octhexdigits macros
Date: Sun, 5 May 2024 12:55:00 +0300

isodigit -> isoct; octtobin -> fromoct; hextobin -> fromhex.
* src/octhexdigits.h: rename macros
* src/stat.c, src/printf.c: use new macros
---
 src/octhexdigits.h |  9 +++------
 src/printf.c       | 10 +++++-----
 src/stat.c         | 12 ++++++------
 3 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/src/octhexdigits.h b/src/octhexdigits.h
index d947715..fff6866 100644
--- a/src/octhexdigits.h
+++ b/src/octhexdigits.h
@@ -1,7 +1,4 @@
-#define isodigit(c) ('0' <= (c) && (c) <= '7')
-#define octtobin(c) ((c) - '0')
-/* FIXME-maybe: macros names may be misleading: "bin" may be interpreted as
-   "having a value of (char)'0' or (char)'1'". Rename? `hextonative`?
-   `hextoint`?  */
-#define hextobin(c) ('a' <= (c) && (c) <= 'f' ? (c) - 'a' + 10 : \
+#define isoct(c) ('0' <= (c) && (c) <= '7')
+#define fromoct(c) ((c) - '0')
+#define fromhex(c) ('a' <= (c) && (c) <= 'f' ? (c) - 'a' + 10 : \
                      'A' <= (c) && (c) <= 'F' ? (c) - 'A' + 10 : (c) - '0')
diff --git a/src/printf.c b/src/printf.c
index d6d3609..44bb1d3 100644
--- a/src/printf.c
+++ b/src/printf.c
@@ -261,20 +261,20 @@ print_esc (char const *escstart, bool octal_0)
       for (esc_length = 0, ++p;
            esc_length < 2 && c_isxdigit (to_uchar (*p));
            ++esc_length, ++p)
-        esc_value = esc_value * 16 + hextobin (*p);
+        esc_value = esc_value * 16 + fromhex (*p);
       if (esc_length == 0)
         error (EXIT_FAILURE, 0, _("missing hexadecimal number in escape"));
       putchar (esc_value);
     }
-  else if (isodigit (*p))
+  else if (isoct (*p))
     {
       /* Parse \0ooo (if octal_0 && *p == '0') or \ooo (otherwise).
          Allow \ooo if octal_0 && *p != '0'; this is an undocumented
          extension to POSIX that is compatible with Bash 2.05b.  */
       for (esc_length = 0, p += octal_0 && *p == '0';
-           esc_length < 3 && isodigit (*p);
+           esc_length < 3 && isoct (*p);
            ++esc_length, ++p)
-        esc_value = esc_value * 8 + octtobin (*p);
+        esc_value = esc_value * 8 + fromoct (*p);
       putchar (esc_value);
     }
   else if (*p && strchr ("\"\\abcefnrtv", *p))
@@ -291,7 +291,7 @@ print_esc (char const *escstart, bool octal_0)
         {
           if (! c_isxdigit (to_uchar (*p)))
             error (EXIT_FAILURE, 0, _("missing hexadecimal number in escape"));
-          uni_value = uni_value * 16 + hextobin (*p);
+          uni_value = uni_value * 16 + fromhex (*p);
         }
 
       /* Error for invalid code points 0000D800 through 0000DFFF inclusive.
diff --git a/src/stat.c b/src/stat.c
index 632f81c..9179547 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -1199,28 +1199,28 @@ print_it (char const *format, int fd, char const 
*filename,
               break;
             }
           ++b;
-          if (isodigit (*b))
+          if (isoct (*b))
             {
-              int esc_value = octtobin (*b);
+              int esc_value = fromoct (*b);
               int esc_length = 1;      /* number of octal digits */
-              for (++b; esc_length < 3 && isodigit (*b);
+              for (++b; esc_length < 3 && isoct (*b);
                    ++esc_length, ++b)
                 {
-                  esc_value = esc_value * 8 + octtobin (*b);
+                  esc_value = esc_value * 8 + fromoct (*b);
                 }
               putchar (esc_value);
               --b;
             }
           else if (*b == 'x' && c_isxdigit (to_uchar (b[1])))
             {
-              int esc_value = hextobin (b[1]); /* Value of \xhh escape. */
+              int esc_value = fromhex (b[1]);  /* Value of \xhh escape. */
               /* A hexadecimal \xhh escape sequence must have
                  1 or 2 hex. digits.  */
               ++b;
               if (c_isxdigit (to_uchar (b[1])))
                 {
                   ++b;
-                  esc_value = esc_value * 16 + hextobin (*b);
+                  esc_value = esc_value * 16 + fromhex (*b);
                 }
               putchar (esc_value);
             }
-- 
2.45.0




reply via email to

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