]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
c-format: Recognize the %b format directive.
authorBruno Haible <bruno@clisp.org>
Sun, 28 May 2023 10:56:43 +0000 (12:56 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 28 May 2023 13:37:45 +0000 (15:37 +0200)
* 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.

NEWS
gettext-tools/src/format-c-parse.h
gettext-tools/tests/format-c-1
gettext-tools/tests/format-c-2

diff --git a/NEWS b/NEWS
index 0332e52f1635769ff38c252aa80a983dc8ddeecb..7a1d08c173693e1c226c08d69d7322e81f27d43a 100644 (file)
--- 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.
 
index f6f5efdf9ec040d4c0c76a8667a057d7218c86b0..a53e61c49bd0217d0477d6e40f4894ad28a2aea8 100644 (file)
@@ -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 <haible@clisp.cons.org>, 2001.
 
    This program is free software: you can redistribute it and/or modify
    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
 
 
-/* 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;
index 83ba0ca74b0675f380e45ff8e442fe030d9c0534..677c4b5c3d9d45fe9233535a9f52215d99fbfe44 100755 (executable)
@@ -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
index 4883a27efef9d3a85042afc9fd0e3c45f8edccae..5f7a99c2a0d368acf34bc17aa94c963efbdab87e 100755 (executable)
@@ -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