[PATCH v5 0/4] Support translated long option names in getopt and argp

Vivien Kraus vivien@planete-kraus.eu
Wed Jun 4 22:06:14 GMT 2025


Hello Florian,

Thank you for your feedback.  Since I already had a few failing tests
before my modifications, I ignored anything that did not seem
relevant.

Le mercredi 04 juin 2025 à 10:37 +0200, Florian Weimer a écrit :
> * Vivien Kraus:
> 
> > It is possible to support translated long option names in a program
> > by
> > adding new option records with the translated names in the options
> > array. However, it is significant work for all packages.
> > 
> > The discussion was started on bug-standards and support in glibc
> > may
> > be desirable [1].
> > 
> > With this change, getopt will try and match the untranslated
> > options
> > names, then the translated option names if not found. 
> > Abbreviations
> > will only match the untranslated names.
> > 
> > [1]:
> > https://lists.gnu.org/archive/html/bug-standards/2025-05/msg00000.html
> 
> I don't think this is a good idea.  It can make cross-cultural
> collaboration more difficult.  Office applications (particularly
> spreadsheets) already use translated names for their programming
> languages.  It makes it more difficult to find appropriate guides and
> apply them to your own environment.  The proposed approach for
> getopt_long mitigates some of the problems because the untranslated
> option names always work, but there will be considerable friction
> once
> this feature gets significant traction.

Would this concern be blocking?  If so, the remaining problems would
need to be clarified before we can address them.

Le mercredi 04 juin 2025 à 10:46 +0200, Florian Weimer a écrit :
> * Vivien Kraus:
> 
> >  This field says whether the option takes an argument.  It is an
> > integer,
> > diff --git a/posix/Versions b/posix/Versions
> > index 0624d24bcc..3ef3609711 100644
> > --- a/posix/Versions
> > +++ b/posix/Versions
> > @@ -18,7 +18,7 @@ libc {
> >      __environ; _environ;
> >  
> >      # variables in normal name space
> > -    environ; optarg; opterr; optind; optopt;
> > +    environ; optarg; opterr; optind; optopt; optctxt;
> >      re_max_failures; re_syntax_options;
> >  
> >      # a*
> 
> You cannot add new symbols to an existing version.  You need to start
> a
> GLIBC_2.42 section and add it there.

Thank you, I would not have known.
 
> > diff --git a/posix/bits/getopt_core.h b/posix/bits/getopt_core.h
> > index 95d01103f2..0a145bc4ad 100644
> > --- a/posix/bits/getopt_core.h
> > +++ b/posix/bits/getopt_core.h
> > @@ -58,6 +58,11 @@ extern int opterr;
> >  
> >  extern int optopt;
> >  
> > +/* Callers store the translation context in which to retrieve
> > option
> > +   names.  If unset, the option names will not be translated. */
> > +
> > +extern const char *optctxt;
> > +
> >  /* Get definitions and prototypes for functions to process the
> >     arguments in ARGV (ARGC of them, minus the program name) for
> >     options given in OPTS.
> > diff --git a/posix/getopt.c b/posix/getopt.c
> > index 451dfe8c0e..2fc928962a 100644
> > --- a/posix/getopt.c
> > +++ b/posix/getopt.c
> > @@ -114,6 +114,11 @@ int opterr = 1;
> >  
> >  int optopt = '?';
> >  
> > +/* Callers store an optional context to enable option name
> > +   translation. */
> > +
> > +const char *optctxt = NULL;
> 
> Doesn't this result in many conform and linknamespace test failures?
> I would expect that the declaration of optctxt needs to be
> conditional
> on __USE_GNU.
> 
> The getopt function is in POSIX, so posix/getopt.c may only define
> strong symbols that are also part of POSIX.  I think you need to find
> a
> way to move the definition of optctxt out of posix/getopt.c, and
> reference optctxt only from the getopt_long code paths.

You are right, it does indeed make these tests fail, and they also
fail if I keep calls to gettext inside the getopt.c file.  Let’s try a
function pointer.  It seems to work.

There is 1 remaining new test failure in my setup.  I had 146 failures
before these patches, and the 147th is elf/check-localplt, with output:

    Extra PLT reference: libc.so: dcgettext

and test result:

    FAIL: elf/check-localplt
    original exit status 1

I’m not sure why; do you have an idea?

Best regards,

Vivien

Vivien Kraus (4):
  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

 argp/Makefile                  |  14 ++++
 argp/argp-help.c               |  63 ++++++++++++++---
 argp/argp-parse.c              |   1 +
 argp/tst-argphelp-localized.c  | 102 ++++++++++++++++++++++++++++
 argp/tst-argphelp-localized.po |  18 +++++
 argp/tst-argpusage-localized.c |  82 ++++++++++++++++++++++
 manual/argp.texi               |  25 +++++--
 manual/getopt.texi             |  35 ++++++++--
 posix/Makefile                 |  13 ++++
 posix/Versions                 |   3 +
 posix/bits/getopt_ext.h        |  12 ++++
 posix/getopt.c                 | 112 +++++++++++++++++++++++++-----
 posix/getopt1.c                |  53 +++++++++++++--
 posix/getopt_int.h             |  14 +++-
 posix/tstgetoptl.c             | 120 +++++++++++++++++++++++++++++++++
 posix/tstgetoptl.po            |  27 ++++++++
 16 files changed, 651 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/tstgetoptl.c
 create mode 100644 posix/tstgetoptl.po


base-commit: 2fca4b624bd3ceb8c756b4145c7e96aa032b2b98
-- 
2.49.0



More information about the Libc-alpha mailing list