]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: rename octhexdigits macros
authorNikolay Nechaev <Nikolay_Nechaev@mail.ru>
Sun, 5 May 2024 09:55:00 +0000 (12:55 +0300)
committerPádraig Brady <P@draigBrady.com>
Sun, 5 May 2024 16:50:28 +0000 (17:50 +0100)
isodigit -> isoct; octtobin -> fromoct; hextobin -> fromhex.
* src/octhexdigits.h: Rename macros.
* src/stat.c, src/printf.c: Use new macros.

src/octhexdigits.h
src/printf.c
src/stat.c

index d9477154a1877f4731b05765184d1af1928a8b03..fff6866b5e11c66547e36bdeb1f2f874fbdbd1f1 100644 (file)
@@ -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')
index d6d36094187f006b8619364863ab16d5d9823c60..44bb1d314e21eaa5ebbac789098cbebdd60618b7 100644 (file)
@@ -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.
index 632f81cc9cac7f712808bdab208ea8c7ca46b7b2..91795471fd777138b0f0e789d47bdf6009cd905f 100644 (file)
@@ -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);
             }