]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: ISDIGIT → c_isdigit
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 30 Dec 2024 18:45:54 +0000 (10:45 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 30 Dec 2024 18:55:23 +0000 (10:55 -0800)
* gl/lib/strnumcmp-in.h (ISDIGIT):
* src/system.h (ISDIGIT): Remove.  All uses replaced by c_isdigit,
with appropriate inclusions of c-ctype.h.  This is more regular,
and is more portable to existing (but unlikely) platforms where
INT_MAX == UINT_MAX.

23 files changed:
gl/lib/strnumcmp-in.h
gl/modules/strnumcmp
src/csplit.c
src/expand-common.c
src/expr.c
src/factor.c
src/fmt.c
src/head.c
src/kill.c
src/ls.c
src/nice.c
src/od.c
src/operand2sig.c
src/pr.c
src/printf.c
src/seq.c
src/set-fields.c
src/sort.c
src/stat.c
src/system.h
src/tail.c
src/test.c
src/tr.c

index 4662bbeec420fa564b222eaff12e4de8fd78f410..7b02145dfa18c1079c41a578638415c910f9556c 100644 (file)
 
 # include "strnumcmp.h"
 
+# include "c-ctype.h"
 # include <stddef.h>
 
 # define NEGATION_SIGN   '-'
 # define NUMERIC_ZERO    '0'
 
-/* ISDIGIT differs from isdigit, as follows:
-   - Its arg may be any int or unsigned int; it need not be an unsigned char
-     or EOF.
-   - It's typically faster.
-   POSIX says that only '0' through '9' are digits.  Prefer ISDIGIT to
-   isdigit unless it's important to use the locale's definition
-   of 'digit' even when the host does not conform to POSIX.  */
-# define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)
-
-
 /* Compare strings A and B containing decimal fractions < 1.
    DECIMAL_POINT is the decimal point.  Each string
    should begin with a decimal point followed immediately by the digits
@@ -76,13 +67,13 @@ fraccompare (char const *a, char const *b, char decimal_point)
   if (*a == decimal_point && *b == decimal_point)
     {
       while (*++a == *++b)
-        if (! ISDIGIT (*a))
+        if (! c_isdigit (*a))
           return 0;
-      if (ISDIGIT (*a) && ISDIGIT (*b))
+      if (c_isdigit (*a) && c_isdigit (*b))
         return *a - *b;
-      if (ISDIGIT (*a))
+      if (c_isdigit (*a))
         goto a_trailing_nonzero;
-      if (ISDIGIT (*b))
+      if (c_isdigit (*b))
         goto b_trailing_nonzero;
       return 0;
     }
@@ -91,14 +82,14 @@ fraccompare (char const *a, char const *b, char decimal_point)
     a_trailing_nonzero:
       while (*a == NUMERIC_ZERO)
         a++;
-      return ISDIGIT (*a);
+      return c_isdigit (*a);
     }
   else if (*b++ == decimal_point)
     {
     b_trailing_nonzero:
       while (*b == NUMERIC_ZERO)
         b++;
-      return - ISDIGIT (*b);
+      return - c_isdigit (*b);
     }
   return 0;
 }
@@ -131,7 +122,7 @@ numcompare (char const *a, char const *b,
             do
               tmpa = *++a;
             while (tmpa == NUMERIC_ZERO);
-          if (ISDIGIT (tmpa))
+          if (c_isdigit (tmpa))
             return -1;
           while (tmpb == NUMERIC_ZERO || tmpb == thousands_sep)
             tmpb = *++b;
@@ -139,13 +130,13 @@ numcompare (char const *a, char const *b,
             do
               tmpb = *++b;
             while (tmpb == NUMERIC_ZERO);
-          return - ISDIGIT (tmpb);
+          return - c_isdigit (tmpb);
         }
       do
         tmpb = *++b;
       while (tmpb == NUMERIC_ZERO || tmpb == thousands_sep);
 
-      while (tmpa == tmpb && ISDIGIT (tmpa))
+      while (tmpa == tmpb && c_isdigit (tmpa))
         {
           do
             tmpa = *++a;
@@ -155,18 +146,18 @@ numcompare (char const *a, char const *b,
           while (tmpb == thousands_sep);
         }
 
-      if ((tmpa == decimal_point && !ISDIGIT (tmpb))
-          || (tmpb == decimal_point && !ISDIGIT (tmpa)))
+      if ((tmpa == decimal_point && !c_isdigit (tmpb))
+          || (tmpb == decimal_point && !c_isdigit (tmpa)))
         return fraccompare (b, a, decimal_point);
 
       tmp = tmpb - tmpa;
 
-      for (log_a = 0; ISDIGIT (tmpa); ++log_a)
+      for (log_a = 0; c_isdigit (tmpa); ++log_a)
         do
           tmpa = *++a;
         while (tmpa == thousands_sep);
 
-      for (log_b = 0; ISDIGIT (tmpb); ++log_b)
+      for (log_b = 0; c_isdigit (tmpb); ++log_b)
         do
           tmpb = *++b;
         while (tmpb == thousands_sep);
@@ -188,7 +179,7 @@ numcompare (char const *a, char const *b,
         do
           tmpb = *++b;
         while (tmpb == NUMERIC_ZERO);
-      if (ISDIGIT (tmpb))
+      if (c_isdigit (tmpb))
         return 1;
       while (tmpa == NUMERIC_ZERO || tmpa == thousands_sep)
         tmpa = *++a;
@@ -196,7 +187,7 @@ numcompare (char const *a, char const *b,
         do
           tmpa = *++a;
         while (tmpa == NUMERIC_ZERO);
-      return ISDIGIT (tmpa);
+      return c_isdigit (tmpa);
     }
   else
     {
@@ -205,7 +196,7 @@ numcompare (char const *a, char const *b,
       while (tmpb == NUMERIC_ZERO || tmpb == thousands_sep)
         tmpb = *++b;
 
-      while (tmpa == tmpb && ISDIGIT (tmpa))
+      while (tmpa == tmpb && c_isdigit (tmpa))
         {
           do
             tmpa = *++a;
@@ -215,18 +206,18 @@ numcompare (char const *a, char const *b,
           while (tmpb == thousands_sep);
         }
 
-      if ((tmpa == decimal_point && !ISDIGIT (tmpb))
-          || (tmpb == decimal_point && !ISDIGIT (tmpa)))
+      if ((tmpa == decimal_point && !c_isdigit (tmpb))
+          || (tmpb == decimal_point && !c_isdigit (tmpa)))
         return fraccompare (a, b, decimal_point);
 
       tmp = tmpa - tmpb;
 
-      for (log_a = 0; ISDIGIT (tmpa); ++log_a)
+      for (log_a = 0; c_isdigit (tmpa); ++log_a)
         do
           tmpa = *++a;
         while (tmpa == thousands_sep);
 
-      for (log_b = 0; ISDIGIT (tmpb); ++log_b)
+      for (log_b = 0; c_isdigit (tmpb); ++log_b)
         do
           tmpb = *++b;
         while (tmpb == thousands_sep);
index 83f4e7c388aaae4b82e22a04f41b4d320d82fd0c..f36da19d0a639508b5fc108d0af609f6877a3870 100644 (file)
@@ -8,6 +8,7 @@ lib/strnumcmp.h
 lib/strnumcmp-in.h
 
 Depends-on:
+c-ctype
 inline
 stddef
 
index babb73949dd39967efa83648332b407f9fffcb83..e6455f00ceebd31ac851a292a43add48d005aad2 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <regex.h>
 
+#include "c-ctype.h"
 #include "fd-reopen.h"
 #include "quote.h"
 #include "safe-read.h"
@@ -1262,10 +1263,10 @@ max_out (char *format)
         percent = true;
         int flags;
         f += get_format_flags (f, &flags);
-        while (ISDIGIT (*f))
+        while (c_isdigit (*f))
           f++;
         if (*f == '.')
-          while (ISDIGIT (*++f))
+          while (c_isdigit (*++f))
             continue;
         check_format_conv_type (f, flags);
       }
index e3f9ea84eccfc0cb4ae622ba02fd392ed4006f76..2fa0e89106b958dc84d252f0df6dd84caf7c2ecf 100644 (file)
@@ -20,6 +20,7 @@
 #include <stdio.h>
 #include <sys/types.h>
 #include "system.h"
+#include "c-ctype.h"
 #include "fadvise.h"
 #include "quote.h"
 
@@ -183,7 +184,7 @@ parse_tab_stops (char const *stops)
           increment_tabval = true;
           extend_tabval = false;
         }
-      else if (ISDIGIT (*stops))
+      else if (c_isdigit (*stops))
         {
           if (!have_tabval)
             {
index 3ecec07350b4e1815cc9286d93963bdd2821df07..5a680d2ec2482590a3c55e45457701d9a2472a2e 100644 (file)
@@ -35,6 +35,7 @@
 
 #include <gmp.h>
 #include <regex.h>
+#include "c-ctype.h"
 #include "long-options.h"
 #include "mcel.h"
 #include "strnumcmp.h"
@@ -439,7 +440,7 @@ looks_like_integer (char const *cp)
   cp += (*cp == '-');
 
   do
-    if (! ISDIGIT (*cp))
+    if (! c_isdigit (*cp))
       return false;
   while (*++cp);
 
index 85cd1b1c90f42ea06f7185023715081c890cc053..04aa8806e7b10d465fcbe911f32326742e5f4539 100644 (file)
 
 #include "system.h"
 #include "assure.h"
+#include "c-ctype.h"
 #include "full-write.h"
 #include "quote.h"
 #include "readtokens.h"
@@ -2257,7 +2258,7 @@ strto2uintmax (uintmax_t *hip, uintmax_t *lop, char const *s)
       if (c == 0)
         break;
 
-      if (UNLIKELY (!ISDIGIT (c)))
+      if (UNLIKELY (!c_isdigit (c)))
         {
           err = LONGINT_INVALID;
           break;
index 59086f35e0e3ae9c6a6073f0ee5661a38517b2b2..122debc9d38e71e69c1a0f70eb5a5c7a8b7f2b0e 100644 (file)
--- a/src/fmt.c
+++ b/src/fmt.c
@@ -334,7 +334,7 @@ main (int argc, char **argv)
   prefix = "";
   prefix_length = prefix_lead_space = prefix_full_length = 0;
 
-  if (argc > 1 && argv[1][0] == '-' && ISDIGIT (argv[1][1]))
+  if (argc > 1 && argv[1][0] == '-' && c_isdigit (argv[1][1]))
     {
       /* Old option syntax; a dash followed by one or more digits.  */
       max_width_option = argv[1] + 1;
@@ -351,7 +351,7 @@ main (int argc, char **argv)
     switch (optchar)
       {
       default:
-        if (ISDIGIT (optchar))
+        if (c_isdigit (optchar))
           error (0, 0, _("invalid option -- %c; -WIDTH is recognized\
  only when it is the first\noption; use -w N instead"),
                  optchar);
index cb418b4494dcddfff47027c1c0e3c9e2074d5fcc..710262ec902b5f22043f58c50723be225e47738d 100644 (file)
@@ -32,6 +32,7 @@
 #include "system.h"
 
 #include "assure.h"
+#include "c-ctype.h"
 #include "full-read.h"
 #include "safe-read.h"
 #include "stat-size.h"
@@ -944,7 +945,7 @@ main (int argc, char **argv)
 
   line_end = '\n';
 
-  if (1 < argc && argv[1][0] == '-' && ISDIGIT (argv[1][1]))
+  if (1 < argc && argv[1][0] == '-' && c_isdigit (argv[1][1]))
     {
       char *a = argv[1];
       char *n_string = ++a;
@@ -954,7 +955,7 @@ main (int argc, char **argv)
       /* Old option syntax; a dash, one or more digits, and one or
          more option letters.  Move past the number. */
       do ++a;
-      while (ISDIGIT (*a));
+      while (c_isdigit (*a));
 
       /* Pointer to the byte after the last digit.  */
       end_n_string = a;
@@ -1055,7 +1056,7 @@ main (int argc, char **argv)
         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
 
         default:
-          if (ISDIGIT (c))
+          if (c_isdigit (c))
             error (0, 0, _("invalid trailing option -- %c"), c);
           usage (EXIT_FAILURE);
         }
index 314855653ecb88ef8ccbad7ff98feabb58888d63..591371c192e52de3db0f544c08c623ff5d783b8d 100644 (file)
@@ -23,6 +23,7 @@
 #include <signal.h>
 
 #include "system.h"
+#include "c-ctype.h"
 #include "sig2str.h"
 #include "operand2sig.h"
 #include "quote.h"
@@ -154,7 +155,7 @@ list_signals (bool table, char *const *argv)
             signum = operand2sig (*argv);
             if (signum < 0)
               status = EXIT_FAILURE;
-            else if (ISDIGIT (**argv))
+            else if (c_isdigit (**argv))
               {
                 if (sig2str (signum, signame) == 0)
                   puts (signame);
index 4732fc861f795fb46e759322a8a34bccbb72b6b7..c9f389a6994305b5352dda7ec7a1f0e5cf3455b9 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -1366,7 +1366,7 @@ abmon_init (char abmon[12][ABFORMAT_SIZE])
       int fill = max_mon_width - mon_width[i];
       if (ABFORMAT_SIZE - mon_len[i] <= fill)
         return false;
-      bool align_left = !isdigit (to_uchar (abmon[i][0]));
+      bool align_left = !c_isdigit (abmon[i][0]);
       int fill_offset;
       if (align_left)
         fill_offset = mon_len[i];
index 58ab59fd312b0afc900f85d55c5c69c7dd2c4567..e935191be97379635ba16a940174724d12b3849b 100644 (file)
@@ -29,6 +29,7 @@
 # include <sys/resource.h>
 #endif
 
+#include "c-ctype.h"
 #include "quote.h"
 #include "xstrtol.h"
 
@@ -118,7 +119,7 @@ main (int argc, char **argv)
     {
       char const *s = argv[i];
 
-      if (s[0] == '-' && ISDIGIT (s[1 + (s[1] == '-' || s[1] == '+')]))
+      if (s[0] == '-' && c_isdigit (s[1 + (s[1] == '-' || s[1] == '+')]))
         {
           adjustment_given = s + 1;
           ++i;
index 37a934a78144fda2853cf39e351ee9cf7e19153f..45a425e1014618469d4e12b8e54d2fd3baa25e52 100644 (file)
--- a/src/od.c
+++ b/src/od.c
@@ -26,6 +26,7 @@
 #include "system.h"
 #include "argmatch.h"
 #include "assure.h"
+#include "c-ctype.h"
 #include "ftoastr.h"
 #include "quote.h"
 #include "stat-size.h"
@@ -632,7 +633,7 @@ simple_strtoi (char const *s, char const **p, int *val)
 {
   int sum;
 
-  for (sum = 0; ISDIGIT (*s); s++)
+  for (sum = 0; c_isdigit (*s); s++)
     if (ckd_mul (&sum, sum, 10) || ckd_add (&sum, sum, *s - '0'))
       return false;
   *p = s;
@@ -1888,7 +1889,7 @@ main (int argc, char **argv)
 
         case 2:
           if ((traditional || argv[optind + 1][0] == '+'
-               || ISDIGIT (argv[optind + 1][0]))
+               || c_isdigit (argv[optind + 1][0]))
               && parse_old_offset (argv[optind + 1], &o2))
             {
               if (traditional && parse_old_offset (argv[optind], &o1))
index b46cb1bede2cee8d66eb2bd17c253b3f5de8dbc8..fe87494443597b5e4094629213a8bd82a031e099 100644 (file)
@@ -27,6 +27,7 @@
 #include <sys/wait.h>
 
 #include "system.h"
+#include "c-ctype.h"
 #include "quote.h"
 #include "sig2str.h"
 #include "operand2sig.h"
@@ -36,7 +37,7 @@ operand2sig (char const *operand)
 {
   int signum;
 
-  if (ISDIGIT (*operand))
+  if (c_isdigit (*operand))
     {
       /* Note we don't put a limit on the maximum value passed,
          because we're checking shell $? values here, and ksh for
index a08da2fd75c6bc867c8e82b1c1d7a080df720121..eafab398b43c8bc10ec43799bc451d7d93b2ae60 100644 (file)
--- a/src/pr.c
+++ b/src/pr.c
 #include <getopt.h>
 #include <sys/types.h>
 #include "system.h"
+#include "c-ctype.h"
 #include "fadvise.h"
 #include "hard-locale.h"
 #include "mbswidth.h"
@@ -887,7 +888,7 @@ main (int argc, char **argv)
       if (c == -1)
         break;
 
-      if (ISDIGIT (c))
+      if (c_isdigit (c))
         {
           /* Accumulate column-count digits specified via old-style options. */
           if (n_digits + 1 >= n_alloc)
@@ -1175,7 +1176,7 @@ getoptarg (char *arg, char switch_char, char *character, int *number)
       usage (EXIT_FAILURE);
     }
 
-  if (!ISDIGIT (*arg))
+  if (!c_isdigit (*arg))
     *character = *arg++;
   if (*arg)
     {
index bb5a7c72310bf48e78e3d3ed120447a6b00df597..0d5921e75cf3eb79f95033cf1cc9d808b255e1d0 100644 (file)
@@ -612,7 +612,7 @@ print_formatted (char const *format, int argc, char **argv)
               have_field_width = true;
             }
           else
-            while (ISDIGIT (*ac.f))
+            while (c_isdigit (*ac.f))
               *pdirec++ = *ac.f++;
           if (*ac.f == '.')
             {
@@ -645,7 +645,7 @@ print_formatted (char const *format, int argc, char **argv)
                   have_precision = true;
                 }
               else
-                while (ISDIGIT (*ac.f))
+                while (c_isdigit (*ac.f))
                   *pdirec++ = *ac.f++;
             }
 
index 1b3be26baeb6c45095cdd0907b1062500ce8b2d8..63bdc5d943a36e10b2dd3376d4d7e33db5bb4046 100644 (file)
--- a/src/seq.c
+++ b/src/seq.c
@@ -23,6 +23,7 @@
 #include <sys/types.h>
 
 #include "system.h"
+#include "c-ctype.h"
 #include "cl-strtod.h"
 #include "full-write.h"
 #include "quote.h"
@@ -190,7 +191,7 @@ scan_arg (char const *arg)
           ret.width += (fraction_len == 0                      /* #.  -> #   */
                         ? -1
                         : (decimal_point == arg                /* .#  -> 0.# */
-                           || ! ISDIGIT (decimal_point[-1]))); /* -.# -> 0.# */
+                           || ! c_isdigit (decimal_point[-1]))); /* -.# -> 0.# */
         }
       char const *e = strchr (arg, 'e');
       if (! e)
@@ -539,7 +540,7 @@ static bool
 all_digits_p (char const *s)
 {
   size_t n = strlen (s);
-  return ISDIGIT (s[0]) && n == strspn (s, "0123456789");
+  return c_isdigit (s[0]) && n == strspn (s, "0123456789");
 }
 
 int
@@ -571,7 +572,7 @@ main (int argc, char **argv)
   while (optind < argc)
     {
       if (argv[optind][0] == '-'
-          && ((optc = argv[optind][1]) == '.' || ISDIGIT (optc)))
+          && ((optc = argv[optind][1]) == '.' || c_isdigit (optc)))
         {
           /* means negative number */
           break;
index 6102282eafba2c334e2b3ca3dc1899b9b0bf1002..06806b1565982e57219b176ca4a0513d315cd80a 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "system.h"
 #include <ctype.h>
+#include "c-ctype.h"
 #include "quote.h"
 #include "set-fields.h"
 
@@ -230,7 +231,7 @@ set_fields (char const *fieldstr, unsigned int options)
           lhs_specified = false;
           rhs_specified = false;
         }
-      else if (ISDIGIT (*fieldstr))
+      else if (c_isdigit (*fieldstr))
         {
           /* Record beginning of digit string, in case we have to
              complain about it.  */
index 7205007745041d27e9b501b669e4e543f4da9751..4f875b585c11b6b2349124dd58d15f5c1803aba2 100644 (file)
@@ -32,6 +32,7 @@
 #include "system.h"
 #include "argmatch.h"
 #include "assure.h"
+#include "c-ctype.h"
 #include "fadvise.h"
 #include "filevercmp.h"
 #include "flexmember.h"
@@ -1389,7 +1390,7 @@ specify_sort_size (int oi, char c, char const *s)
   enum strtol_error e = xstrtoumax (s, &suffix, 10, &n, "EgGkKmMPQRtTYZ");
 
   /* The default unit is KiB.  */
-  if (e == LONGINT_OK && ISDIGIT (suffix[-1]))
+  if (e == LONGINT_OK && c_isdigit (suffix[-1]))
     {
       if (n <= UINTMAX_MAX / 1024)
         n *= 1024;
@@ -1398,7 +1399,7 @@ specify_sort_size (int oi, char c, char const *s)
     }
 
   /* A 'b' suffix means bytes; a '%' suffix means percent of memory.  */
-  if (e == LONGINT_INVALID_SUFFIX_CHAR && ISDIGIT (suffix[-1]) && ! suffix[1])
+  if (e == LONGINT_INVALID_SUFFIX_CHAR && c_isdigit (suffix[-1]) && ! suffix[1])
     switch (suffix[0])
       {
       case 'b':
@@ -1921,7 +1922,7 @@ traverse_raw_number (char const **number)
      to be lacking in units.
      FIXME: add support for multibyte thousands_sep and decimal_point.  */
 
-  while (ISDIGIT (ch = *p++))
+  while (c_isdigit (ch = *p++))
     {
       if (max_digit < ch)
         max_digit = ch;
@@ -1942,7 +1943,7 @@ traverse_raw_number (char const **number)
     }
 
   if (ch == decimal_point)
-    while (ISDIGIT (ch = *p++))
+    while (c_isdigit (ch = *p++))
       if (max_digit < ch)
         max_digit = ch;
 
@@ -4476,7 +4477,7 @@ main (int argc, char **argv)
           if (optarg[0] == '+')
             {
               bool minus_pos_usage = (optind != argc && argv[optind][0] == '-'
-                                      && ISDIGIT (argv[optind][1]));
+                                      && c_isdigit (argv[optind][1]));
               traditional_usage |= minus_pos_usage && !posixly_correct;
               if (traditional_usage)
                 {
@@ -4701,7 +4702,7 @@ main (int argc, char **argv)
           if (optarg == argv[optind - 1])
             {
               char const *p;
-              for (p = optarg; ISDIGIT (*p); p++)
+              for (p = optarg; c_isdigit (*p); p++)
                 continue;
               optind -= (*p != '\0');
             }
index 264efc296f98e70f2dcc07f71e67b2db6950e985..faae92748012a37f5894005bc938701e29843dd4 100644 (file)
@@ -738,7 +738,7 @@ out_epoch_sec (char *pformat, size_t prefix_len,
       sec_prefix_len = dot - pformat;
       pformat[prefix_len] = '\0';
 
-      if (ISDIGIT (dot[1]))
+      if (c_isdigit (dot[1]))
         {
           long int lprec = strtol (dot + 1, nullptr, 10);
           precision = (lprec <= INT_MAX ? lprec : INT_MAX);
@@ -748,7 +748,7 @@ out_epoch_sec (char *pformat, size_t prefix_len,
           precision = 9;
         }
 
-      if (precision && ISDIGIT (dot[-1]))
+      if (precision && c_isdigit (dot[-1]))
         {
           /* If a nontrivial width is given, subtract the width of the
              decimal point and PRECISION digits that will be output
@@ -758,7 +758,7 @@ out_epoch_sec (char *pformat, size_t prefix_len,
 
           do
             --p;
-          while (ISDIGIT (p[-1]));
+          while (c_isdigit (p[-1]));
 
           long int lwidth = strtol (p, nullptr, 10);
           width = (lwidth <= INT_MAX ? lwidth : INT_MAX);
index ea30fb4b6ac59d7650b3ae078d7fb15c4f27422a..a95613b86d6f4ac4462804bf1a98d6ef57f09b52 100644 (file)
@@ -143,15 +143,6 @@ enum
 
 #include "timespec.h"
 
-/* ISDIGIT differs from isdigit, as follows:
-   - Its arg may be any int or unsigned int; it need not be an unsigned char
-     or EOF.
-   - It's typically faster.
-   POSIX says that only '0' through '9' are digits.  Prefer ISDIGIT to
-   isdigit unless it's important to use the locale's definition
-   of 'digit' even when the host does not conform to POSIX.  */
-#define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)
-
 /* Convert a possibly-signed character to an unsigned character.  This is
    a bit safer than casting to unsigned char, since it catches some type
    errors that the cast doesn't.  */
index 19f5725560c7d2e05d70cdcadca6d6f1aae90f37..99a23c96623fd9c348980cc4fdf90ded6ec70e03 100644 (file)
@@ -33,6 +33,7 @@
 #include "system.h"
 #include "argmatch.h"
 #include "assure.h"
+#include "c-ctype.h"
 #include "cl-strtod.h"
 #include "fcntl--.h"
 #include "iopoll.h"
@@ -2157,7 +2158,7 @@ parse_obsolete_option (int argc, char * const *argv, uintmax_t *n_units)
     }
 
   n_string = p;
-  while (ISDIGIT (*p))
+  while (c_isdigit (*p))
     p++;
   n_string_end = p;
 
index 7d3a78879231e4a8d5e4309ace3b81003afe1a9c..23e75b02e2c9c1e266f5a4b92ec840933d3a63a3 100644 (file)
@@ -40,6 +40,7 @@
 
 #include "system.h"
 #include "assure.h"
+#include "c-ctype.h"
 #include "quote.h"
 #include "stat-time.h"
 #include "strnumcmp.h"
@@ -143,9 +144,9 @@ find_int (char const *string)
       p += (*p == '-');
     }
 
-  if (ISDIGIT (*p++))
+  if (c_isdigit (*p++))
     {
-      while (ISDIGIT (*p))
+      while (c_isdigit (*p))
         p++;
       while (isspace (to_uchar (*p)))
         p++;
index 4201dd0aab614583a6b3847434d0c0a93d0cc759..2a7b7dfb613769ff29e54a1c5a23d662fc231fba 100644 (file)
--- a/src/tr.c
+++ b/src/tr.c
@@ -25,6 +25,7 @@
 
 #include "system.h"
 #include "assure.h"
+#include "c-ctype.h"
 #include "fadvise.h"
 #include "quote.h"
 #include "safe-read.h"
@@ -383,7 +384,7 @@ is_char_class_member (enum Char_class char_class, unsigned char c)
       result = iscntrl (c);
       break;
     case CC_DIGIT:
-      result = isdigit (c);
+      result = c_isdigit (c);
       break;
     case CC_GRAPH:
       result = isgraph (c);
@@ -404,7 +405,7 @@ is_char_class_member (enum Char_class char_class, unsigned char c)
       result = isupper (c);
       break;
     case CC_XDIGIT:
-      result = isxdigit (c);
+      result = c_isxdigit (c);
       break;
     default:
       unreachable ();
@@ -830,7 +831,7 @@ star_digits_closebracket (const struct E_string *es, size_t idx)
     return false;
 
   for (size_t i = idx + 1; i < es->len; i++)
-    if (!ISDIGIT (es->s[i]) || es->escaped[i])
+    if (!c_isdigit (es->s[i]) || es->escaped[i])
       return es_match (es, i, ']');
   return false;
 }