From: Bruno Haible Date: Sun, 28 May 2023 10:56:43 +0000 (+0200) Subject: c-format: Recognize the %b format directive. X-Git-Tag: v0.22~75 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=278e90f2ba97ca2ae888dd84d032dcfa87306591;p=thirdparty%2Fgettext.git c-format: Recognize the %b format directive. * gettext-tools/src/format-c-parse.h (format_parse_entrails): Recognize %b as a directive that takes an unsigned integer argument. * gettext-tools/tests/format-c-1: Add test of %b. * gettext-tools/tests/format-c-2: Add type compatibility test for %b. * NEWS: Mention it. --- diff --git a/NEWS b/NEWS index 0332e52f1..7a1d08c17 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,8 @@ Version 0.21.2 - May 2023 as arguments. o xgettext now recognizes numbers with digit separators, as defined by ISO C 23, as tokens. + o xgettext and msgfmt now recognize the format string directive %b + (for binary integer output, as defined by ISO C 23) in format strings. - Tcl: xgettext now supports the \x, \u, and \U escapes as defined in Tcl 8.6. diff --git a/gettext-tools/src/format-c-parse.h b/gettext-tools/src/format-c-parse.h index f6f5efdf9..a53e61c49 100644 --- a/gettext-tools/src/format-c-parse.h +++ b/gettext-tools/src/format-c-parse.h @@ -1,5 +1,5 @@ /* Parsing C format strings. - Copyright (C) 2001-2004, 2006-2007, 2009-2010, 2018, 2020, 2022 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2006-2007, 2009-2010, 2018, 2020, 2022-2023 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify @@ -16,8 +16,10 @@ along with this program. If not, see . */ -/* C format strings are described in POSIX (IEEE P1003.1 2001), section - XSH 3 fprintf(). See also Linux fprintf(3) manual page. +/* C format strings are described in + * POSIX (IEEE P1003.1 2001), section XSH 3 fprintf(). + * ISO C 23, section 7.23.6.1 fprintf and section 7.31.2.1 fwprintf. + * See also Linux fprintf(3) manual page. A directive - starts with '%' or '%m$' where m is a positive integer, - is optionally followed by any of the characters '#', '0', '-', ' ', '+', @@ -35,7 +37,7 @@ - 'c', 'C', that need a character argument, - 's', 'S', that need a string argument, - 'i', 'd', that need a signed integer argument, - - 'o', 'u', 'x', 'X', that need an unsigned integer argument, + - 'u', 'o', 'x', 'X', 'b', that need an unsigned integer argument, - 'e', 'E', 'f', 'F', 'g', 'G', 'a', 'A', that need a floating-point argument, - 'p', that needs a 'void *' argument, @@ -676,7 +678,7 @@ format_parse_entrails (const char *format, bool translated, type = FAT_INTEGER; type |= (size & FAT_SIZE_MASK); break; - case 'u': case 'o': case 'x': case 'X': + case 'u': case 'o': case 'x': case 'X': case 'b': type = FAT_INTEGER | FAT_UNSIGNED; type |= (size & FAT_SIZE_MASK); break; diff --git a/gettext-tools/tests/format-c-1 b/gettext-tools/tests/format-c-1 index 83ba0ca74..677c4b5c3 100755 --- a/gettext-tools/tests/format-c-1 +++ b/gettext-tools/tests/format-c-1 @@ -22,6 +22,8 @@ cat <<\EOF > f-c-1.data "abc%x" # Valid: one integer argument "abc%X" +# Valid: one integer argument +"abc%b" # Valid: one floating-point argument "abc%e" # Valid: one floating-point argument diff --git a/gettext-tools/tests/format-c-2 b/gettext-tools/tests/format-c-2 index 4883a27ef..5f7a99c2a 100755 --- a/gettext-tools/tests/format-c-2 +++ b/gettext-tools/tests/format-c-2 @@ -56,6 +56,9 @@ msgstr "xyz%x" msgid "abc%u" msgstr "xyz%X" # Valid: type compatibility +msgid "abc%u" +msgstr "xyz%b" +# Valid: type compatibility msgid "abc%e" msgstr "xyz%E" # Valid: type compatibility