[PATCH v13 0/9] Support translated option names in getopt and argp

Vivien Kraus vivien@planete-kraus.eu
Tue Oct 7 18:13:24 GMT 2025


Dear glibc developers,

It looks like sending a new revision of the patch series is the best
way for me to communicate with you. So here is a V13 for communication
purposes.

Bruno,

Le 27/05/2025 à 22:29, Bruno Haible a écrit :
> It would be good to add pgettext() and friends to glibc. It's on my
> long-term TODO list to move their declarations to an LGPLed .h file.
> That .h file may be <libintl.h>, if it's done in sync with glibc.
> Otherwise, it would be called something like <libintlx.h> or
> <libintlx/context.h>.
>
> So, for the topic of getopt(), please do NOT assume that pgettext
> will never be in glibc. Instead, think about how the programmer could
> provide the 'context' argument that pgettext() needs, or whether this
> 'context' argument should be a fixed constant literal.

The only way I see to prepare such a future move would be to have
getopt receive the context argument and use it to translate option
names.  If it does not use it at first, then developers will have to
modify their programs later when it does.  So, I reimplemented
pgettext_expr in such a way that the future replacement discussed here
will not change anything from the developer’s point of view.

I tried not to look at the source code to write this function, but
unfortunately, I looked at the public header file
share/gettext/gettext.h for its interface, and it spoils the
implementation secret: paste the context, \004, and the message;
translate the concatenation, and if there is no translation, remove
the context.  Am I allowed to submit this code?  The translation must
work this way exactly, otherwise using pgettext later will break
translations.

Carlos,

Le 25/08/2025 à 16:35, Carlos O'Donell a écrit :
> Vivien,
>
> Thank you for working through the review comments.
>
> I have a high level question for you.
>
> The code in question is shared between gnulib and glibc (see the top-level
> SHARED-FILES in glibc).
>
> While the code hasn't been synchronized in a while, it is code that
> we would like to be able to share.
>
> Currently glibc accepts either DCO or copyright assignment.
>
> Currently gnulib accepts only code under copyright assignment to the FSF.
>
> Would you be interested in assigning copyright to the FSF so this
> code could be included in gnulib in the future?
>
> Please see the "Contribution Checklist" here:
> https://sourceware.org/glibc/wiki/Contribution%20checklist#Copyright_FSF_or_disclaimer

I replied on 2025-08-25, but I suspect you did not receive it, since
you later wrote:

Le 06/10/2025 à 15:27, Carlos O'Donell a écrit :
> Vivien,
>
> Thank you again for re-posting v12.
>
> I want to give you some concrete direction here.
>
> Firstly, I think that this is a valuable and useful change.
>
> However, to continue the review we do need to solve how you plan to
> contribute the changes.
>
> Firstly, some of the code which is just used by glibc can be contributed
> via DCO (without copyright assignment) or with Copyright assignment to
> the FSF.
>
> Some of the code is shared with gnulib and will need copyright assignment
> since gnulib requires this.
>
> Do you need any help with the next steps to clarify your contribution
> status with respect to copyright?

I replied on 2025-10-06, saying I would make a new revision in case
you did not receive it.  Since I don’t know, let me state things here
instead.

I would love to have this functionality into gnulib.  I love gnulib.
I would like to assign my copyright to the FSF.  I am the author of
these changes, with the caveat about the unclear status of my pgettext
emulation, discussed above.  I avoided the DCO, and added a copyright
FSF line on top of all my new files.

Best regards,

Vivien

Vivien Kraus (9):
  posix: allow getopt_long to match translated option names
  posix: let the getopt caller set the translation context
  argp: document translated names in --help and --usage
  posix: let the getopt caller choose the textdomain for translation
  posix: do not allow option name translations for secure programs
  posix, argp: Support deprecation of long option name translations
  argp: do not display option name translations if __libc_enable_secure
  posix: Add getopt_long_collision
  posix: Add a script for static validation of getopt_long PO files

 argp/Makefile                                 |  14 ++
 argp/argp-help.c                              |  83 +++++++-
 argp/argp-parse.c                             |   1 +
 argp/tst-argphelp-localized.c                 | 169 +++++++++++++++
 argp/tst-argphelp-localized.po                |  23 ++
 argp/tst-argpusage-localized.c                |  82 ++++++++
 manual/argp.texi                              |  25 ++-
 manual/getopt.texi                            |  81 ++++++-
 posix/Makefile                                |  40 ++++
 posix/Versions                                |   3 +
 posix/bits/getopt_ext.h                       |  17 ++
 posix/check-getopt-translations.pl            | 199 ++++++++++++++++++
 posix/getopt.c                                | 168 +++++++++++++--
 posix/getopt1.c                               | 102 ++++++++-
 posix/getopt_int.h                            |  14 +-
 .../standalone-multiple-getopt-collisions.po  |  45 ++++
 posix/tst-check-getopt-translations.sh        |  59 ++++++
 posix/tst-getopt_long_collision.c             |  83 ++++++++
 posix/tst-getopt_long_collision.po            |  22 ++
 posix/tstgetoptl.c                            | 144 +++++++++++++
 posix/tstgetoptl.po                           |  27 +++
 sysdeps/mach/hurd/i386/libc.abilist           |   3 +
 sysdeps/mach/hurd/x86_64/libc.abilist         |   3 +
 sysdeps/unix/sysv/linux/aarch64/libc.abilist  |   3 +
 sysdeps/unix/sysv/linux/alpha/libc.abilist    |   3 +
 sysdeps/unix/sysv/linux/arc/libc.abilist      |   3 +
 sysdeps/unix/sysv/linux/arm/be/libc.abilist   |   3 +
 sysdeps/unix/sysv/linux/arm/le/libc.abilist   |   3 +
 sysdeps/unix/sysv/linux/csky/libc.abilist     |   3 +
 sysdeps/unix/sysv/linux/hppa/libc.abilist     |   3 +
 sysdeps/unix/sysv/linux/i386/libc.abilist     |   3 +
 .../sysv/linux/loongarch/lp64/libc.abilist    |   3 +
 .../sysv/linux/m68k/coldfire/libc.abilist     |   3 +
 .../unix/sysv/linux/m68k/m680x0/libc.abilist  |   3 +
 .../sysv/linux/microblaze/be/libc.abilist     |   3 +
 .../sysv/linux/microblaze/le/libc.abilist     |   3 +
 .../sysv/linux/mips/mips32/fpu/libc.abilist   |   3 +
 .../sysv/linux/mips/mips32/nofpu/libc.abilist |   3 +
 .../sysv/linux/mips/mips64/n32/libc.abilist   |   3 +
 .../sysv/linux/mips/mips64/n64/libc.abilist   |   3 +
 sysdeps/unix/sysv/linux/or1k/libc.abilist     |   3 +
 .../linux/powerpc/powerpc32/fpu/libc.abilist  |   3 +
 .../powerpc/powerpc32/nofpu/libc.abilist      |   3 +
 .../linux/powerpc/powerpc64/be/libc.abilist   |   3 +
 .../linux/powerpc/powerpc64/le/libc.abilist   |   3 +
 .../unix/sysv/linux/riscv/rv32/libc.abilist   |   3 +
 .../unix/sysv/linux/riscv/rv64/libc.abilist   |   3 +
 .../unix/sysv/linux/s390/s390-32/libc.abilist |   3 +
 .../unix/sysv/linux/s390/s390-64/libc.abilist |   3 +
 sysdeps/unix/sysv/linux/sh/be/libc.abilist    |   3 +
 sysdeps/unix/sysv/linux/sh/le/libc.abilist    |   3 +
 .../sysv/linux/sparc/sparc32/libc.abilist     |   3 +
 .../sysv/linux/sparc/sparc64/libc.abilist     |   3 +
 .../unix/sysv/linux/x86_64/64/libc.abilist    |   3 +
 .../unix/sysv/linux/x86_64/x32/libc.abilist   |   3 +
 55 files changed, 1460 insertions(+), 43 deletions(-)
 create mode 100644 argp/tst-argphelp-localized.c
 create mode 100644 argp/tst-argphelp-localized.po
 create mode 100644 argp/tst-argpusage-localized.c
 create mode 100644 posix/check-getopt-translations.pl
 create mode 100644 posix/standalone-multiple-getopt-collisions.po
 create mode 100644 posix/tst-check-getopt-translations.sh
 create mode 100644 posix/tst-getopt_long_collision.c
 create mode 100644 posix/tst-getopt_long_collision.po
 create mode 100644 posix/tstgetoptl.c
 create mode 100644 posix/tstgetoptl.po


base-commit: 2ea943f7d487d6a4166658b32af7c5365889fc34
-- 
2.34.1



More information about the Libc-alpha mailing list