From: Bruno Haible Date: Tue, 12 May 2026 00:16:25 +0000 (+0200) Subject: Use countof, part 3. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=474d099880bcfea1410bdd9b4bac2e2039b50a79;p=thirdparty%2Fgettext.git Use countof, part 3. * m4/more-warnings.m4 (gt_MORE_WARNINGS): Update comment. * gettext-tools/src/cldr-plural-exp.c: Include (SIZEOF): Remove macro. (cldr_plural_rule_list_print): Use countof instead of SIZEOF. * gettext-tools/src/format-kde-kuit.c: Include (SIZEOF): Remove macro. (is_reference): Use countof instead of SIZEOF. * gettext-tools/src/its.c: Include (SIZEOF): Remove macro. (_its_is_valid_simple_gen_xml, is_valid_xhtml_element, is_valid_html_element): Use countof instead of SIZEOF. * gettext-tools/src/msginit.c: Include (SIZEOF): Remove macro. (catalogname_for_locale, plural_forms, fill_header): Use countof instead of SIZEOF. * gettext-tools/src/msgl-check.c: Include (SIZEOF): Remove macro. (check_header_entry): Use countof instead of SIZEOF. * gettext-tools/src/msgl-header.c: Include (SIZEOF): Remove macro. (msgdomain_list_set_header_field): Use countof instead of SIZEOF. * gettext-tools/src/open-catalog.c: Include (SIZEOF): Remove macro. (try_open_catalog_file): Use countof instead of SIZEOF. * gettext-tools/src/po-charset.c: Include (SIZEOF): Remove macro. (po_charset_canonicalize, po_is_charset_weird, po_is_charset_weird_cjk): Use countof instead of SIZEOF. * gettext-tools/src/write-mo.c: Include (SIZEOF): Remove macro. (write_table): Use countof instead of SIZEOF. * gettext-tools/src/x-awk.c: Include (SIZEOF): Remove macro. (phase3_unget): Use countof instead of SIZEOF. * gettext-tools/src/x-c.c: Include (SIZEOF): Remove macro. (phase1_ungetc, phase2_ungetc, phase3_ungetc, phase5_unget, phase6_unget, x_c_unlex): Use countof instead of SIZEOF. * gettext-tools/src/x-csharp.c: Include (SIZEOF): Remove macro. (phase1_ungetc, phase2_ungetc, phase3_ungetc, phase5_ungetc, phase6_unget, phase7_unget): Use countof instead of SIZEOF. * gettext-tools/src/x-java.c: Include (SIZEOF): Remove macro. (phase1_ungetc, phase2_ungetc, phase3_ungetc, phase5_unget, phase6_unget): Use countof instead of SIZEOF. * gettext-tools/src/x-javascript.c: Include (SIZEOF): Remove macro. (phase1_ungetc, phase2_ungetc, phase5_scan_xml_markup, phase5_unget): Use countof instead of SIZEOF. * gettext-tools/src/x-lua.c: Include (SIZEOF): Remove macro. (phase1_ungetc, phase3_unget, phase4_unget): Use countof instead of SIZEOF. * gettext-tools/src/x-modula2.c: Include (SIZEOF): Remove macro. (phase2_ungetc, phase3_unget, phase4_unget): Use countof instead of SIZEOF. * gettext-tools/src/x-php.c: Include (SIZEOF): Remove macro. (phase1_ungetc, phase2_ungetc, phase3_ungetc, phase4_unget): Use countof instead of SIZEOF. * gettext-tools/src/x-python.c: Include (SIZEOF): Remove macro. (phase1_ungetc, phase2_ungetc, phase5_unget): Use countof instead of SIZEOF. * gettext-tools/src/x-scheme.c: Include (SIZEOF): Remove macro. (phase1_ungetc, read_object): Use countof instead of SIZEOF. * gettext-tools/src/x-sh.c: Include (SIZEOF): Remove macro. (phase1_ungetc, phase2_ungetc): Use countof instead of SIZEOF. * gettext-tools/src/x-smalltalk.c: Include (SIZEOF): Remove macro. (phase2_unget, phase3_unget, phase4_unget): Use countof instead of SIZEOF. * gettext-tools/src/x-tcl.c: Include (SIZEOF): Remove macro. (phase1_ungetc, phase2_ungetc): Use countof instead of SIZEOF. * gettext-tools/src/x-vala.c: Include (SIZEOF): Remove macro. (phase1_ungetc, phase3_unget, phase4_unget): Use countof instead of SIZEOF. * gettext-tools/src/x-ycp.c: Include (SIZEOF): Remove macro. (phase2_ungetc, phase5_unget, phase8_unget): Use countof instead of SIZEOF. * gettext-tools/src/xg-check.c: Include (SIZEOF): Remove macro. (string_has_url): Use countof instead of SIZEOF. * gettext-tools/src/xgettext.c (SIZEOF): Remove macro. --- diff --git a/gettext-tools/src/cldr-plural-exp.c b/gettext-tools/src/cldr-plural-exp.c index 3ac3046f1..961d2ee90 100644 --- a/gettext-tools/src/cldr-plural-exp.c +++ b/gettext-tools/src/cldr-plural-exp.c @@ -18,6 +18,7 @@ #include +#include #include #include #include @@ -551,8 +552,6 @@ static print_condition_function_ty print_condition_functions[] = print_condition_greater }; -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) - void cldr_plural_rule_list_print (struct cldr_plural_rule_list_ty *rules, FILE *fp) { @@ -641,7 +640,7 @@ cldr_plural_rule_list_print (struct cldr_plural_rule_list_ty *rules, FILE *fp) break; struct cldr_plural_condition_ty *condition = rules->items[i]->condition; - for (size_t j = 0; j < SIZEOF (print_condition_functions); j++) + for (size_t j = 0; j < countof (print_condition_functions); j++) if (print_condition_functions[j] (condition, fp)) return; } diff --git a/gettext-tools/src/format-kde-kuit.c b/gettext-tools/src/format-kde-kuit.c index b3980244b..d012dcf71 100644 --- a/gettext-tools/src/format-kde-kuit.c +++ b/gettext-tools/src/format-kde-kuit.c @@ -20,6 +20,7 @@ #include #include +#include #include #include "format.h" @@ -48,8 +49,6 @@ #define _(str) gettext (str) -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) - /* KUIT (KDE User Interface Text) is an XML-like markup which augments translatable strings with semantic information: @@ -153,7 +152,7 @@ is_reference (const char *input) /* EntityRef */ { bool isNameStartChar = false; - for (int i = 0; i < SIZEOF (name_chars1); i++) + for (int i = 0; i < countof (name_chars1); i++) if (name_chars1[i].start <= uc && uc <= name_chars1[i].end) { isNameStartChar = true; @@ -169,14 +168,14 @@ is_reference (const char *input) str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str); bool isNameChar = false; - for (int i = 0; i < SIZEOF (name_chars1); i++) + for (int i = 0; i < countof (name_chars1); i++) if (name_chars1[i].start <= uc && uc <= name_chars1[i].end) { isNameChar = true; break; } if (!isNameChar) - for (int i = 0; i < SIZEOF (name_chars2); i++) + for (int i = 0; i < countof (name_chars2); i++) if (name_chars2[i].start <= uc && uc <= name_chars2[i].end) { isNameChar = true; diff --git a/gettext-tools/src/its.c b/gettext-tools/src/its.c index bbd8c809d..24481a386 100644 --- a/gettext-tools/src/its.c +++ b/gettext-tools/src/its.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -53,8 +54,6 @@ #define _(str) gettext (str) -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) - /* The Internationalization Tag Set (ITS) 2.0 standard is available at: https://www.w3.org/TR/its20/ @@ -2257,7 +2256,7 @@ _its_is_valid_simple_gen_xml (const char *contents, /* Stack of open elements. */ string_desc_t open_elements[100]; size_t open_elements_count = 0; - const size_t open_elements_max = SIZEOF (open_elements); + const size_t open_elements_max = countof (open_elements); const char *p = contents; const char *curr_text_segment_start = p; @@ -2519,7 +2518,7 @@ _its_is_valid_simple_gen_xml (const char *contents, if (set_doc_encoding_utf8 (add_to_node->doc)) { uint8_t buf[6]; - int nbytes = u8_uctomb (buf, ucs, SIZEOF (buf)); + int nbytes = u8_uctomb (buf, ucs, countof (buf)); if (nbytes <= 0) abort (); xmlNodeSetContentLen (text_node, BAD_CAST buf, nbytes); @@ -2640,7 +2639,7 @@ is_valid_xhtml_element (string_desc_t tag) }; /* Use binary search. */ size_t lo = 0; - size_t hi = SIZEOF (allowed); + size_t hi = countof (allowed); while (lo < hi) { /* Invariant: @@ -2738,7 +2737,7 @@ is_valid_html_element (string_desc_t tag) }; /* Use binary search. */ size_t lo = 0; - size_t hi = SIZEOF (allowed); + size_t hi = countof (allowed); while (lo < hi) { /* Invariant: diff --git a/gettext-tools/src/msginit.c b/gettext-tools/src/msginit.c index 78c88e671..9a572b4b8 100644 --- a/gettext-tools/src/msginit.c +++ b/gettext-tools/src/msginit.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -95,8 +96,6 @@ # define F_OK 0 #endif -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) - extern const char * _nl_expand_alias (const char *name); /* Locale name. */ @@ -758,7 +757,7 @@ catalogname_for_locale (const char *locale) } /* If the territory is the language's principal territory, drop it. */ - for (size_t i = 0; i < SIZEOF (locales_with_principal_territory); i++) + for (size_t i = 0; i < countof (locales_with_principal_territory); i++) if (streq (locale, locales_with_principal_territory[i])) { const char *language_end = strchr (locale, '_'); @@ -1390,7 +1389,7 @@ plural_forms () dirs[0] = "common"; dirs[1] = "supplemental"; dirs[2] = "plurals.xml"; - for (size_t i = 0; i < SIZEOF (dirs); i++) + for (size_t i = 0; i < countof (dirs); i++) { char *dir = xconcatenated_filename (last_dir, dirs[i], NULL); free (last_dir); @@ -1791,13 +1790,13 @@ fill_header (msgdomain_list_ty *mdlp, bool fresh) if (fresh) { fields = fresh_fields; - nfields = SIZEOF (fresh_fields); + nfields = countof (fresh_fields); field_last_translator = FRESH_FIELDS_LAST_TRANSLATOR; } else { fields = update_fields; - nfields = SIZEOF (update_fields); + nfields = countof (update_fields); field_last_translator = UPDATE_FIELDS_LAST_TRANSLATOR; } @@ -1873,7 +1872,7 @@ fill_header (msgdomain_list_ty *mdlp, bool fresh) (time (&now), (localtime (&now))->tm_year + 1900)); } - subst_string_list (header_mp->comment, SIZEOF (subst), subst); + subst_string_list (header_mp->comment, countof (subst), subst); } /* Finally remove the fuzzy attribute. */ diff --git a/gettext-tools/src/msgl-check.c b/gettext-tools/src/msgl-check.c index 72bbda54a..196a04aba 100644 --- a/gettext-tools/src/msgl-check.c +++ b/gettext-tools/src/msgl-check.c @@ -22,6 +22,7 @@ #include "msgl-check.h" #include +#include #include #include #include @@ -41,8 +42,6 @@ #define _(str) gettext (str) -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) - /* Evaluates the plural formula for min <= n <= max and returns the estimated number of times the value j was assumed. */ @@ -723,7 +722,7 @@ check_header_entry (const message_ty *mp, const char *msgstr_string, "text/plain; charset=CHARSET", "ENCODING", "" }; - const size_t nfields = SIZEOF (required_fields); + const size_t nfields = countof (required_fields); /* FIXME: We could check if a required header field is missing and report it as error. However, it's could be too rigorous and break backward compatibility. */ diff --git a/gettext-tools/src/msgl-header.c b/gettext-tools/src/msgl-header.c index 3e9241dee..8c024bb47 100644 --- a/gettext-tools/src/msgl-header.c +++ b/gettext-tools/src/msgl-header.c @@ -22,12 +22,11 @@ /* Specification. */ #include "msgl-header.h" +#include #include #include "xalloc.h" -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) - void header_set_charset (message_ty *header_mp, const char *charsetstr, @@ -80,7 +79,7 @@ msgdomain_list_set_header_field (msgdomain_list_ty *mdlp, /* Search the field in known_fields[]. */ int field_index = -1; - for (size_t k = 0; k < SIZEOF (known_fields); k++) + for (size_t k = 0; k < countof (known_fields); k++) if (streq (known_fields[k].name, field)) { field_index = k; @@ -149,11 +148,11 @@ msgdomain_list_set_header_field (msgdomain_list_ty *mdlp, /* Test whether h starts with a field name whose index is > field_index. */ size_t k; - for (k = field_index + 1; k < SIZEOF (known_fields); k++) + for (k = field_index + 1; k < countof (known_fields); k++) if (strncmp (h, known_fields[k].name, known_fields[k].len) == 0) break; - if (k < SIZEOF (known_fields)) + if (k < countof (known_fields)) break; h = strchr (h, '\n'); if (h == NULL) diff --git a/gettext-tools/src/open-catalog.c b/gettext-tools/src/open-catalog.c index d6f114f53..59b89193b 100644 --- a/gettext-tools/src/open-catalog.c +++ b/gettext-tools/src/open-catalog.c @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -37,9 +38,6 @@ #define _(str) gettext (str) -/* This macro is used to determine the number of elements in an array. */ -#define SIZEOF(a) (sizeof(a)/sizeof(a[0])) - static FILE * try_open_catalog_file (const char *input_name, char **real_file_name_p) { @@ -59,7 +57,7 @@ try_open_catalog_file (const char *input_name, char **real_file_name_p) specified, the current directory is used. */ const char *dir; for (int j = 0; (dir = dir_list_nth (j)) != NULL; ++j) - for (size_t k = 0; k < SIZEOF (extension); ++k) + for (size_t k = 0; k < countof (extension); ++k) { char *file_name = xconcatenated_filename (dir, input_name, extension[k]); @@ -79,7 +77,7 @@ try_open_catalog_file (const char *input_name, char **real_file_name_p) { /* The name is not relative. Try the various extensions, but ignore the directory search list. */ - for (size_t k = 0; k < SIZEOF (extension); ++k) + for (size_t k = 0; k < countof (extension); ++k) { char *file_name = xconcatenated_filename ("", input_name, extension[k]); diff --git a/gettext-tools/src/po-charset.c b/gettext-tools/src/po-charset.c index b67f214a6..56bffcbd5 100644 --- a/gettext-tools/src/po-charset.c +++ b/gettext-tools/src/po-charset.c @@ -23,6 +23,7 @@ /* Specification. */ #include "po-charset.h" +#include #include #include "c-strcase.h" @@ -30,8 +31,6 @@ #define _(str) gettext (str) -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) - static const char ascii[] = "ASCII"; /* The canonicalized encoding name for ASCII. */ @@ -96,7 +95,7 @@ po_charset_canonicalize (const char *charset) utf8 }; - for (size_t i = 0; i < SIZEOF (standard_charsets); i++) + for (size_t i = 0; i < countof (standard_charsets); i++) if (c_strcasecmp (charset, standard_charsets[i]) == 0) return standard_charsets[i < 3 ? 0 : i < 27 ? ((i - 3) & ~1) + 3 : i]; return NULL; @@ -129,7 +128,7 @@ bool po_is_charset_weird (const char *canon_charset) "JOHAB" }; - for (size_t i = 0; i < SIZEOF (weird_charsets); i++) + for (size_t i = 0; i < countof (weird_charsets); i++) if (streq (canon_charset, weird_charsets[i])) return true; return false; @@ -151,7 +150,7 @@ bool po_is_charset_weird_cjk (const char *canon_charset) "JOHAB" /* 0x{00..7F}, 0x{84..F9}{31..FE} */ }; - for (size_t i = 0; i < SIZEOF (weird_cjk_charsets); i++) + for (size_t i = 0; i < countof (weird_cjk_charsets); i++) if (streq (canon_charset, weird_cjk_charsets[i])) return true; return false; diff --git a/gettext-tools/src/write-mo.c b/gettext-tools/src/write-mo.c index c7bd294bf..bd3105796 100644 --- a/gettext-tools/src/write-mo.c +++ b/gettext-tools/src/write-mo.c @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -68,8 +69,6 @@ # endif /* GNU CC2 */ #endif /* roundup */ -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) - /* True if no conversion to UTF-8 is desired. */ bool no_convert_to_utf8; @@ -573,7 +572,7 @@ write_table (FILE *output_file, message_list_ty *mlp) for (size_t ss = 0; ss < n_sysdep_strings; ss++) { - for (size_t u = 0; u < SIZEOF (useful_instantiation_rules); u++) + for (size_t u = 0; u < countof (useful_instantiation_rules); u++) { const struct sysdep_instantiation_rule *instrule = &useful_instantiation_rules[u]; diff --git a/gettext-tools/src/x-awk.c b/gettext-tools/src/x-awk.c index a63682b6e..8c1fa389b 100644 --- a/gettext-tools/src/x-awk.c +++ b/gettext-tools/src/x-awk.c @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -45,8 +46,6 @@ #define _(s) gettext(s) -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) - /* The awk syntax is defined in the gawk manual page and documentation. See also gawk/awkgram.y. */ @@ -642,7 +641,7 @@ phase3_unget (token_ty *tp) { if (tp->type != token_type_eof) { - if (phase3_pushback_length == SIZEOF (phase3_pushback)) + if (phase3_pushback_length == countof (phase3_pushback)) abort (); phase3_pushback[phase3_pushback_length++] = *tp; } diff --git a/gettext-tools/src/x-c.c b/gettext-tools/src/x-c.c index c0f4b5c9b..39e9bb059 100644 --- a/gettext-tools/src/x-c.c +++ b/gettext-tools/src/x-c.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -51,8 +52,6 @@ #define _(s) gettext(s) -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) - /* The ANSI C standard defines several phases of translation: @@ -689,7 +688,7 @@ phase1_ungetc (int c) FALLTHROUGH; default: - if (phase1_pushback_length == SIZEOF (phase1_pushback)) + if (phase1_pushback_length == countof (phase1_pushback)) abort (); phase1_pushback[phase1_pushback_length++] = c; break; @@ -758,7 +757,7 @@ phase2_ungetc (int c) { if (c != EOF) { - if (phase2_pushback_length == SIZEOF (phase2_pushback)) + if (phase2_pushback_length == countof (phase2_pushback)) abort (); phase2_pushback[phase2_pushback_length++] = c; } @@ -799,7 +798,7 @@ phase3_ungetc (int c) { if (c != EOF) { - if (phase3_pushback_length == SIZEOF (phase3_pushback)) + if (phase3_pushback_length == countof (phase3_pushback)) abort (); phase3_pushback[phase3_pushback_length++] = c; } @@ -1807,7 +1806,7 @@ phase5_unget (token_ty *tp) { if (tp->type != token_type_eof) { - if (phase5_pushback_length == SIZEOF (phase5_pushback)) + if (phase5_pushback_length == countof (phase5_pushback)) abort (); phase5_pushback[phase5_pushback_length++] = *tp; } @@ -1948,7 +1947,7 @@ phase6_unget (token_ty *tp) { if (tp->type != token_type_eof) { - if (phase6_pushback_length == SIZEOF (phase6_pushback)) + if (phase6_pushback_length == countof (phase6_pushback)) abort (); phase6_pushback[phase6_pushback_length++] = *tp; } @@ -2250,7 +2249,7 @@ x_c_unlex (xgettext_token_ty *tp) { if (tp->type != xgettext_token_type_eof) { - if (phase9_pushback_length == SIZEOF (phase9_pushback)) + if (phase9_pushback_length == countof (phase9_pushback)) abort (); phase9_pushback[phase9_pushback_length++] = *tp; } diff --git a/gettext-tools/src/x-csharp.c b/gettext-tools/src/x-csharp.c index 513e8f134..cab3977a2 100644 --- a/gettext-tools/src/x-csharp.c +++ b/gettext-tools/src/x-csharp.c @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -52,8 +53,6 @@ #define _(s) gettext(s) -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) - /* The C# syntax is defined in ECMA-334, second edition. Strings with embedded expressions are defined in @@ -177,7 +176,7 @@ phase1_ungetc (int c) { if (c == '\n') --line_number; - if (phase1_pushback_length == SIZEOF (phase1_pushback)) + if (phase1_pushback_length == countof (phase1_pushback)) abort (); phase1_pushback[phase1_pushback_length++] = c; } @@ -431,7 +430,7 @@ phase2_ungetc (int c) { if (c != UEOF) { - if (phase2_pushback_length == SIZEOF (phase2_pushback)) + if (phase2_pushback_length == countof (phase2_pushback)) abort (); phase2_pushback[phase2_pushback_length++] = c; } @@ -507,7 +506,7 @@ phase3_ungetc (int c) { if (c == UNL) --logical_line_number; - if (phase3_pushback_length == SIZEOF (phase3_pushback)) + if (phase3_pushback_length == countof (phase3_pushback)) abort (); phase3_pushback[phase3_pushback_length++] = c; } @@ -1226,7 +1225,7 @@ phase5_ungetc (int c) { if (c != UEOF) { - if (phase5_pushback_length == SIZEOF (phase5_pushback)) + if (phase5_pushback_length == countof (phase5_pushback)) abort (); phase5_pushback[phase5_pushback_length++] = c; } @@ -1771,7 +1770,7 @@ phase6_unget (token_ty *tp) { if (tp->type != token_type_eof) { - if (phase6_pushback_length == SIZEOF (phase6_pushback)) + if (phase6_pushback_length == countof (phase6_pushback)) abort (); phase6_pushback[phase6_pushback_length++] = *tp; } @@ -1841,7 +1840,7 @@ phase7_unget (token_ty *tp) { if (tp->type != token_type_eof) { - if (phase7_pushback_length == SIZEOF (phase7_pushback)) + if (phase7_pushback_length == countof (phase7_pushback)) abort (); phase7_pushback[phase7_pushback_length++] = *tp; } diff --git a/gettext-tools/src/x-java.c b/gettext-tools/src/x-java.c index d11cb44c0..cacdc9f6d 100644 --- a/gettext-tools/src/x-java.c +++ b/gettext-tools/src/x-java.c @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -51,8 +52,6 @@ #define _(s) gettext(s) -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) - /* The Java syntax is defined in the Java Language Specification @@ -218,14 +217,14 @@ phase1_ungetc (int c) phase1_pushback[phase1_pushback_length - 1]++; else { - if (phase1_pushback_length == SIZEOF (phase1_pushback)) + if (phase1_pushback_length == countof (phase1_pushback)) abort (); phase1_pushback[phase1_pushback_length++] = MULTIPLE_U (1); } } else { - if (phase1_pushback_length == SIZEOF (phase1_pushback)) + if (phase1_pushback_length == countof (phase1_pushback)) abort (); phase1_pushback[phase1_pushback_length++] = c; } @@ -323,7 +322,7 @@ phase2_ungetc (int c) { if (c != P2_EOF) { - if (phase2_pushback_length == SIZEOF (phase2_pushback)) + if (phase2_pushback_length == countof (phase2_pushback)) abort (); phase2_pushback[phase2_pushback_length++] = c; } @@ -392,7 +391,7 @@ phase3_ungetc (int c) { if (c == '\n') --line_number; - if (phase3_pushback_length == SIZEOF (phase3_pushback)) + if (phase3_pushback_length == countof (phase3_pushback)) abort (); phase3_pushback[phase3_pushback_length++] = c; } @@ -1525,7 +1524,7 @@ phase5_unget (token_ty *tp) { if (tp->type != token_type_eof) { - if (phase5_pushback_length == SIZEOF (phase5_pushback)) + if (phase5_pushback_length == countof (phase5_pushback)) abort (); phase5_pushback[phase5_pushback_length++] = *tp; } @@ -1600,7 +1599,7 @@ phase6_unget (token_ty *tp) { if (tp->type != token_type_eof) { - if (phase6_pushback_length == SIZEOF (phase6_pushback)) + if (phase6_pushback_length == countof (phase6_pushback)) abort (); phase6_pushback[phase6_pushback_length++] = *tp; } diff --git a/gettext-tools/src/x-javascript.c b/gettext-tools/src/x-javascript.c index 7c4726290..9e4e12479 100644 --- a/gettext-tools/src/x-javascript.c +++ b/gettext-tools/src/x-javascript.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -57,8 +58,6 @@ #define _(s) gettext(s) -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) - /* The JavaScript aka ECMA-Script syntax is defined in ECMA-262 specification: @@ -292,7 +291,7 @@ phase1_ungetc (int c) if (c == '\n') --line_number; - if (phase1_pushback_length == SIZEOF (phase1_pushback)) + if (phase1_pushback_length == countof (phase1_pushback)) abort (); phase1_pushback[phase1_pushback_length++] = c; } @@ -541,7 +540,7 @@ phase2_ungetc (int c) { if (c != UEOF) { - if (phase2_pushback_length == SIZEOF (phase2_pushback)) + if (phase2_pushback_length == countof (phase2_pushback)) abort (); phase2_pushback[phase2_pushback_length++] = c; } @@ -1211,7 +1210,7 @@ phase5_scan_xml_markup (token_ty *tp) { "?", "?" } }; - for (int i = 0; i < SIZEOF (markers); i++) + for (int i = 0; i < countof (markers); i++) { const char *start = markers[i].start; const char *end = markers[i].end; @@ -1220,7 +1219,7 @@ phase5_scan_xml_markup (token_ty *tp) /* Look for a start marker. */ for (j = 0; start[j] != '\0'; j++) { - assert (phase2_pushback_length + j < SIZEOF (phase2_pushback)); + assert (phase2_pushback_length + j < countof (phase2_pushback)); int c = phase2_getc (); if (c == UEOF) goto eof; @@ -1243,7 +1242,7 @@ phase5_scan_xml_markup (token_ty *tp) { for (j = 0; end[j] != '\0'; j++) { - assert (phase2_pushback_length + 1 < SIZEOF (phase2_pushback)); + assert (phase2_pushback_length + 1 < countof (phase2_pushback)); int c = phase2_getc (); if (c == UEOF) goto eof; @@ -1702,7 +1701,7 @@ phase5_unget (token_ty *tp) { if (tp->type != token_type_eof) { - if (phase5_pushback_length == SIZEOF (phase5_pushback)) + if (phase5_pushback_length == countof (phase5_pushback)) abort (); phase5_pushback[phase5_pushback_length++] = *tp; } diff --git a/gettext-tools/src/x-lua.c b/gettext-tools/src/x-lua.c index 61b54f681..166d86f4b 100644 --- a/gettext-tools/src/x-lua.c +++ b/gettext-tools/src/x-lua.c @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -47,8 +48,6 @@ #define _(s) gettext(s) -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) - /* The Lua syntax is defined in the Lua manual sections 3.1 and 9, which can be found at https://www.lua.org/manual/5.2/manual.html#3.1 @@ -192,7 +191,7 @@ phase1_ungetc (int c) if (c == '\n') --line_number; - if (phase1_pushback_length == SIZEOF (phase1_pushback)) + if (phase1_pushback_length == countof (phase1_pushback)) abort (); phase1_pushback[phase1_pushback_length++] = c; } @@ -435,7 +434,7 @@ phase3_unget (token_ty *tp) { if (tp->type != token_type_eof) { - if (phase3_pushback_length == SIZEOF (phase3_pushback)) + if (phase3_pushback_length == countof (phase3_pushback)) abort (); phase3_pushback[phase3_pushback_length++] = *tp; } @@ -858,7 +857,7 @@ phase4_unget (token_ty *tp) { if (tp->type != token_type_eof) { - if (phase4_pushback_length == SIZEOF (phase4_pushback)) + if (phase4_pushback_length == countof (phase4_pushback)) abort (); phase4_pushback[phase4_pushback_length++] = *tp; } diff --git a/gettext-tools/src/x-modula2.c b/gettext-tools/src/x-modula2.c index 02b3e12d8..0cb96ac2b 100644 --- a/gettext-tools/src/x-modula2.c +++ b/gettext-tools/src/x-modula2.c @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -44,8 +45,6 @@ #define _(s) gettext(s) -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) - /* The Modula-2 syntax is defined in the book "The Programming Language Modula-2" by Niklaus Wirth @@ -275,7 +274,7 @@ phase2_ungetc (int c) { if (c != EOF) { - if (phase2_pushback_length == SIZEOF (phase2_pushback)) + if (phase2_pushback_length == countof (phase2_pushback)) abort (); phase2_pushback[phase2_pushback_length++] = c; } @@ -495,7 +494,7 @@ phase3_unget (token_ty *tp) { if (tp->type != token_type_eof) { - if (phase3_pushback_length == SIZEOF (phase3_pushback)) + if (phase3_pushback_length == countof (phase3_pushback)) abort (); phase3_pushback[phase3_pushback_length++] = *tp; } @@ -569,7 +568,7 @@ phase4_unget (token_ty *tp) { if (tp->type != token_type_eof) { - if (phase4_pushback_length == SIZEOF (phase4_pushback)) + if (phase4_pushback_length == countof (phase4_pushback)) abort (); phase4_pushback[phase4_pushback_length++] = *tp; } diff --git a/gettext-tools/src/x-php.c b/gettext-tools/src/x-php.c index 497544afd..0220b16bf 100644 --- a/gettext-tools/src/x-php.c +++ b/gettext-tools/src/x-php.c @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -46,8 +47,6 @@ #define _(s) gettext(s) -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) - /* The PHP syntax is defined in phpdoc/manual/langref.html. See also php-8.1.0/Zend/zend_language_scanner.l @@ -286,7 +285,7 @@ phase1_ungetc (struct php_extractor *xp, int c) if (c == '\n') --(xp->line_number); - if (xp->phase1_pushback_length == SIZEOF (xp->phase1_pushback)) + if (xp->phase1_pushback_length == countof (xp->phase1_pushback)) abort (); xp->phase1_pushback[xp->phase1_pushback_length++] = c; } @@ -610,7 +609,7 @@ phase2_ungetc (struct php_extractor *xp, int c) { if (c != EOF) { - if (xp->phase2_pushback_length == SIZEOF (xp->phase2_pushback)) + if (xp->phase2_pushback_length == countof (xp->phase2_pushback)) abort (); xp->phase2_pushback[xp->phase2_pushback_length++] = c; } @@ -793,7 +792,7 @@ phase3_ungetc (struct php_extractor *xp, int c) { if (c != EOF) { - if (xp->phase3_pushback_length == SIZEOF (xp->phase3_pushback)) + if (xp->phase3_pushback_length == countof (xp->phase3_pushback)) abort (); xp->phase3_pushback[xp->phase3_pushback_length++] = c; } @@ -1548,7 +1547,7 @@ phase4_unget (struct php_extractor *xp, token_ty *tp) { if (tp->type != token_type_eof) { - if (xp->phase4_pushback_length == SIZEOF (xp->phase4_pushback)) + if (xp->phase4_pushback_length == countof (xp->phase4_pushback)) abort (); xp->phase4_pushback[xp->phase4_pushback_length++] = *tp; } diff --git a/gettext-tools/src/x-python.c b/gettext-tools/src/x-python.c index 92615209d..72baf97c7 100644 --- a/gettext-tools/src/x-python.c +++ b/gettext-tools/src/x-python.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -61,8 +62,6 @@ #undef max /* clean up after MSVC's */ #define max(a,b) ((a) > (b) ? (a) : (b)) -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) - /* The Python syntax is defined in the Python Reference Manual /usr/share/doc/packages/python/html/ref/index.html. @@ -236,7 +235,7 @@ phase1_ungetc (int c) if (c == '\n') --line_number; - if (phase1_pushback_length == SIZEOF (phase1_pushback)) + if (phase1_pushback_length == countof (phase1_pushback)) abort (); phase1_pushback[phase1_pushback_length++] = c; } @@ -520,7 +519,7 @@ phase2_ungetc (int c) { if (c != UEOF) { - if (phase2_pushback_length == SIZEOF (phase2_pushback)) + if (phase2_pushback_length == countof (phase2_pushback)) abort (); phase2_pushback[phase2_pushback_length++] = c; } @@ -1603,7 +1602,7 @@ phase5_unget (token_ty *tp) { if (tp->type != token_type_eof) { - if (phase5_pushback_length == SIZEOF (phase5_pushback)) + if (phase5_pushback_length == countof (phase5_pushback)) abort (); phase5_pushback[phase5_pushback_length++] = *tp; } diff --git a/gettext-tools/src/x-scheme.c b/gettext-tools/src/x-scheme.c index 6b7a50b9f..a104fc464 100644 --- a/gettext-tools/src/x-scheme.c +++ b/gettext-tools/src/x-scheme.c @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -46,8 +47,6 @@ #define _(s) gettext(s) -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) - /* The Scheme syntax is described in R5RS and following standards: - R5RS: https://conservatory.scheme.org/schemers/Documents/Standards/R5RS/HTML/ @@ -232,7 +231,7 @@ phase1_ungetc (int c) if (c == '\n') --line_number; - if (phase1_pushback_length == SIZEOF (phase1_pushback)) + if (phase1_pushback_length == countof (phase1_pushback)) abort (); phase1_pushback[phase1_pushback_length++] = c; } @@ -1408,7 +1407,7 @@ read_object (struct object *op, flag_region_ty *outer_region) "curly-infix", "curly-infix-and-bracket-lists" }; - int num_directives = SIZEOF (directives); + int num_directives = countof (directives); enum { max_directive_len = 29 }; bool seen_directive = false; for (int d = 0; d < num_directives; d++) diff --git a/gettext-tools/src/x-sh.c b/gettext-tools/src/x-sh.c index 80c22a130..d20de84a1 100644 --- a/gettext-tools/src/x-sh.c +++ b/gettext-tools/src/x-sh.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -46,8 +47,6 @@ #define _(s) gettext(s) -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) - /* The sh syntax is defined in POSIX:2001, see http://www.opengroup.org/onlinepubs/007904975/utilities/xcu_chap02.html @@ -233,7 +232,7 @@ phase1_ungetc (int c) FALLTHROUGH; default: - if (phase1_pushback_length == SIZEOF (phase1_pushback)) + if (phase1_pushback_length == countof (phase1_pushback)) abort (); phase1_pushback[phase1_pushback_length++] = c; break; @@ -643,7 +642,7 @@ phase2_ungetc (int c) FALLTHROUGH; default: - if (phase2_pushback_length == SIZEOF (phase2_pushback)) + if (phase2_pushback_length == countof (phase2_pushback)) abort (); phase2_pushback[phase2_pushback_length++] = c; break; diff --git a/gettext-tools/src/x-smalltalk.c b/gettext-tools/src/x-smalltalk.c index 4f5520060..352175f14 100644 --- a/gettext-tools/src/x-smalltalk.c +++ b/gettext-tools/src/x-smalltalk.c @@ -22,6 +22,7 @@ #include "x-smalltalk.h" #include +#include #include #include #include @@ -39,8 +40,6 @@ #define _(s) gettext(s) -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) - /* The relevant parts of the Smalltalk syntax are: @@ -428,7 +427,7 @@ phase2_unget (token_ty *tp) { if (tp->type != token_type_eof) { - if (phase2_pushback_length == SIZEOF (phase2_pushback)) + if (phase2_pushback_length == countof (phase2_pushback)) abort (); phase2_pushback[phase2_pushback_length++] = *tp; } @@ -475,7 +474,7 @@ phase3_unget (token_ty *tp) { if (tp->type != token_type_eof) { - if (phase3_pushback_length == SIZEOF (phase3_pushback)) + if (phase3_pushback_length == countof (phase3_pushback)) abort (); phase3_pushback[phase3_pushback_length++] = *tp; } @@ -550,7 +549,7 @@ phase4_unget (token_ty *tp) { if (tp->type != token_type_eof) { - if (phase4_pushback_length == SIZEOF (phase4_pushback)) + if (phase4_pushback_length == countof (phase4_pushback)) abort (); phase4_pushback[phase4_pushback_length++] = *tp; } diff --git a/gettext-tools/src/x-tcl.c b/gettext-tools/src/x-tcl.c index 4e3be4c9e..e56697830 100644 --- a/gettext-tools/src/x-tcl.c +++ b/gettext-tools/src/x-tcl.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -50,8 +51,6 @@ #define _(s) gettext(s) -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) - /* The Tcl syntax is defined in the Tcl.n manual page, see https://www.tcl-lang.org/man/tcl8.6/TclCmd/Tcl.htm . @@ -225,7 +224,7 @@ phase1_ungetc (int c) FALLTHROUGH; default: - if (phase1_pushback_length == SIZEOF (phase1_pushback)) + if (phase1_pushback_length == countof (phase1_pushback)) abort (); phase1_pushback[phase1_pushback_length++] = c; break; @@ -311,7 +310,7 @@ phase2_ungetc (int c) ++brace_depth; break; } - if (phase2_pushback_length == SIZEOF (phase2_pushback)) + if (phase2_pushback_length == countof (phase2_pushback)) abort (); phase2_pushback[phase2_pushback_length++] = c; } diff --git a/gettext-tools/src/x-vala.c b/gettext-tools/src/x-vala.c index b3905e396..3dc9338ae 100644 --- a/gettext-tools/src/x-vala.c +++ b/gettext-tools/src/x-vala.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -51,8 +52,6 @@ #define _(s) gettext(s) -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) - /* The Vala syntax is defined in the Vala Reference Manual https://gnome.pages.gitlab.gnome.org/vala/manual/index.html. See also vala/valascanner.vala. @@ -244,7 +243,7 @@ phase1_ungetc (int c) if (c == '\n') --line_number; - if (phase1_pushback_length == SIZEOF (phase1_pushback)) + if (phase1_pushback_length == countof (phase1_pushback)) abort (); phase1_pushback[phase1_pushback_length++] = c; } @@ -1232,7 +1231,7 @@ phase3_unget (token_ty *tp) { if (tp->type != token_type_eof) { - if (phase3_pushback_length == SIZEOF (phase3_pushback)) + if (phase3_pushback_length == countof (phase3_pushback)) abort (); phase3_pushback[phase3_pushback_length++] = *tp; } @@ -1290,7 +1289,7 @@ phase4_unget (token_ty *tp) { if (tp->type != token_type_eof) { - if (phase4_pushback_length == SIZEOF (phase4_pushback)) + if (phase4_pushback_length == countof (phase4_pushback)) abort (); phase4_pushback[phase4_pushback_length++] = *tp; } diff --git a/gettext-tools/src/x-ycp.c b/gettext-tools/src/x-ycp.c index 96a0cc0cf..f916b7592 100644 --- a/gettext-tools/src/x-ycp.c +++ b/gettext-tools/src/x-ycp.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -43,8 +44,6 @@ #define _(s) gettext(s) -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) - /* The YCP syntax is defined in libycp/doc/syntax.html. See also libycp/src/scanner.ll. @@ -274,7 +273,7 @@ phase2_ungetc (int c) { if (c != EOF) { - if (phase2_pushback_length == SIZEOF (phase2_pushback)) + if (phase2_pushback_length == countof (phase2_pushback)) abort (); phase2_pushback[phase2_pushback_length++] = c; } @@ -533,7 +532,7 @@ phase5_unget (token_ty *tp) { if (tp->type != token_type_eof) { - if (phase5_pushback_length == SIZEOF (phase5_pushback)) + if (phase5_pushback_length == countof (phase5_pushback)) abort (); phase5_pushback[phase5_pushback_length++] = *tp; } @@ -581,7 +580,7 @@ phase8_unget (token_ty *tp) { if (tp->type != token_type_eof) { - if (phase8_pushback_length == SIZEOF (phase8_pushback)) + if (phase8_pushback_length == countof (phase8_pushback)) abort (); phase8_pushback[phase8_pushback_length++] = *tp; } diff --git a/gettext-tools/src/xg-check.c b/gettext-tools/src/xg-check.c index 0da4203f2..ba6a97f00 100644 --- a/gettext-tools/src/xg-check.c +++ b/gettext-tools/src/xg-check.c @@ -21,6 +21,7 @@ /* Specification. */ #include "xg-check.h" +#include #include #include @@ -40,8 +41,6 @@ #define _(str) gettext (str) -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) - /* Function that implements a single syntax check. MP is a message. @@ -372,7 +371,7 @@ string_has_url (const char *string) "irc://", "ircs://" }; - for (size_t i = 0; i < SIZEOF (patterns); i++) + for (size_t i = 0; i < countof (patterns); i++) { const char *pattern = patterns[i]; /* msgid and msgid_plural are typically entirely ASCII. Therefore here diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c index b9aeec3c1..02aea45fa 100644 --- a/gettext-tools/src/xgettext.c +++ b/gettext-tools/src/xgettext.c @@ -140,8 +140,7 @@ #include "x-appdata.h" -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) -#define ENDOF(a) ((a) + SIZEOF(a)) +#define ENDOF(a) ((a) + countof (a)) /* If true, add all comments immediately preceding one of the keywords. */ diff --git a/m4/more-warnings.m4 b/m4/more-warnings.m4 index f239a96d5..e0ba29b9b 100644 --- a/m4/more-warnings.m4 +++ b/m4/more-warnings.m4 @@ -1,5 +1,5 @@ # more-warnings.m4 -# serial 6 (gettext-1.1) +# serial 7 (gettext-1.1) dnl Copyright (C) 2023-2026 Free Software Foundation, Inc. dnl This file is free software, distributed under the terms of the GNU dnl General Public License. As a special exception to the GNU General @@ -87,7 +87,7 @@ AS_HELP_STRING([[--disable-more-warnings]], [obey exactly the warning options sp dnl are worth eliminating; see below. nw="$nw -Wshadow" dnl Too many warnings. We often use signed types like 'int' or 'idx_t' - dnl for counter variables, yet SIZEOF(array) is an unsigned value. + dnl for counter variables, yet countof(array) is an unsigned value. nw="$nw -Wsign-compare" dnl This warning is based on older ISO C standards. It warns, in particular, dnl about function definitions that are valid in ISO C 23 (static and