From: Paul Eggert Date: Mon, 30 Dec 2024 18:45:54 +0000 (-0800) Subject: maint: ISDIGIT → c_isdigit X-Git-Tag: v9.6~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9eb131e53029a648b549f507cac47f4769031073;p=thirdparty%2Fcoreutils.git maint: ISDIGIT → c_isdigit * 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. --- diff --git a/gl/lib/strnumcmp-in.h b/gl/lib/strnumcmp-in.h index 4662bbeec4..7b02145dfa 100644 --- a/gl/lib/strnumcmp-in.h +++ b/gl/lib/strnumcmp-in.h @@ -22,21 +22,12 @@ # include "strnumcmp.h" +# include "c-ctype.h" # include # 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); diff --git a/gl/modules/strnumcmp b/gl/modules/strnumcmp index 83f4e7c388..f36da19d0a 100644 --- a/gl/modules/strnumcmp +++ b/gl/modules/strnumcmp @@ -8,6 +8,7 @@ lib/strnumcmp.h lib/strnumcmp-in.h Depends-on: +c-ctype inline stddef diff --git a/src/csplit.c b/src/csplit.c index babb73949d..e6455f00ce 100644 --- a/src/csplit.c +++ b/src/csplit.c @@ -28,6 +28,7 @@ #include +#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); } diff --git a/src/expand-common.c b/src/expand-common.c index e3f9ea84ec..2fa0e89106 100644 --- a/src/expand-common.c +++ b/src/expand-common.c @@ -20,6 +20,7 @@ #include #include #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) { diff --git a/src/expr.c b/src/expr.c index 3ecec07350..5a680d2ec2 100644 --- a/src/expr.c +++ b/src/expr.c @@ -35,6 +35,7 @@ #include #include +#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); diff --git a/src/factor.c b/src/factor.c index 85cd1b1c90..04aa8806e7 100644 --- a/src/factor.c +++ b/src/factor.c @@ -109,6 +109,7 @@ #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; diff --git a/src/fmt.c b/src/fmt.c index 59086f35e0..122debc9d3 100644 --- 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); diff --git a/src/head.c b/src/head.c index cb418b4494..710262ec90 100644 --- a/src/head.c +++ b/src/head.c @@ -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); } diff --git a/src/kill.c b/src/kill.c index 314855653e..591371c192 100644 --- a/src/kill.c +++ b/src/kill.c @@ -23,6 +23,7 @@ #include #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); diff --git a/src/ls.c b/src/ls.c index 4732fc861f..c9f389a699 100644 --- 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]; diff --git a/src/nice.c b/src/nice.c index 58ab59fd31..e935191be9 100644 --- a/src/nice.c +++ b/src/nice.c @@ -29,6 +29,7 @@ # include #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; diff --git a/src/od.c b/src/od.c index 37a934a781..45a425e101 100644 --- 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)) diff --git a/src/operand2sig.c b/src/operand2sig.c index b46cb1bede..fe87494443 100644 --- a/src/operand2sig.c +++ b/src/operand2sig.c @@ -27,6 +27,7 @@ #include #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 diff --git a/src/pr.c b/src/pr.c index a08da2fd75..eafab398b4 100644 --- a/src/pr.c +++ b/src/pr.c @@ -313,6 +313,7 @@ #include #include #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) { diff --git a/src/printf.c b/src/printf.c index bb5a7c7231..0d5921e75c 100644 --- a/src/printf.c +++ b/src/printf.c @@ -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++; } diff --git a/src/seq.c b/src/seq.c index 1b3be26bae..63bdc5d943 100644 --- a/src/seq.c +++ b/src/seq.c @@ -23,6 +23,7 @@ #include #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; diff --git a/src/set-fields.c b/src/set-fields.c index 6102282eaf..06806b1565 100644 --- a/src/set-fields.c +++ b/src/set-fields.c @@ -20,6 +20,7 @@ #include "system.h" #include +#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. */ diff --git a/src/sort.c b/src/sort.c index 7205007745..4f875b585c 100644 --- a/src/sort.c +++ b/src/sort.c @@ -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'); } diff --git a/src/stat.c b/src/stat.c index 264efc296f..faae927480 100644 --- a/src/stat.c +++ b/src/stat.c @@ -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); diff --git a/src/system.h b/src/system.h index ea30fb4b6a..a95613b86d 100644 --- a/src/system.h +++ b/src/system.h @@ -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. */ diff --git a/src/tail.c b/src/tail.c index 19f5725560..99a23c9662 100644 --- a/src/tail.c +++ b/src/tail.c @@ -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; diff --git a/src/test.c b/src/test.c index 7d3a788792..23e75b02e2 100644 --- a/src/test.c +++ b/src/test.c @@ -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++; diff --git a/src/tr.c b/src/tr.c index 4201dd0aab..2a7b7dfb61 100644 --- 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; }