]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Refactor: Use gnulib's 'options' module.
authorBruno Haible <bruno@clisp.org>
Sat, 28 Jun 2025 21:48:03 +0000 (23:48 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 28 Jun 2025 21:48:03 +0000 (23:48 +0200)
* autogen.sh (GNULIB_MODULES_RUNTIME_FOR_SRC, GNULIB_MODULES_TOOLS_FOR_SRC): Add
'options'. Remove 'getopt-gnu'.
* gettext-runtime/src/envsubst.c: Include options.h instead of <getopt.h>.
(long_options): Remove variable.
(main): Define options array here. Call start_options, get_next_option instead
of getopt_long().
* gettext-runtime/src/gettext.c: Likewise.
* gettext-runtime/src/ngettext.c: Likewise.
* gettext-runtime/src/printf_gettext.c: Likewise.
* gettext-runtime/src/printf_ngettext.c: Likewise.
* gettext-tools/src/cldr-plurals.c: Likewise.
* gettext-tools/src/hostname.c: Likewise.
* gettext-tools/src/msgattrib.c: Likewise.
* gettext-tools/src/msgcat.c: Likewise.
* gettext-tools/src/msgcmp.c: Likewise.
* gettext-tools/src/msgcomm.c: Likewise.
* gettext-tools/src/msgconv.c: Likewise.
* gettext-tools/src/msgen.c: Likewise.
* gettext-tools/src/msgexec.c: Likewise.
* gettext-tools/src/msgfilter.c: Likewise.
* gettext-tools/src/msgfmt.c: Likewise.
* gettext-tools/src/msggrep.c: Likewise.
* gettext-tools/src/msginit.c: Likewise.
* gettext-tools/src/msgmerge.c: Likewise.
* gettext-tools/src/msgunfmt.c: Likewise.
* gettext-tools/src/msguniq.c: Likewise.
* gettext-tools/src/recode-sr-latin.c: Likewise.
* gettext-tools/src/urlget.c: Likewise.
* gettext-tools/src/xgettext.c: Likewise.
* gettext-tools/tests/tstgettext.c: Likewise.
* gettext-tools/tests/tstngettext.c: Likewise.

27 files changed:
autogen.sh
gettext-runtime/src/envsubst.c
gettext-runtime/src/gettext.c
gettext-runtime/src/ngettext.c
gettext-runtime/src/printf_gettext.c
gettext-runtime/src/printf_ngettext.c
gettext-tools/src/cldr-plurals.c
gettext-tools/src/hostname.c
gettext-tools/src/msgattrib.c
gettext-tools/src/msgcat.c
gettext-tools/src/msgcmp.c
gettext-tools/src/msgcomm.c
gettext-tools/src/msgconv.c
gettext-tools/src/msgen.c
gettext-tools/src/msgexec.c
gettext-tools/src/msgfilter.c
gettext-tools/src/msgfmt.c
gettext-tools/src/msggrep.c
gettext-tools/src/msginit.c
gettext-tools/src/msgmerge.c
gettext-tools/src/msgunfmt.c
gettext-tools/src/msguniq.c
gettext-tools/src/recode-sr-latin.c
gettext-tools/src/urlget.c
gettext-tools/src/xgettext.c
gettext-tools/tests/tstgettext.c
gettext-tools/tests/tstngettext.c

index 934c5d78f3083252f9377db83876eda98b341207..0aa68224ea01a586a2e43c2b9b6a30a65a8c6449 100755 (executable)
@@ -106,13 +106,13 @@ if ! $skip_gnulib; then
     closeout
     error
     fzprintf-posix
-    getopt-gnu
     gettext-h
     havelib
     mbrtoc32
     mbszero
     memmove
     noreturn
+    options
     progname
     propername
     quote
@@ -218,7 +218,6 @@ if ! $skip_gnulib; then
     gcd
     getaddrinfo
     getline
-    getopt-gnu
     getrusage
     gettext-h
     gocomp-script
@@ -247,6 +246,7 @@ if ! $skip_gnulib; then
     open
     opendir
     openmp-init
+    options
     pipe-filter-ii
     progname
     propername
index 596c2213190cdac0f807a433602cdda9f75cd396..26201e89982a0687868df6fe4f926ddd8d192005 100644 (file)
@@ -20,7 +20,6 @@
 #endif
 
 #include <errno.h>
-#include <getopt.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -29,6 +28,7 @@
 #include <locale.h>
 
 #include <error.h>
+#include "options.h"
 #include "attribute.h"
 #include "noreturn.h"
 #include "closeout.h"
 /* If true, substitution shall be performed on all variables.  */
 static bool all_variables;
 
-/* Long options.  */
-static const struct option long_options[] =
-{
-  { "help", no_argument, NULL, 'h' },
-  { "variables", no_argument, NULL, 'v' },
-  { "version", no_argument, NULL, 'V' },
-  { NULL, 0, NULL, 0 }
-};
-
 /* Forward declaration of local functions.  */
 _GL_NORETURN_FUNC static void usage (int status);
 static void print_variables (const char *string);
@@ -69,8 +60,6 @@ main (int argc, char *argv[])
   bool do_help = false;
   bool do_version = false;
 
-  int opt;
-
   /* Set program name for message texts.  */
   set_program_name (argv[0]);
 
@@ -86,10 +75,20 @@ main (int argc, char *argv[])
   atexit (close_stdout);
 
   /* Parse command line options.  */
-  while ((opt = getopt_long (argc, argv, "hvV", long_options, NULL)) != EOF)
+  BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
+  static const struct program_option options[] =
+  {
+    { "help",      'h', no_argument },
+    { "variables", 'v', no_argument },
+    { "version",   'V', no_argument },
+  };
+  END_ALLOW_OMITTING_FIELD_INITIALIZERS
+  start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
+  int opt;
+  while ((opt = get_next_option ()) != -1)
     switch (opt)
       {
-      case '\0':          /* Long option.  */
+      case '\0':          /* Long option with key == 0.  */
         break;
       case 'h':
         do_help = true;
index fa39ea892d9b3a87a644346096b0e11d06496b15..6dfa785690e4a40d7a7e2d3ea3e8b5efa98599b7 100644 (file)
@@ -19,7 +19,6 @@
 # include <config.h>
 #endif
 
-#include <getopt.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -27,6 +26,7 @@
 #include <locale.h>
 
 #include <error.h>
+#include "options.h"
 #include "attribute.h"
 #include "noreturn.h"
 #include "closeout.h"
@@ -48,24 +48,12 @@ static bool inhibit_added_newline;
    message catalog.  */
 static bool do_expand;
 
-/* Long options.  */
-static const struct option long_options[] =
-{
-  { "context", required_argument, NULL, 'c' },
-  { "domain", required_argument, NULL, 'd' },
-  { "help", no_argument, NULL, 'h' },
-  { "shell-script", no_argument, NULL, 's' },
-  { "version", no_argument, NULL, 'V' },
-  { NULL, 0, NULL, 0 }
-};
-
 /* Forward declaration of local functions.  */
 _GL_NORETURN_FUNC static void usage (int status);
 
 int
 main (int argc, char *argv[])
 {
-  int optchar;
   const char *msgid;
 
   /* Default values for command line options.  */
@@ -93,11 +81,25 @@ main (int argc, char *argv[])
   atexit (close_stdout);
 
   /* Parse command line options.  */
-  while ((optchar = getopt_long (argc, argv, "+c:d:eEhnsV", long_options, NULL))
-         != EOF)
+  BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
+  static const struct program_option options[] =
+  {
+    { "context",      'c', required_argument },
+    { "domain",       'd', required_argument },
+    { "help",         'h', no_argument       },
+    { "shell-script", 's', no_argument       },
+    { "version",      'V', no_argument       },
+    { NULL,           'e', no_argument       },
+    { NULL,           'E', no_argument       },
+    { NULL,           'n', no_argument       },
+  };
+  END_ALLOW_OMITTING_FIELD_INITIALIZERS
+  start_options (argc, argv, options, NON_OPTION_TERMINATES_OPTIONS, 0);
+  int optchar;
+  while ((optchar = get_next_option ()) != -1)
     switch (optchar)
       {
-      case '\0':          /* Long option.  */
+      case '\0':          /* Long option with key == 0.  */
         break;
       case 'c':
         context = optarg;
index 43dadad8de37e5ecda0170ed275b8e768e3c5adf..2f7fe644ad91b8f20c016605d14da29cf2f1fc9f 100644 (file)
@@ -18,7 +18,6 @@
 # include <config.h>
 #endif
 
-#include <getopt.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -28,6 +27,7 @@
 #include <errno.h>
 
 #include <error.h>
+#include "options.h"
 #include "attribute.h"
 #include "noreturn.h"
 #include "closeout.h"
    message catalog.  */
 static int do_expand;
 
-/* Long options.  */
-static const struct option long_options[] =
-{
-  { "context", required_argument, NULL, 'c' },
-  { "domain", required_argument, NULL, 'd' },
-  { "help", no_argument, NULL, 'h' },
-  { "version", no_argument, NULL, 'V' },
-  { NULL, 0, NULL, 0 }
-};
-
 /* Forward declaration of local functions.  */
 _GL_NORETURN_FUNC static void usage (int status);
 
 int
 main (int argc, char *argv[])
 {
-  int optchar;
   const char *msgid;
   const char *msgid_plural;
   const char *count;
@@ -90,11 +79,23 @@ main (int argc, char *argv[])
   atexit (close_stdout);
 
   /* Parse command line options.  */
-  while ((optchar = getopt_long (argc, argv, "+c:d:eEhV", long_options, NULL))
-         != EOF)
+  BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
+  static const struct program_option options[] =
+  {
+    { "context", 'c', required_argument },
+    { "domain",  'd', required_argument },
+    { "help",    'h', no_argument       },
+    { "version", 'V', no_argument       },
+    { NULL,      'e', no_argument       },
+    { NULL,      'E', no_argument       },
+  };
+  END_ALLOW_OMITTING_FIELD_INITIALIZERS
+  start_options (argc, argv, options, NON_OPTION_TERMINATES_OPTIONS, 0);
+  int optchar;
+  while ((optchar = get_next_option ()) != -1)
     switch (optchar)
       {
-      case '\0':          /* Long option.  */
+      case '\0':          /* Long option with key == 0.  */
         break;
       case 'c':
         context = optarg;
index e92e06a742dc9b3b07fe763cf695099d8ec1dc21..3ef0a8977b48d494f37c0526bfb168d6e34e10ab 100644 (file)
 # include <config.h>
 #endif
 
-#include <getopt.h>
 #include <locale.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 
 #include <error.h>
+#include "options.h"
 #include "printf-command.h"
 #include "noreturn.h"
 #include "closeout.h"
@@ -73,22 +73,20 @@ main (int argc, char *argv[])
 
   /* Parse command line options.  */
   {
-    /* Long options.  */
-    static const struct option long_options[] =
+    BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
+    static const struct program_option options[] =
     {
-      { "context", required_argument, NULL, 'c' },
-      { "help", no_argument, NULL, 'h' },
-      { "version", no_argument, NULL, 'V' },
-      { NULL, 0, NULL, 0 }
+      { "context", 'c', required_argument },
+      { "help",    'h', no_argument       },
+      { "version", 'V', no_argument       },
     };
-
+    END_ALLOW_OMITTING_FIELD_INITIALIZERS
+    start_options (argc, argv, options, NON_OPTION_TERMINATES_OPTIONS, 0);
     int optchar;
-
-    while ((optchar = getopt_long (argc, argv, "+c:hV", long_options, NULL))
-           != EOF)
+    while ((optchar = get_next_option ()) != -1)
       switch (optchar)
         {
-        case '\0':          /* Long option.  */
+        case '\0':          /* Long option with key == 0.  */
           break;
         case 'c':
           context = optarg;
index 9511cb0675127d62d89af1e1aa158271a2675406..b8a2efe504d8061116670ae621725c32132f3276 100644 (file)
 
 #include <ctype.h>
 #include <errno.h>
-#include <getopt.h>
 #include <locale.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 
 #include <error.h>
+#include "options.h"
 #include "printf-command.h"
 #include "noreturn.h"
 #include "closeout.h"
@@ -78,22 +78,20 @@ main (int argc, char *argv[])
 
   /* Parse command line options.  */
   {
-    /* Long options.  */
-    static const struct option long_options[] =
+    BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
+    static const struct program_option options[] =
     {
-      { "context", required_argument, NULL, 'c' },
-      { "help", no_argument, NULL, 'h' },
-      { "version", no_argument, NULL, 'V' },
-      { NULL, 0, NULL, 0 }
+      { "context", 'c', required_argument },
+      { "help",    'h', no_argument       },
+      { "version", 'V', no_argument       },
     };
-
+    END_ALLOW_OMITTING_FIELD_INITIALIZERS
+    start_options (argc, argv, options, NON_OPTION_TERMINATES_OPTIONS, 0);
     int optchar;
-
-    while ((optchar = getopt_long (argc, argv, "+c:hV", long_options, NULL))
-           != EOF)
+    while ((optchar = get_next_option ()) != -1)
       switch (optchar)
         {
-        case '\0':          /* Long option.  */
+        case '\0':          /* Long option with key == 0.  */
           break;
         case 'c':
           context = optarg;
index 0dbb64c0ee9e0bd9ba7eca83689685e05046b4a7..03f02224de20b786d8f00773cc45488446a07292 100644 (file)
@@ -26,7 +26,7 @@
 #include "c-ctype.h"
 #include <errno.h>
 #include <error.h>
-#include <getopt.h>
+#include "options.h"
 #include "gettext.h"
 #include <libxml/tree.h>
 #include <libxml/parser.h>
@@ -211,22 +211,12 @@ or by email to <%s>.\n"),
   exit (status);
 }
 
-/* Long options.  */
-static const struct option long_options[] =
-{
-  { "cldr", no_argument, NULL, 'c' },
-  { "help", no_argument, NULL, 'h' },
-  { "version", no_argument, NULL, 'V' },
-  { NULL, 0, NULL, 0 }
-};
-
 int
 main (int argc, char **argv)
 {
   bool opt_cldr_format = false;
   bool do_help = false;
   bool do_version = false;
-  int optchar;
 
   /* Set program name for messages.  */
   set_program_name (argv[0]);
@@ -243,10 +233,21 @@ main (int argc, char **argv)
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
-  while ((optchar = getopt_long (argc, argv, "chV", long_options, NULL)) != EOF)
+  /* Parse command line options.  */
+  BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
+  static const struct program_option options[] =
+  {
+    { "cldr",    'c', no_argument },
+    { "help",    'h', no_argument },
+    { "version", 'V', no_argument },
+  };
+  END_ALLOW_OMITTING_FIELD_INITIALIZERS
+  start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
+  int optchar;
+  while ((optchar = get_next_option ()) != -1)
     switch (optchar)
       {
-      case '\0':                /* Long option.  */
+      case '\0':          /* Long option with key == 0.  */
         break;
 
       case 'c':
index bb3e59dac040d5c45bc6699afb41402935717aef..98fe8baf908c7ff63f668ade80c92b632c6c6d34 100644 (file)
@@ -21,7 +21,6 @@
 #endif
 
 #include <errno.h>
-#include <getopt.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -96,6 +95,7 @@
 #include <stdbool.h>
 
 #include <error.h>
+#include "options.h"
 #include "noreturn.h"
 #include "closeout.h"
 #include "error-progname.h"
 /* Output format.  */
 static enum { default_format, short_format, long_format, ip_format } format;
 
-/* Long options.  */
-static const struct option long_options[] =
-{
-  { "fqdn", no_argument, NULL, 'f' },
-  { "help", no_argument, NULL, 'h' },
-  { "ip-address", no_argument, NULL, 'i' },
-  { "long", no_argument, NULL, 'f' },
-  { "short", no_argument, NULL, 's' },
-  { "version", no_argument, NULL, 'V' },
-  { NULL, 0, NULL, 0 }
-};
-
 
 /* Forward declaration of local functions.  */
 _GL_NORETURN_FUNC static void usage (int status);
@@ -132,7 +120,6 @@ static void print_hostname (void);
 int
 main (int argc, char *argv[])
 {
-  int optchar;
   bool do_help;
   bool do_version;
 
@@ -157,11 +144,23 @@ main (int argc, char *argv[])
   format = default_format;
 
   /* Parse command line options.  */
-  while ((optchar = getopt_long (argc, argv, "fhisV", long_options, NULL))
-         != EOF)
+  BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
+  static const struct program_option options[] =
+  {
+    { "fqdn",       'f', no_argument },
+    { "help",       'h', no_argument },
+    { "ip-address", 'i', no_argument },
+    { "long",       'f', no_argument },
+    { "short",      's', no_argument },
+    { "version",    'V', no_argument },
+  };
+  END_ALLOW_OMITTING_FIELD_INITIALIZERS
+  start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
+  int optchar;
+  while ((optchar = get_next_option ()) != -1)
     switch (optchar)
       {
-      case '\0':          /* Long option.  */
+      case '\0':          /* Long option with key == 0.  */
         break;
       case 'f':
         format = long_format;
index b85838360a4d620e2673410d895a2dc6d24dbd6c..0556af694a28e9016a7cd63d23aca1b465bd860b 100644 (file)
@@ -20,7 +20,6 @@
 # include "config.h"
 #endif
 
-#include <getopt.h>
 #include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -29,6 +28,7 @@
 #include <textstyle.h>
 
 #include <error.h>
+#include "options.h"
 #include "noreturn.h"
 #include "closeout.h"
 #include "dir-list.h"
@@ -81,50 +81,6 @@ enum
 };
 static int to_change;
 
-/* Long options.  */
-static const struct option long_options[] =
-{
-  { "add-location", optional_argument, NULL, 'n' },
-  { "clear-fuzzy", no_argument, NULL, CHAR_MAX + 8 },
-  { "clear-obsolete", no_argument, NULL, CHAR_MAX + 10 },
-  { "clear-previous", no_argument, NULL, CHAR_MAX + 18 },
-  { "empty", no_argument, NULL, CHAR_MAX + 23 },
-  { "color", optional_argument, NULL, CHAR_MAX + 19 },
-  { "directory", required_argument, NULL, 'D' },
-  { "escape", no_argument, NULL, 'E' },
-  { "force-po", no_argument, &force_po, 1 },
-  { "fuzzy", no_argument, NULL, CHAR_MAX + 11 },
-  { "help", no_argument, NULL, 'h' },
-  { "ignore-file", required_argument, NULL, CHAR_MAX + 15 },
-  { "indent", no_argument, NULL, 'i' },
-  { "no-escape", no_argument, NULL, 'e' },
-  { "no-fuzzy", no_argument, NULL, CHAR_MAX + 3 },
-  { "no-location", no_argument, NULL, CHAR_MAX + 22 },
-  { "no-obsolete", no_argument, NULL, CHAR_MAX + 5 },
-  { "no-wrap", no_argument, NULL, CHAR_MAX + 13 },
-  { "obsolete", no_argument, NULL, CHAR_MAX + 12 },
-  { "only-file", required_argument, NULL, CHAR_MAX + 14 },
-  { "only-fuzzy", no_argument, NULL, CHAR_MAX + 4 },
-  { "only-obsolete", no_argument, NULL, CHAR_MAX + 6 },
-  { "output-file", required_argument, NULL, 'o' },
-  { "previous", no_argument, NULL, CHAR_MAX + 21 },
-  { "properties-input", no_argument, NULL, 'P' },
-  { "properties-output", no_argument, NULL, 'p' },
-  { "set-fuzzy", no_argument, NULL, CHAR_MAX + 7 },
-  { "set-obsolete", no_argument, NULL, CHAR_MAX + 9 },
-  { "sort-by-file", no_argument, NULL, 'F' },
-  { "sort-output", no_argument, NULL, 's' },
-  { "stringtable-input", no_argument, NULL, CHAR_MAX + 16 },
-  { "stringtable-output", no_argument, NULL, CHAR_MAX + 17 },
-  { "strict", no_argument, NULL, 'S' },
-  { "style", required_argument, NULL, CHAR_MAX + 20 },
-  { "translated", no_argument, NULL, CHAR_MAX + 1 },
-  { "untranslated", no_argument, NULL, CHAR_MAX + 2 },
-  { "version", no_argument, NULL, 'V' },
-  { "width", required_argument, NULL, 'w' },
-  { NULL, 0, NULL, 0 }
-};
-
 
 /* Forward declaration of local functions.  */
 _GL_NORETURN_FUNC static void usage (int status);
@@ -136,7 +92,6 @@ static msgdomain_list_ty *process_msgdomain_list (msgdomain_list_ty *mdlp,
 int
 main (int argc, char **argv)
 {
-  int optchar;
   bool do_help;
   bool do_version;
   char *output_file;
@@ -176,11 +131,57 @@ main (int argc, char **argv)
   only_file = NULL;
   ignore_file = NULL;
 
-  while ((optchar = getopt_long (argc, argv, "D:eEFhino:pPsVw:", long_options,
-                                 NULL)) != EOF)
+  /* Parse command line options.  */
+  BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
+  static const struct program_option options[] =
+  {
+    { "add-location",       CHAR_MAX + 'n', optional_argument },
+    { NULL,                 'n',            no_argument       },
+    { "clear-fuzzy",        CHAR_MAX + 8,   no_argument       },
+    { "clear-obsolete",     CHAR_MAX + 10,  no_argument       },
+    { "clear-previous",     CHAR_MAX + 18,  no_argument       },
+    { "empty",              CHAR_MAX + 23,  no_argument       },
+    { "color",              CHAR_MAX + 19,  optional_argument },
+    { "directory",          'D',            required_argument },
+    { "escape",             'E',            no_argument       },
+    { "force-po",           0,              no_argument,      &force_po, 1 },
+    { "fuzzy",              CHAR_MAX + 11,  no_argument       },
+    { "help",               'h',            no_argument       },
+    { "ignore-file",        CHAR_MAX + 15,  required_argument },
+    { "indent",             'i',            no_argument       },
+    { "no-escape",          'e',            no_argument       },
+    { "no-fuzzy",           CHAR_MAX + 3,   no_argument       },
+    { "no-location",        CHAR_MAX + 22,  no_argument       },
+    { "no-obsolete",        CHAR_MAX + 5,   no_argument       },
+    { "no-wrap",            CHAR_MAX + 13,  no_argument       },
+    { "obsolete",           CHAR_MAX + 12,  no_argument       },
+    { "only-file",          CHAR_MAX + 14,  required_argument },
+    { "only-fuzzy",         CHAR_MAX + 4,   no_argument       },
+    { "only-obsolete",      CHAR_MAX + 6,   no_argument       },
+    { "output-file",        'o',            required_argument },
+    { "previous",           CHAR_MAX + 21,  no_argument       },
+    { "properties-input",   'P',            no_argument       },
+    { "properties-output",  'p',            no_argument       },
+    { "set-fuzzy",          CHAR_MAX + 7,   no_argument       },
+    { "set-obsolete",       CHAR_MAX + 9,   no_argument       },
+    { "sort-by-file",       'F',            no_argument       },
+    { "sort-output",        's',            no_argument       },
+    { "stringtable-input",  CHAR_MAX + 16,  no_argument       },
+    { "stringtable-output", CHAR_MAX + 17,  no_argument       },
+    { "strict",             CHAR_MAX + 24,  no_argument       },
+    { "style",              CHAR_MAX + 20,  required_argument },
+    { "translated",         CHAR_MAX + 1,   no_argument       },
+    { "untranslated",       CHAR_MAX + 2,   no_argument       },
+    { "version",            'V',            no_argument       },
+    { "width",              'w',            required_argument },
+  };
+  END_ALLOW_OMITTING_FIELD_INITIALIZERS
+  start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
+  int optchar;
+  while ((optchar = get_next_option ()) != -1)
     switch (optchar)
       {
-      case '\0':                /* Long option.  */
+      case '\0':                /* Long option with key == 0.  */
         break;
 
       case 'D':
@@ -207,7 +208,8 @@ main (int argc, char **argv)
         message_print_style_indent ();
         break;
 
-      case 'n':
+      case 'n':            /* -n */
+      case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
         if (handle_filepos_comment_option (optarg))
           usage (EXIT_FAILURE);
         break;
@@ -228,7 +230,7 @@ main (int argc, char **argv)
         sort_by_msgid = true;
         break;
 
-      case 'S':
+      case CHAR_MAX + 24: /* --strict */
         message_print_style_uniforum ();
         break;
 
index 595493e6c1f0f9c1e1a9a8f13f449fe4b1890ab5..d438e99ea537a54a5ea5f8f68ce6c544e85ee362 100644 (file)
@@ -20,7 +20,6 @@
 # include "config.h"
 #endif
 
-#include <getopt.h>
 #include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -29,6 +28,7 @@
 #include <textstyle.h>
 
 #include <error.h>
+#include "options.h"
 #include "noreturn.h"
 #include "closeout.h"
 #include "dir-list.h"
@@ -62,40 +62,6 @@ static int force_po;
 /* Target encoding.  */
 static const char *to_code;
 
-/* Long options.  */
-static const struct option long_options[] =
-{
-  { "add-location", optional_argument, NULL, 'n' },
-  { "color", optional_argument, NULL, CHAR_MAX + 5 },
-  { "directory", required_argument, NULL, 'D' },
-  { "escape", no_argument, NULL, 'E' },
-  { "files-from", required_argument, NULL, 'f' },
-  { "force-po", no_argument, &force_po, 1 },
-  { "help", no_argument, NULL, 'h' },
-  { "indent", no_argument, NULL, 'i' },
-  { "lang", required_argument, NULL, CHAR_MAX + 7 },
-  { "no-escape", no_argument, NULL, 'e' },
-  { "no-location", no_argument, NULL, CHAR_MAX + 8 },
-  { "no-wrap", no_argument, NULL, CHAR_MAX + 2 },
-  { "output-file", required_argument, NULL, 'o' },
-  { "properties-input", no_argument, NULL, 'P' },
-  { "properties-output", no_argument, NULL, 'p' },
-  { "sort-by-file", no_argument, NULL, 'F' },
-  { "sort-output", no_argument, NULL, 's' },
-  { "strict", no_argument, NULL, 'S' },
-  { "stringtable-input", no_argument, NULL, CHAR_MAX + 3 },
-  { "stringtable-output", no_argument, NULL, CHAR_MAX + 4 },
-  { "style", required_argument, NULL, CHAR_MAX + 6 },
-  { "to-code", required_argument, NULL, 't' },
-  { "unique", no_argument, NULL, 'u' },
-  { "use-first", no_argument, NULL, CHAR_MAX + 1 },
-  { "version", no_argument, NULL, 'V' },
-  { "width", required_argument, NULL, 'w' },
-  { "more-than", required_argument, NULL, '>' },
-  { "less-than", required_argument, NULL, '<' },
-  { NULL, 0, NULL, 0 }
-};
-
 
 /* Forward declaration of local functions.  */
 _GL_NORETURN_FUNC static void usage (int status);
@@ -105,7 +71,6 @@ int
 main (int argc, char **argv)
 {
   int cnt;
-  int optchar;
   bool do_help;
   bool do_version;
   char *output_file;
@@ -145,11 +110,47 @@ main (int argc, char **argv)
   less_than = INT_MAX;
   use_first = false;
 
-  while ((optchar = getopt_long (argc, argv, "<:>:D:eEf:Fhino:pPst:uVw:",
-                                 long_options, NULL)) != EOF)
+  /* Parse command line options.  */
+  BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
+  static const struct program_option options[] =
+  {
+    { "add-location",       CHAR_MAX + 'n', optional_argument },
+    { NULL,                 'n',            no_argument       },
+    { "color",              CHAR_MAX + 5,   optional_argument },
+    { "directory",          'D',            required_argument },
+    { "escape",             'E',            no_argument       },
+    { "files-from",         'f',            required_argument },
+    { "force-po",           0,              no_argument,      &force_po, 1 },
+    { "help",               'h',            no_argument       },
+    { "indent",             'i',            no_argument       },
+    { "lang",               CHAR_MAX + 7,   required_argument },
+    { "no-escape",          'e',            no_argument       },
+    { "no-location",        CHAR_MAX + 8,   no_argument       },
+    { "no-wrap",            CHAR_MAX + 2,   no_argument       },
+    { "output-file",        'o',            required_argument },
+    { "properties-input",   'P',            no_argument       },
+    { "properties-output",  'p',            no_argument       },
+    { "sort-by-file",       'F',            no_argument       },
+    { "sort-output",        's',            no_argument       },
+    { "strict",             CHAR_MAX + 9,   no_argument       },
+    { "stringtable-input",  CHAR_MAX + 3,   no_argument       },
+    { "stringtable-output", CHAR_MAX + 4,   no_argument       },
+    { "style",              CHAR_MAX + 6,   required_argument },
+    { "to-code",            't',            required_argument },
+    { "unique",             'u',            no_argument       },
+    { "use-first",          CHAR_MAX + 1,   no_argument       },
+    { "version",            'V',            no_argument       },
+    { "width",              'w',            required_argument },
+    { "more-than",          '>',            required_argument },
+    { "less-than",          '<',            required_argument },
+  };
+  END_ALLOW_OMITTING_FIELD_INITIALIZERS
+  start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
+  int optchar;
+  while ((optchar = get_next_option ()) != -1)
     switch (optchar)
       {
-      case '\0':                /* Long option.  */
+      case '\0':                /* Long option with key == 0.  */
         break;
 
       case '>':
@@ -200,7 +201,8 @@ main (int argc, char **argv)
         message_print_style_indent ();
         break;
 
-      case 'n':
+      case 'n':            /* -n */
+      case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
         if (handle_filepos_comment_option (optarg))
           usage (EXIT_FAILURE);
         break;
@@ -221,7 +223,7 @@ main (int argc, char **argv)
         sort_by_msgid = true;
         break;
 
-      case 'S':
+      case CHAR_MAX + 9: /* --strict */
         message_print_style_uniforum ();
         break;
 
index b0dd71f4ad99d066a8f0dcdf6d9160628b8ce783..e8bf4cbb500152d91c847dff2ea67e753252cc6f 100644 (file)
@@ -19,7 +19,6 @@
 # include <config.h>
 #endif
 
-#include <getopt.h>
 #include <limits.h>
 #include <stdbool.h>
 #include <stdio.h>
@@ -27,6 +26,7 @@
 #include <locale.h>
 
 #include <error.h>
+#include "options.h"
 #include "noreturn.h"
 #include "closeout.h"
 #include "dir-list.h"
@@ -66,21 +66,6 @@ static bool include_fuzzies = false;
 /* Whether to consider untranslated messages as translations.  */
 static bool include_untranslated = false;
 
-/* Long options.  */
-static const struct option long_options[] =
-{
-  { "directory", required_argument, NULL, 'D' },
-  { "help", no_argument, NULL, 'h' },
-  { "multi-domain", no_argument, NULL, 'm' },
-  { "no-fuzzy-matching", no_argument, NULL, 'N' },
-  { "properties-input", no_argument, NULL, 'P' },
-  { "stringtable-input", no_argument, NULL, CHAR_MAX + 1 },
-  { "use-fuzzy", no_argument, NULL, CHAR_MAX + 2 },
-  { "use-untranslated", no_argument, NULL, CHAR_MAX + 3 },
-  { "version", no_argument, NULL, 'V' },
-  { NULL, 0, NULL, 0 }
-};
-
 
 /* Forward declaration of local functions.  */
 _GL_NORETURN_FUNC static void usage (int status);
@@ -91,7 +76,6 @@ static void compare (const char *fn1, const char *fn2,
 int
 main (int argc, char *argv[])
 {
-  int optchar;
   bool do_help;
   bool do_version;
   catalog_input_format_ty input_syntax = &input_format_po;
@@ -115,11 +99,28 @@ main (int argc, char *argv[])
 
   do_help = false;
   do_version = false;
-  while ((optchar = getopt_long (argc, argv, "D:hmNPV", long_options, NULL))
-         != EOF)
+
+  /* Parse command line options.  */
+  BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
+  static const struct program_option options[] =
+  {
+    { "directory",         'D',          required_argument },
+    { "help",              'h',          no_argument },
+    { "multi-domain",      'm',          no_argument },
+    { "no-fuzzy-matching", 'N',          no_argument },
+    { "properties-input",  'P',          no_argument },
+    { "stringtable-input", CHAR_MAX + 1, no_argument },
+    { "use-fuzzy",         CHAR_MAX + 2, no_argument },
+    { "use-untranslated",  CHAR_MAX + 3, no_argument },
+    { "version",           'V',          no_argument },
+  };
+  END_ALLOW_OMITTING_FIELD_INITIALIZERS
+  start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
+  int optchar;
+  while ((optchar = get_next_option ()) != -1)
     switch (optchar)
       {
-      case '\0':                /* long option */
+      case '\0':                /* Long option with key == 0.  */
         break;
 
       case 'D':
index 114b0d6aac699272a05abd8fe484348915ee43ed..666d34611fbf922d64b49a2159ce1a8b7a695478 100644 (file)
@@ -20,7 +20,6 @@
 # include <config.h>
 #endif
 
-#include <getopt.h>
 #include <limits.h>
 #include <locale.h>
 #include <stdio.h>
@@ -29,6 +28,7 @@
 #include <textstyle.h>
 
 #include <error.h>
+#include "options.h"
 #include "noreturn.h"
 #include "closeout.h"
 #include "dir-list.h"
@@ -63,40 +63,6 @@ static int force_po;
 /* Target encoding.  */
 static const char *to_code;
 
-/* Long options.  */
-static const struct option long_options[] =
-{
-  { "add-location", optional_argument, NULL, 'n' },
-  { "color", optional_argument, NULL, CHAR_MAX + 5 },
-  { "directory", required_argument, NULL, 'D' },
-  { "escape", no_argument, NULL, 'E' },
-  { "files-from", required_argument, NULL, 'f' },
-  { "force-po", no_argument, &force_po, 1 },
-  { "help", no_argument, NULL, 'h' },
-  { "indent", no_argument, NULL, 'i' },
-  { "no-escape", no_argument, NULL, 'e' },
-  { "no-location", no_argument, NULL, CHAR_MAX + 7 },
-  { "no-wrap", no_argument, NULL, CHAR_MAX + 2 },
-  { "omit-header", no_argument, NULL, CHAR_MAX + 1 },
-  { "output", required_argument, NULL, 'o' }, /* for backward compatibility */
-  { "output-file", required_argument, NULL, 'o' },
-  { "properties-input", no_argument, NULL, 'P' },
-  { "properties-output", no_argument, NULL, 'p' },
-  { "sort-by-file", no_argument, NULL, 'F' },
-  { "sort-output", no_argument, NULL, 's' },
-  { "strict", no_argument, NULL, 'S' },
-  { "stringtable-input", no_argument, NULL, CHAR_MAX + 3 },
-  { "stringtable-output", no_argument, NULL, CHAR_MAX + 4 },
-  { "style", required_argument, NULL, CHAR_MAX + 6 },
-  { "to-code", required_argument, NULL, 't' },
-  { "unique", no_argument, NULL, 'u' },
-  { "version", no_argument, NULL, 'V' },
-  { "width", required_argument, NULL, 'w' },
-  { "more-than", required_argument, NULL, '>' },
-  { "less-than", required_argument, NULL, '<' },
-  { NULL, 0, NULL, 0 }
-};
-
 
 /* Forward declaration of local functions.  */
 _GL_NORETURN_FUNC static void usage (int status);
@@ -106,7 +72,6 @@ int
 main (int argc, char *argv[])
 {
   int cnt;
-  int optchar;
   bool do_help = false;
   bool do_version = false;
   msgdomain_list_ty *result;
@@ -140,11 +105,47 @@ main (int argc, char *argv[])
   less_than = -1;
   use_first = false;
 
-  while ((optchar = getopt_long (argc, argv, "<:>:D:eEf:Fhino:pPst:uVw:",
-                                 long_options, NULL)) != EOF)
+  /* Parse command line options.  */
+  BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
+  static const struct program_option options[] =
+  {
+    { "add-location",       CHAR_MAX + 'n', optional_argument },
+    { NULL,                 'n',            no_argument       },
+    { "color",              CHAR_MAX + 5,   optional_argument },
+    { "directory",          'D',            required_argument },
+    { "escape",             'E',            no_argument       },
+    { "files-from",         'f',            required_argument },
+    { "force-po",           0,              no_argument,      &force_po, 1 },
+    { "help",               'h',            no_argument       },
+    { "indent",             'i',            no_argument       },
+    { "no-escape",          'e',            no_argument       },
+    { "no-location",        CHAR_MAX + 7,   no_argument       },
+    { "no-wrap",            CHAR_MAX + 2,   no_argument       },
+    { "omit-header",        CHAR_MAX + 1,   no_argument       },
+    { "output",             'o',            required_argument }, /* for backward compatibility */
+    { "output-file",        'o',            required_argument },
+    { "properties-input",   'P',            no_argument       },
+    { "properties-output",  'p',            no_argument       },
+    { "sort-by-file",       'F',            no_argument       },
+    { "sort-output",        's',            no_argument       },
+    { "strict",             CHAR_MAX + 8,   no_argument       },
+    { "stringtable-input",  CHAR_MAX + 3,   no_argument       },
+    { "stringtable-output", CHAR_MAX + 4,   no_argument       },
+    { "style",              CHAR_MAX + 6,   required_argument },
+    { "to-code",            't',            required_argument },
+    { "unique",             'u',            no_argument       },
+    { "version",            'V',            no_argument       },
+    { "width",              'w',            required_argument },
+    { "more-than",          '>',            required_argument },
+    { "less-than",          '<',            required_argument },
+  };
+  END_ALLOW_OMITTING_FIELD_INITIALIZERS
+  start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
+  int optchar;
+  while ((optchar = get_next_option ()) != -1)
     switch (optchar)
       {
-      case '\0':                /* Long option.  */
+      case '\0':                /* Long option with key == 0.  */
         break;
 
       case '>':
@@ -195,7 +196,8 @@ main (int argc, char *argv[])
         message_print_style_indent ();
         break;
 
-      case 'n':
+      case 'n':            /* -n */
+      case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
         if (handle_filepos_comment_option (optarg))
           usage (EXIT_FAILURE);
         break;
@@ -216,7 +218,7 @@ main (int argc, char *argv[])
         sort_by_msgid = true;
         break;
 
-      case 'S':
+      case CHAR_MAX + 8: /* --strict */
         message_print_style_uniforum ();
         break;
 
index b6dc494cfc6e047b7f46311d9139a84b8cfda6e7..f47a83c32dd62309412e6d91001e56fd3e0a6265 100644 (file)
@@ -20,7 +20,6 @@
 # include "config.h"
 #endif
 
-#include <getopt.h>
 #include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -29,6 +28,7 @@
 #include <textstyle.h>
 
 #include <error.h>
+#include "options.h"
 #include "noreturn.h"
 #include "closeout.h"
 #include "dir-list.h"
@@ -60,34 +60,6 @@ static int force_po;
 /* Target encoding.  */
 static const char *to_code;
 
-/* Long options.  */
-static const struct option long_options[] =
-{
-  { "add-location", optional_argument, NULL, 'n' },
-  { "color", optional_argument, NULL, CHAR_MAX + 4 },
-  { "directory", required_argument, NULL, 'D' },
-  { "escape", no_argument, NULL, 'E' },
-  { "force-po", no_argument, &force_po, 1 },
-  { "help", no_argument, NULL, 'h' },
-  { "indent", no_argument, NULL, 'i' },
-  { "no-escape", no_argument, NULL, 'e' },
-  { "no-location", no_argument, NULL, CHAR_MAX + 6 },
-  { "no-wrap", no_argument, NULL, CHAR_MAX + 1 },
-  { "output-file", required_argument, NULL, 'o' },
-  { "properties-input", no_argument, NULL, 'P' },
-  { "properties-output", no_argument, NULL, 'p' },
-  { "sort-by-file", no_argument, NULL, 'F' },
-  { "sort-output", no_argument, NULL, 's' },
-  { "strict", no_argument, NULL, 'S' },
-  { "stringtable-input", no_argument, NULL, CHAR_MAX + 2 },
-  { "stringtable-output", no_argument, NULL, CHAR_MAX + 3 },
-  { "style", required_argument, NULL, CHAR_MAX + 5 },
-  { "to-code", required_argument, NULL, 't' },
-  { "version", no_argument, NULL, 'V' },
-  { "width", required_argument, NULL, 'w' },
-  { NULL, 0, NULL, 0 }
-};
-
 
 /* Forward declaration of local functions.  */
 _GL_NORETURN_FUNC static void usage (int status);
@@ -96,7 +68,6 @@ _GL_NORETURN_FUNC static void usage (int status);
 int
 main (int argc, char **argv)
 {
-  int opt;
   bool do_help;
   bool do_version;
   char *output_file;
@@ -130,12 +101,41 @@ main (int argc, char **argv)
   output_file = NULL;
   input_file = NULL;
 
-  while ((opt = getopt_long (argc, argv, "D:eEFhino:pPst:Vw:", long_options,
-                             NULL))
-         != EOF)
+  /* Parse command line options.  */
+  BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
+  static const struct program_option options[] =
+  {
+    { "add-location",       CHAR_MAX + 'n', optional_argument },
+    { NULL,                 'n',            no_argument       },
+    { "color",              CHAR_MAX + 4,   optional_argument },
+    { "directory",          'D',            required_argument },
+    { "escape",             'E',            no_argument       },
+    { "force-po",           0,              no_argument,      &force_po, 1 },
+    { "help",               'h',            no_argument       },
+    { "indent",             'i',            no_argument       },
+    { "no-escape",          'e',            no_argument       },
+    { "no-location",        CHAR_MAX + 6,   no_argument       },
+    { "no-wrap",            CHAR_MAX + 1,   no_argument       },
+    { "output-file",        'o',            required_argument },
+    { "properties-input",   'P',            no_argument       },
+    { "properties-output",  'p',            no_argument       },
+    { "sort-by-file",       'F',            no_argument       },
+    { "sort-output",        's',            no_argument       },
+    { "strict",             CHAR_MAX + 7,   no_argument       },
+    { "stringtable-input",  CHAR_MAX + 2,   no_argument       },
+    { "stringtable-output", CHAR_MAX + 3,   no_argument       },
+    { "style",              CHAR_MAX + 5,   required_argument },
+    { "to-code",            't',            required_argument },
+    { "version",            'V',            no_argument       },
+    { "width",              'w',            required_argument },
+  };
+  END_ALLOW_OMITTING_FIELD_INITIALIZERS
+  start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
+  int opt;
+  while ((opt = get_next_option ()) != -1)
     switch (opt)
       {
-      case '\0':                /* Long option.  */
+      case '\0':                /* Long option with key == 0.  */
         break;
 
       case 'D':
@@ -162,7 +162,8 @@ main (int argc, char **argv)
         message_print_style_indent ();
         break;
 
-      case 'n':
+      case 'n':            /* -n */
+      case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
         if (handle_filepos_comment_option (optarg))
           usage (EXIT_FAILURE);
         break;
@@ -183,7 +184,7 @@ main (int argc, char **argv)
         sort_by_msgid = true;
         break;
 
-      case 'S':
+      case CHAR_MAX + 7: /* --strict */
         message_print_style_uniforum ();
         break;
 
index f7fb82d009a101abb9dc44929cd3c40bac1e4f99..f9d9b20a6c10ad8514d2a6651f25f38844b4969c 100644 (file)
@@ -20,7 +20,6 @@
 # include "config.h"
 #endif
 
-#include <getopt.h>
 #include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -29,6 +28,7 @@
 #include <textstyle.h>
 
 #include <error.h>
+#include "options.h"
 #include "noreturn.h"
 #include "closeout.h"
 #include "dir-list.h"
 /* Force output of PO file even if empty.  */
 static int force_po;
 
-/* Long options.  */
-static const struct option long_options[] =
-{
-  { "add-location", optional_argument, NULL, 'n' },
-  { "color", optional_argument, NULL, CHAR_MAX + 5 },
-  { "directory", required_argument, NULL, 'D' },
-  { "escape", no_argument, NULL, 'E' },
-  { "force-po", no_argument, &force_po, 1 },
-  { "help", no_argument, NULL, 'h' },
-  { "indent", no_argument, NULL, 'i' },
-  { "lang", required_argument, NULL, CHAR_MAX + 4 },
-  { "no-escape", no_argument, NULL, 'e' },
-  { "no-location", no_argument, NULL, CHAR_MAX + 7 },
-  { "no-wrap", no_argument, NULL, CHAR_MAX + 1 },
-  { "output-file", required_argument, NULL, 'o' },
-  { "properties-input", no_argument, NULL, 'P' },
-  { "properties-output", no_argument, NULL, 'p' },
-  { "sort-by-file", no_argument, NULL, 'F' },
-  { "sort-output", no_argument, NULL, 's' },
-  { "strict", no_argument, NULL, 'S' },
-  { "stringtable-input", no_argument, NULL, CHAR_MAX + 2 },
-  { "stringtable-output", no_argument, NULL, CHAR_MAX + 3 },
-  { "style", required_argument, NULL, CHAR_MAX + 6 },
-  { "version", no_argument, NULL, 'V' },
-  { "width", required_argument, NULL, 'w' },
-  { NULL, 0, NULL, 0 }
-};
-
 
 /* Forward declaration of local functions.  */
 _GL_NORETURN_FUNC static void usage (int status);
@@ -97,7 +69,6 @@ static msgdomain_list_ty *fill_header (msgdomain_list_ty *mdlp);
 int
 main (int argc, char **argv)
 {
-  int opt;
   bool do_help;
   bool do_version;
   char *output_file;
@@ -131,12 +102,41 @@ main (int argc, char **argv)
   do_version = false;
   output_file = NULL;
 
-  while ((opt = getopt_long (argc, argv,
-                             "D:eEFhino:pPsVw:",
-                             long_options, NULL)) != EOF)
+  /* Parse command line options.  */
+  BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
+  static const struct program_option options[] =
+  {
+    { "add-location",       CHAR_MAX + 'n', optional_argument },
+    { NULL,                 'n',            no_argument       },
+    { "color",              CHAR_MAX + 5,   optional_argument },
+    { "directory",          'D',            required_argument },
+    { "escape",             'E',            no_argument       },
+    { "force-po",           0,              no_argument,      &force_po, 1 },
+    { "help",               'h',            no_argument       },
+    { "indent",             'i',            no_argument       },
+    { "lang",               CHAR_MAX + 4,   required_argument },
+    { "no-escape",          'e',            no_argument       },
+    { "no-location",        CHAR_MAX + 7,   no_argument       },
+    { "no-wrap",            CHAR_MAX + 1,   no_argument       },
+    { "output-file",        'o',            required_argument },
+    { "properties-input",   'P',            no_argument       },
+    { "properties-output",  'p',            no_argument       },
+    { "sort-by-file",       'F',            no_argument       },
+    { "sort-output",        's',            no_argument       },
+    { "strict",             CHAR_MAX + 8,   no_argument       },
+    { "stringtable-input",  CHAR_MAX + 2,   no_argument       },
+    { "stringtable-output", CHAR_MAX + 3,   no_argument       },
+    { "style",              CHAR_MAX + 6,   required_argument },
+    { "version",            'V',            no_argument       },
+    { "width",              'w',            required_argument },
+  };
+  END_ALLOW_OMITTING_FIELD_INITIALIZERS
+  start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
+  int opt;
+  while ((opt = get_next_option ()) != -1)
     switch (opt)
       {
-      case '\0':                /* Long option.  */
+      case '\0':                /* Long option with key == 0.  */
         break;
 
       case 'D':
@@ -163,7 +163,8 @@ main (int argc, char **argv)
         message_print_style_indent ();
         break;
 
-      case 'n':
+      case 'n':            /* -n */
+      case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
         if (handle_filepos_comment_option (optarg))
           usage (EXIT_FAILURE);
         break;
@@ -184,7 +185,7 @@ main (int argc, char **argv)
         sort_by_msgid = true;
         break;
 
-      case 'S':
+      case CHAR_MAX + 8: /* --strict */
         message_print_style_uniforum ();
         break;
 
index e7ab4263f5efed6841aa9b6fa372a9eedac3927b..bc52c42340e108e0c8323e92551a82d5e93edfb5 100644 (file)
@@ -21,7 +21,6 @@
 #endif
 
 #include <errno.h>
-#include <getopt.h>
 #include <limits.h>
 #include <locale.h>
 #include <signal.h>
@@ -32,6 +31,7 @@
 #include <unistd.h>
 
 #include <error.h>
+#include "options.h"
 #include "noreturn.h"
 #include "closeout.h"
 #include "dir-list.h"
@@ -77,19 +77,6 @@ static bool newline;
 /* Maximum exit code encountered.  */
 static int exitcode;
 
-/* Long options.  */
-static const struct option long_options[] =
-{
-  { "directory", required_argument, NULL, 'D' },
-  { "help", no_argument, NULL, 'h' },
-  { "input", required_argument, NULL, 'i' },
-  { "newline", no_argument, NULL, CHAR_MAX + 2 },
-  { "properties-input", no_argument, NULL, 'P' },
-  { "stringtable-input", no_argument, NULL, CHAR_MAX + 1 },
-  { "version", no_argument, NULL, 'V' },
-  { NULL, 0, NULL, 0 }
-};
-
 
 /* Forward declaration of local functions.  */
 _GL_NORETURN_FUNC static void usage (int status);
@@ -99,7 +86,6 @@ static void process_msgdomain_list (const msgdomain_list_ty *mdlp);
 int
 main (int argc, char **argv)
 {
-  int opt;
   bool do_help;
   bool do_version;
   const char *input_file;
@@ -129,13 +115,27 @@ main (int argc, char **argv)
   do_version = false;
   input_file = NULL;
 
-  /* The '+' in the options string causes option parsing to terminate when
-     the first non-option, i.e. the subprogram name, is encountered.  */
-  while ((opt = getopt_long (argc, argv, "+D:hi:PV", long_options, NULL))
-         != EOF)
+  /* Parse command line options.  */
+  BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
+  static const struct program_option options[] =
+  {
+    { "directory",         'D',          required_argument },
+    { "help",              'h',          no_argument       },
+    { "input",             'i',          required_argument },
+    { "newline",           CHAR_MAX + 2, no_argument       },
+    { "properties-input",  'P',          no_argument       },
+    { "stringtable-input", CHAR_MAX + 1, no_argument       },
+    { "version",           'V',          no_argument       },
+  };
+  END_ALLOW_OMITTING_FIELD_INITIALIZERS
+  /* The flag NON_OPTION_TERMINATES_OPTIONS causes option parsing to terminate
+     when the first non-option, i.e. the subprogram name, is encountered.  */
+  start_options (argc, argv, options, NON_OPTION_TERMINATES_OPTIONS, 0);
+  int opt;
+  while ((opt = get_next_option ()) != -1)
     switch (opt)
       {
-      case '\0':                /* Long option.  */
+      case '\0':                /* Long option with key == 0.  */
         break;
 
       case 'D':
index 9d3ed88afce20a0ff59fc517d216eb3878c45951..f7dfbb6d85888e04512495b2206cfccb25b74ccf 100644 (file)
@@ -20,7 +20,6 @@
 # include "config.h"
 #endif
 
-#include <getopt.h>
 #include <limits.h>
 #include <locale.h>
 #include <stdio.h>
@@ -33,6 +32,7 @@
 #include <textstyle.h>
 
 #include <error.h>
+#include "options.h"
 #include "noreturn.h"
 #include "closeout.h"
 #include "dir-list.h"
@@ -89,36 +89,6 @@ static bool newline;
 /* Filter function.  */
 static void (*filter) (const char *str, size_t len, char **resultp, size_t *lengthp);
 
-/* Long options.  */
-static const struct option long_options[] =
-{
-  { "add-location", optional_argument, NULL, 'n' },
-  { "color", optional_argument, NULL, CHAR_MAX + 6 },
-  { "directory", required_argument, NULL, 'D' },
-  { "escape", no_argument, NULL, 'E' },
-  { "force-po", no_argument, &force_po, 1 },
-  { "help", no_argument, NULL, 'h' },
-  { "indent", no_argument, NULL, CHAR_MAX + 1 },
-  { "input", required_argument, NULL, 'i' },
-  { "keep-header", no_argument, &keep_header, 1 },
-  { "newline", no_argument, NULL, CHAR_MAX + 9 },
-  { "no-escape", no_argument, NULL, CHAR_MAX + 2 },
-  { "no-location", no_argument, NULL, CHAR_MAX + 8 },
-  { "no-wrap", no_argument, NULL, CHAR_MAX + 3 },
-  { "output-file", required_argument, NULL, 'o' },
-  { "properties-input", no_argument, NULL, 'P' },
-  { "properties-output", no_argument, NULL, 'p' },
-  { "sort-by-file", no_argument, NULL, 'F' },
-  { "sort-output", no_argument, NULL, 's' },
-  { "strict", no_argument, NULL, 'S' },
-  { "stringtable-input", no_argument, NULL, CHAR_MAX + 4 },
-  { "stringtable-output", no_argument, NULL, CHAR_MAX + 5 },
-  { "style", required_argument, NULL, CHAR_MAX + 7 },
-  { "version", no_argument, NULL, 'V' },
-  { "width", required_argument, NULL, 'w' },
-  { NULL, 0, NULL, 0 }
-};
-
 
 /* Forward declaration of local functions.  */
 _GL_NORETURN_FUNC static void usage (int status);
@@ -129,7 +99,6 @@ static msgdomain_list_ty *process_msgdomain_list (msgdomain_list_ty *mdlp);
 int
 main (int argc, char **argv)
 {
-  int opt;
   bool do_help;
   bool do_version;
   char *output_file;
@@ -164,14 +133,45 @@ main (int argc, char **argv)
   output_file = NULL;
   input_file = NULL;
 
-  /* The '+' in the options string causes option parsing to terminate when
-     the first non-option, i.e. the subprogram name, is encountered.  */
-  while ((opt = getopt_long (argc, argv, "+D:EFhi:no:pPsVw:", long_options,
-                             NULL))
-         != EOF)
+  /* Parse command line options.  */
+  BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
+  static const struct program_option options[] =
+  {
+    { "add-location",      CHAR_MAX + 'n', optional_argument },
+    { NULL,                'n',            no_argument       },
+    { "color",             CHAR_MAX + 6,   optional_argument },
+    { "directory",         'D',            required_argument },
+    { "escape",            'E',            no_argument       },
+    { "force-po",           0,             no_argument,      &force_po, 1 },
+    { "help",               'h',           no_argument       },
+    { "indent",             CHAR_MAX + 1,  no_argument       },
+    { "input",              'i',           required_argument },
+    { "keep-header",        0,             no_argument,      &keep_header, 1 },
+    { "newline",            CHAR_MAX + 9,  no_argument       },
+    { "no-escape",          CHAR_MAX + 2,  no_argument       },
+    { "no-location",        CHAR_MAX + 8,  no_argument       },
+    { "no-wrap",            CHAR_MAX + 3,  no_argument       },
+    { "output-file",        'o',           required_argument },
+    { "properties-input",   'P',           no_argument       },
+    { "properties-output",  'p',           no_argument       },
+    { "sort-by-file",       'F',           no_argument       },
+    { "sort-output",        's',           no_argument       },
+    { "strict",             CHAR_MAX + 10, no_argument       },
+    { "stringtable-input",  CHAR_MAX + 4,  no_argument       },
+    { "stringtable-output", CHAR_MAX + 5,  no_argument       },
+    { "style",              CHAR_MAX + 7,  required_argument },
+    { "version",            'V',           no_argument       },
+    { "width",              'w',           required_argument },
+  };
+  END_ALLOW_OMITTING_FIELD_INITIALIZERS
+  /* The flag NON_OPTION_TERMINATES_OPTIONS causes option parsing to terminate
+     when the first non-option, i.e. the subprogram name, is encountered.  */
+  start_options (argc, argv, options, NON_OPTION_TERMINATES_OPTIONS, 0);
+  int opt;
+  while ((opt = get_next_option ()) != -1)
     switch (opt)
       {
-      case '\0':                /* Long option.  */
+      case '\0':                /* Long option with key == 0.  */
         break;
 
       case 'D':
@@ -199,7 +199,8 @@ main (int argc, char **argv)
         input_file = optarg;
         break;
 
-      case 'n':
+      case 'n':            /* -n */
+      case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
         if (handle_filepos_comment_option (optarg))
           usage (EXIT_FAILURE);
         break;
@@ -220,7 +221,7 @@ main (int argc, char **argv)
         sort_by_msgid = true;
         break;
 
-      case 'S':
+      case CHAR_MAX + 10: /* --strict */
         message_print_style_uniforum ();
         break;
 
index 39008c793bf35c74fb180cd15755b52739ceab01..863276e6f5ceb1e5361b63d6466ef1373f67cc25 100644 (file)
@@ -20,7 +20,6 @@
 #endif
 
 #include <ctype.h>
-#include <getopt.h>
 #include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -31,6 +30,7 @@
 #include <assert.h>
 
 #include <error.h>
+#include "options.h"
 #include "noreturn.h"
 #include "closeout.h"
 #include "str-list.h"
@@ -178,49 +178,6 @@ static int msgs_fuzzy;
 /* If not zero print statistics about translation at the end.  */
 static int do_statistics;
 
-/* Long options.  */
-static const struct option long_options[] =
-{
-  { "alignment", required_argument, NULL, 'a' },
-  { "check", no_argument, NULL, 'c' },
-  { "check-accelerators", optional_argument, NULL, CHAR_MAX + 1 },
-  { "check-compatibility", no_argument, NULL, 'C' },
-  { "check-domain", no_argument, NULL, CHAR_MAX + 2 },
-  { "check-format", no_argument, NULL, CHAR_MAX + 3 },
-  { "check-header", no_argument, NULL, CHAR_MAX + 4 },
-  { "csharp", no_argument, NULL, CHAR_MAX + 10 },
-  { "csharp-resources", no_argument, NULL, CHAR_MAX + 11 },
-  { "desktop", no_argument, NULL, CHAR_MAX + 15 },
-  { "directory", required_argument, NULL, 'D' },
-  { "endianness", required_argument, NULL, CHAR_MAX + 13 },
-  { "help", no_argument, NULL, 'h' },
-  { "java", no_argument, NULL, 'j' },
-  { "java2", no_argument, NULL, CHAR_MAX + 5 },
-  { "keyword", optional_argument, NULL, 'k' },
-  { "language", required_argument, NULL, 'L' },
-  { "locale", required_argument, NULL, 'l' },
-  { "no-convert", no_argument, NULL, CHAR_MAX + 17 },
-  { "no-hash", no_argument, NULL, CHAR_MAX + 6 },
-  { "no-redundancy", no_argument, NULL, CHAR_MAX + 18 },
-  { "output-file", required_argument, NULL, 'o' },
-  { "properties-input", no_argument, NULL, 'P' },
-  { "qt", no_argument, NULL, CHAR_MAX + 9 },
-  { "replace-text", no_argument, NULL, CHAR_MAX + 19 },
-  { "resource", required_argument, NULL, 'r' },
-  { "source", no_argument, NULL, CHAR_MAX + 14 },
-  { "statistics", no_argument, &do_statistics, 1 },
-  { "strict", no_argument, NULL, 'S' },
-  { "stringtable-input", no_argument, NULL, CHAR_MAX + 8 },
-  { "tcl", no_argument, NULL, CHAR_MAX + 7 },
-  { "template", required_argument, NULL, CHAR_MAX + 16 },
-  { "use-fuzzy", no_argument, NULL, 'f' },
-  { "use-untranslated", no_argument, NULL, CHAR_MAX + 12 },
-  { "verbose", no_argument, NULL, 'v' },
-  { "version", no_argument, NULL, 'V' },
-  { "xml", no_argument, NULL, 'x' },
-  { NULL, 0, NULL, 0 }
-};
-
 
 /* Forward declaration of local functions.  */
 _GL_NORETURN_FUNC static void usage (int status);
@@ -242,7 +199,6 @@ static int msgfmt_xml_bulk (const char *directory,
 int
 main (int argc, char *argv[])
 {
-  int opt;
   bool do_help = false;
   bool do_version = false;
   bool strict_uniforum = false;
@@ -274,12 +230,56 @@ main (int argc, char *argv[])
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
-  while ((opt = getopt_long (argc, argv, "a:cCd:D:fhjk::l:L:o:Pr:vVx",
-                             long_options, NULL))
-         != EOF)
+  /* Parse command line options.  */
+  BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
+  static const struct program_option options[] =
+  {
+    { "alignment",           'a',           required_argument },
+    { "check",               'c',           no_argument       },
+    { "check-accelerators",  CHAR_MAX + 1,  optional_argument },
+    { "check-compatibility", 'C',           no_argument       },
+    { "check-domain",        CHAR_MAX + 2,  no_argument       },
+    { "check-format",        CHAR_MAX + 3,  no_argument       },
+    { "check-header",        CHAR_MAX + 4,  no_argument       },
+    { "csharp",              CHAR_MAX + 10, no_argument       },
+    { "csharp-resources",    CHAR_MAX + 11, no_argument       },
+    { "desktop",             CHAR_MAX + 15, no_argument       },
+    { "directory",           'D',           required_argument },
+    { "endianness",          CHAR_MAX + 13, required_argument },
+    { "help",                'h',           no_argument       },
+    { "java",                'j',           no_argument       },
+    { "java2",               CHAR_MAX + 5,  no_argument       },
+    { "keyword",             'k',           optional_argument },
+    { "language",            'L',           required_argument },
+    { "locale",              'l',           required_argument },
+    { "no-convert",          CHAR_MAX + 17, no_argument       },
+    { "no-hash",             CHAR_MAX + 6,  no_argument       },
+    { "no-redundancy",       CHAR_MAX + 18, no_argument       },
+    { "output-file",         'o',           required_argument },
+    { "properties-input",    'P',           no_argument       },
+    { "qt",                  CHAR_MAX + 9,  no_argument       },
+    { "replace-text",        CHAR_MAX + 19, no_argument       },
+    { "resource",            'r',           required_argument },
+    { "source",              CHAR_MAX + 14, no_argument       },
+    { "statistics",          0,             no_argument,      &do_statistics, 1 },
+    { "strict",              CHAR_MAX + 20, no_argument       },
+    { "stringtable-input",   CHAR_MAX + 8,  no_argument       },
+    { "tcl",                 CHAR_MAX + 7,  no_argument       },
+    { "template",            CHAR_MAX + 16, required_argument },
+    { "use-fuzzy",           'f',           no_argument       },
+    { "use-untranslated",    CHAR_MAX + 12, no_argument       },
+    { "verbose",             'v',           no_argument       },
+    { "version",             'V',           no_argument       },
+    { "xml",                 'x',           no_argument       },
+    { NULL,                  'd',           required_argument },
+  };
+  END_ALLOW_OMITTING_FIELD_INITIALIZERS
+  start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
+  int opt;
+  while ((opt = get_next_option ()) != -1)
     switch (opt)
       {
-      case '\0':                /* Long option.  */
+      case '\0':                /* Long option with key == 0.  */
         break;
       case 'a':
         if (isdigit ((unsigned char) optarg[0]))
@@ -351,7 +351,7 @@ main (int argc, char *argv[])
         java_resource_name = optarg;
         csharp_resource_name = optarg;
         break;
-      case 'S':
+      case CHAR_MAX + 20: /* --strict */
         strict_uniforum = true;
         break;
       case 'v':
index 6a654678d943b450e9eabaa06837877792ea535b..b31b6f7574c9921efdef5dc984c46a6564d54cd8 100644 (file)
@@ -23,7 +23,6 @@
 
 #include <assert.h>
 #include <errno.h>
-#include <getopt.h>
 #include <limits.h>
 #include <locale.h>
 #include <stdio.h>
@@ -40,6 +39,7 @@
 #include <textstyle.h>
 
 #include <error.h>
+#include "options.h"
 #include "noreturn.h"
 #include "closeout.h"
 #include "dir-list.h"
@@ -91,46 +91,6 @@ struct grep_task {
 };
 static struct grep_task grep_task[5];
 
-/* Long options.  */
-static const struct option long_options[] =
-{
-  { "add-location", optional_argument, NULL, 'n' },
-  { "color", optional_argument, NULL, CHAR_MAX + 9 },
-  { "comment", no_argument, NULL, 'C' },
-  { "directory", required_argument, NULL, 'D' },
-  { "domain", required_argument, NULL, 'M' },
-  { "escape", no_argument, NULL, CHAR_MAX + 1 },
-  { "extended-regexp", no_argument, NULL, 'E' },
-  { "extracted-comment", no_argument, NULL, 'X' },
-  { "file", required_argument, NULL, 'f' },
-  { "fixed-strings", no_argument, NULL, 'F' },
-  { "force-po", no_argument, &force_po, 1 },
-  { "help", no_argument, NULL, 'h' },
-  { "ignore-case", no_argument, NULL, 'i' },
-  { "indent", no_argument, NULL, CHAR_MAX + 2 },
-  { "invert-match", no_argument, NULL, 'v' },
-  { "location", required_argument, NULL, 'N' },
-  { "msgctxt", no_argument, NULL, 'J' },
-  { "msgid", no_argument, NULL, 'K' },
-  { "msgstr", no_argument, NULL, 'T' },
-  { "no-escape", no_argument, NULL, CHAR_MAX + 3 },
-  { "no-location", no_argument, NULL, CHAR_MAX + 11 },
-  { "no-wrap", no_argument, NULL, CHAR_MAX + 6 },
-  { "output-file", required_argument, NULL, 'o' },
-  { "properties-input", no_argument, NULL, 'P' },
-  { "properties-output", no_argument, NULL, 'p' },
-  { "regexp", required_argument, NULL, 'e' },
-  { "sort-by-file", no_argument, NULL, CHAR_MAX + 4 },
-  { "sort-output", no_argument, NULL, CHAR_MAX + 5 },
-  { "strict", no_argument, NULL, 'S' },
-  { "stringtable-input", no_argument, NULL, CHAR_MAX + 7 },
-  { "stringtable-output", no_argument, NULL, CHAR_MAX + 8 },
-  { "style", required_argument, NULL, CHAR_MAX + 10 },
-  { "version", no_argument, NULL, 'V' },
-  { "width", required_argument, NULL, 'w' },
-  { NULL, 0, NULL, 0 }
-};
-
 
 /* Forward declaration of local functions.  */
 _GL_NORETURN_FUNC static void no_pass (int opt);
@@ -141,7 +101,6 @@ static msgdomain_list_ty *process_msgdomain_list (msgdomain_list_ty *mdlp);
 int
 main (int argc, char **argv)
 {
-  int opt;
   bool do_help;
   bool do_version;
   char *output_file;
@@ -191,12 +150,53 @@ main (int argc, char **argv)
       gt->case_insensitive = false;
     }
 
-  while ((opt = getopt_long (argc, argv, "CD:e:Ef:FhiJKM:nN:o:pPTvVw:X",
-                             long_options, NULL))
-         != EOF)
+  /* Parse command line options.  */
+  BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
+  static const struct program_option options[] =
+  {
+    { "add-location",       CHAR_MAX + 'n', optional_argument },
+    { NULL,                 'n',            no_argument       },
+    { "color",              CHAR_MAX + 9,   optional_argument },
+    { "comment",            'C',            no_argument       },
+    { "directory",          'D',            required_argument },
+    { "domain",             'M',            required_argument },
+    { "escape",             CHAR_MAX + 1,   no_argument       },
+    { "extended-regexp",    'E',            no_argument       },
+    { "extracted-comment",  'X',            no_argument       },
+    { "file",               'f',            required_argument },
+    { "fixed-strings",      'F',            no_argument       },
+    { "force-po",           0,              no_argument,      &force_po, 1 },
+    { "help",               'h',            no_argument       },
+    { "ignore-case",        'i',            no_argument       },
+    { "indent",             CHAR_MAX + 2,   no_argument       },
+    { "invert-match",       'v',            no_argument       },
+    { "location",           'N',            required_argument },
+    { "msgctxt",            'J',            no_argument       },
+    { "msgid",              'K',            no_argument       },
+    { "msgstr",             'T',            no_argument       },
+    { "no-escape",          CHAR_MAX + 3,   no_argument       },
+    { "no-location",        CHAR_MAX + 11,  no_argument       },
+    { "no-wrap",            CHAR_MAX + 6,   no_argument       },
+    { "output-file",        'o',            required_argument },
+    { "properties-input",   'P',            no_argument       },
+    { "properties-output",  'p',            no_argument       },
+    { "regexp",             'e',            required_argument },
+    { "sort-by-file",       CHAR_MAX + 4,   no_argument       },
+    { "sort-output",        CHAR_MAX + 5,   no_argument       },
+    { "strict",             CHAR_MAX + 12,  no_argument       },
+    { "stringtable-input",  CHAR_MAX + 7,   no_argument       },
+    { "stringtable-output", CHAR_MAX + 8,   no_argument       },
+    { "style",              CHAR_MAX + 10,  required_argument },
+    { "version",            'V',            no_argument       },
+    { "width",              'w',            required_argument },
+  };
+  END_ALLOW_OMITTING_FIELD_INITIALIZERS
+  start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
+  int opt;
+  while ((opt = get_next_option ()) != -1)
     switch (opt)
       {
-      case '\0':                /* Long option.  */
+      case '\0':                /* Long option with key == 0.  */
         break;
 
       case 'C':
@@ -305,7 +305,8 @@ main (int argc, char **argv)
         string_list_append (domain_names, optarg);
         break;
 
-      case 'n':
+      case 'n':            /* -n */
+      case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
         if (handle_filepos_comment_option (optarg))
           usage (EXIT_FAILURE);
         break;
@@ -326,7 +327,7 @@ main (int argc, char **argv)
         input_syntax = &input_format_properties;
         break;
 
-      case 'S':
+      case CHAR_MAX + 12: /* --strict */
         message_print_style_uniforum ();
         break;
 
index 0dabed15e47b04a2d03dcba64f1324e5d867a6c4..4182ec9e30585735b047e1b15cb43b87c395caaa 100644 (file)
@@ -24,7 +24,6 @@
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <getopt.h>
 #include <limits.h>
 #include <locale.h>
 #include <stdint.h>
@@ -42,7 +41,7 @@
 #include <textstyle.h>
 
 #include <error.h>
-
+#include "options.h"
 #include "noreturn.h"
 #include "closeout.h"
 #include "error-progname.h"
@@ -106,26 +105,6 @@ static const char *language;
 /* If true, the user is not considered to be the translator.  */
 static bool no_translator;
 
-/* Long options.  */
-static const struct option long_options[] =
-{
-  { "color", optional_argument, NULL, CHAR_MAX + 5 },
-  { "help", no_argument, NULL, 'h' },
-  { "input", required_argument, NULL, 'i' },
-  { "locale", required_argument, NULL, 'l' },
-  { "no-translator", no_argument, NULL, CHAR_MAX + 1 },
-  { "no-wrap", no_argument, NULL, CHAR_MAX + 2 },
-  { "output-file", required_argument, NULL, 'o' },
-  { "properties-input", no_argument, NULL, 'P' },
-  { "properties-output", no_argument, NULL, 'p' },
-  { "stringtable-input", no_argument, NULL, CHAR_MAX + 3 },
-  { "stringtable-output", no_argument, NULL, CHAR_MAX + 4 },
-  { "style", required_argument, NULL, CHAR_MAX + 6 },
-  { "version", no_argument, NULL, 'V' },
-  { "width", required_argument, NULL, 'w' },
-  { NULL, 0, NULL, 0 }
-};
-
 /* Forward declaration of local functions.  */
 _GL_NORETURN_FUNC static void usage (int status);
 static const char *find_pot (void);
@@ -139,7 +118,6 @@ static msgdomain_list_ty *update_msgstr_plurals (msgdomain_list_ty *mdlp);
 int
 main (int argc, char **argv)
 {
-  int opt;
   bool do_help;
   bool do_version;
   char *output_file;
@@ -172,11 +150,32 @@ main (int argc, char **argv)
   input_file = NULL;
   locale = NULL;
 
-  while ((opt = getopt_long (argc, argv, "hi:l:o:pPVw:", long_options, NULL))
-         != EOF)
+  /* Parse command line options.  */
+  BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
+  static const struct program_option options[] =
+  {
+    { "color",              CHAR_MAX + 5, optional_argument },
+    { "help",               'h',          no_argument       },
+    { "input",              'i',          required_argument },
+    { "locale",             'l',          required_argument },
+    { "no-translator",      CHAR_MAX + 1, no_argument       },
+    { "no-wrap",            CHAR_MAX + 2, no_argument       },
+    { "output-file",        'o',          required_argument },
+    { "properties-input",   'P',          no_argument       },
+    { "properties-output",  'p',          no_argument       },
+    { "stringtable-input",  CHAR_MAX + 3, no_argument       },
+    { "stringtable-output", CHAR_MAX + 4, no_argument       },
+    { "style",              CHAR_MAX + 6, required_argument },
+    { "version",            'V',          no_argument       },
+    { "width",              'w',          required_argument },
+  };
+  END_ALLOW_OMITTING_FIELD_INITIALIZERS
+  start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
+  int opt;
+  while ((opt = get_next_option ()) != -1)
     switch (opt)
       {
-      case '\0':                /* Long option.  */
+      case '\0':                /* Long option with key == 0.  */
         break;
 
       case 'h':
index 095c187539a0f8d7d8cc5a2c4d55158f74a09d3c..6e8afce04d2efc607990eca281efe3d4dfc02f76 100644 (file)
@@ -20,7 +20,6 @@
 #endif
 #include <alloca.h>
 
-#include <getopt.h>
 #include <limits.h>
 #include <stdbool.h>
 #include <stdio.h>
@@ -34,6 +33,7 @@
 #include <textstyle.h>
 
 #include <error.h>
+#include "options.h"
 #include "noreturn.h"
 #include "closeout.h"
 #include "dir-list.h"
@@ -120,45 +120,6 @@ static bool update_mode = false;
 static const char *version_control_string;
 static const char *backup_suffix_string;
 
-/* Long options.  */
-static const struct option long_options[] =
-{
-  { "add-location", optional_argument, NULL, 'n' },
-  { "backup", required_argument, NULL, CHAR_MAX + 1 },
-  { "color", optional_argument, NULL, CHAR_MAX + 9 },
-  { "compendium", required_argument, NULL, 'C' },
-  { "directory", required_argument, NULL, 'D' },
-  { "escape", no_argument, NULL, 'E' },
-  { "for-msgfmt", no_argument, NULL, CHAR_MAX + 12 },
-  { "force-po", no_argument, &force_po, 1 },
-  { "help", no_argument, NULL, 'h' },
-  { "indent", no_argument, NULL, 'i' },
-  { "lang", required_argument, NULL, CHAR_MAX + 8 },
-  { "multi-domain", no_argument, NULL, 'm' },
-  { "no-escape", no_argument, NULL, 'e' },
-  { "no-fuzzy-matching", no_argument, NULL, 'N' },
-  { "no-location", no_argument, NULL, CHAR_MAX + 11 },
-  { "no-wrap", no_argument, NULL, CHAR_MAX + 4 },
-  { "output-file", required_argument, NULL, 'o' },
-  { "previous", no_argument, NULL, CHAR_MAX + 7 },
-  { "properties-input", no_argument, NULL, 'P' },
-  { "properties-output", no_argument, NULL, 'p' },
-  { "quiet", no_argument, NULL, 'q' },
-  { "sort-by-file", no_argument, NULL, 'F' },
-  { "sort-output", no_argument, NULL, 's' },
-  { "silent", no_argument, NULL, 'q' },
-  { "strict", no_argument, NULL, CHAR_MAX + 2 },
-  { "stringtable-input", no_argument, NULL, CHAR_MAX + 5 },
-  { "stringtable-output", no_argument, NULL, CHAR_MAX + 6 },
-  { "style", required_argument, NULL, CHAR_MAX + 10 },
-  { "suffix", required_argument, NULL, CHAR_MAX + 3 },
-  { "update", no_argument, NULL, 'U' },
-  { "verbose", no_argument, NULL, 'v' },
-  { "version", no_argument, NULL, 'V' },
-  { "width", required_argument, NULL, 'w' },
-  { NULL, 0, NULL, 0 }
-};
-
 
 struct statistics
 {
@@ -181,7 +142,6 @@ static msgdomain_list_ty *merge (const char *fn1, const char *fn2,
 int
 main (int argc, char **argv)
 {
-  int opt;
   bool do_help;
   bool do_version;
   char *output_file;
@@ -218,12 +178,52 @@ main (int argc, char **argv)
   output_file = NULL;
   color = NULL;
 
-  while ((opt = getopt_long (argc, argv, "C:D:eEFhimnNo:pPqsUvVw:",
-                             long_options, NULL))
-         != EOF)
+  /* Parse command line options.  */
+  BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
+  static const struct program_option options[] =
+  {
+    { "add-location",       CHAR_MAX + 'n', optional_argument },
+    { NULL,                 'n',            no_argument       },
+    { "backup",             CHAR_MAX + 1,   required_argument },
+    { "color",              CHAR_MAX + 9,   optional_argument },
+    { "compendium",         'C',            required_argument },
+    { "directory",          'D',            required_argument },
+    { "escape",             'E',            no_argument       },
+    { "for-msgfmt",         CHAR_MAX + 12,  no_argument       },
+    { "force-po",           0,              no_argument,      &force_po, 1 },
+    { "help",               'h',            no_argument       },
+    { "indent",             'i',            no_argument       },
+    { "lang",               CHAR_MAX + 8,   required_argument },
+    { "multi-domain",       'm',            no_argument       },
+    { "no-escape",          'e',            no_argument       },
+    { "no-fuzzy-matching",  'N',            no_argument       },
+    { "no-location",        CHAR_MAX + 11,  no_argument       },
+    { "no-wrap",            CHAR_MAX + 4,   no_argument       },
+    { "output-file",        'o',            required_argument },
+    { "previous",           CHAR_MAX + 7,   no_argument       },
+    { "properties-input",   'P',            no_argument       },
+    { "properties-output",  'p',            no_argument       },
+    { "quiet",              'q',            no_argument       },
+    { "sort-by-file",       'F',            no_argument       },
+    { "sort-output",        's',            no_argument       },
+    { "silent",             'q',            no_argument       },
+    { "strict",             CHAR_MAX + 2,   no_argument       },
+    { "stringtable-input",  CHAR_MAX + 5,   no_argument       },
+    { "stringtable-output", CHAR_MAX + 6,   no_argument       },
+    { "style",              CHAR_MAX + 10,  required_argument },
+    { "suffix",             CHAR_MAX + 3,   required_argument },
+    { "update",             'U',            no_argument       },
+    { "verbose",            'v',            no_argument       },
+    { "version",            'V',            no_argument       },
+    { "width",              'w',            required_argument },
+  };
+  END_ALLOW_OMITTING_FIELD_INITIALIZERS
+  start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
+  int opt;
+  while ((opt = get_next_option ()) != -1)
     switch (opt)
       {
-      case '\0':                /* Long option.  */
+      case '\0':                /* Long option with key == 0.  */
         break;
 
       case 'C':
@@ -258,7 +258,8 @@ main (int argc, char **argv)
         multi_domain_mode = true;
         break;
 
-      case 'n':
+      case 'n':            /* -n */
+      case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
         if (handle_filepos_comment_option (optarg))
           usage (EXIT_FAILURE);
         break;
index 2724fb4ffd59208c37e2c301d4dd32df07ce116e..3777dcd91ea0cc7ef77cb67ca788ce230d7eceaa 100644 (file)
@@ -19,7 +19,6 @@
 # include <config.h>
 #endif
 
-#include <getopt.h>
 #include <limits.h>
 #include <stdbool.h>
 #include <stdio.h>
@@ -29,6 +28,7 @@
 #include <textstyle.h>
 
 #include <error.h>
+#include "options.h"
 #include "noreturn.h"
 #include "closeout.h"
 #include "error-progname.h"
@@ -78,34 +78,6 @@ static const char *tcl_base_directory;
 /* Force output of PO file even if empty.  */
 static int force_po;
 
-/* Long options.  */
-static const struct option long_options[] =
-{
-  { "color", optional_argument, NULL, CHAR_MAX + 6 },
-  { "csharp", no_argument, NULL, CHAR_MAX + 4 },
-  { "csharp-resources", no_argument, NULL, CHAR_MAX + 5 },
-  { "escape", no_argument, NULL, 'E' },
-  { "force-po", no_argument, &force_po, 1 },
-  { "help", no_argument, NULL, 'h' },
-  { "indent", no_argument, NULL, 'i' },
-  { "java", no_argument, NULL, 'j' },
-  { "locale", required_argument, NULL, 'l' },
-  { "no-escape", no_argument, NULL, 'e' },
-  { "no-wrap", no_argument, NULL, CHAR_MAX + 2 },
-  { "output-file", required_argument, NULL, 'o' },
-  { "properties-output", no_argument, NULL, 'p' },
-  { "resource", required_argument, NULL, 'r' },
-  { "sort-output", no_argument, NULL, 's' },
-  { "strict", no_argument, NULL, 'S' },
-  { "stringtable-output", no_argument, NULL, CHAR_MAX + 3 },
-  { "style", required_argument, NULL, CHAR_MAX + 7 },
-  { "tcl", no_argument, NULL, CHAR_MAX + 1 },
-  { "verbose", no_argument, NULL, 'v' },
-  { "version", no_argument, NULL, 'V' },
-  { "width", required_argument, NULL, 'w' },
-  { NULL, 0, NULL, 0 }
-};
-
 
 /* Forward declaration of local functions.  */
 _GL_NORETURN_FUNC static void usage (int status);
@@ -115,7 +87,6 @@ static void read_one_file (message_list_ty *mlp, const char *filename);
 int
 main (int argc, char **argv)
 {
-  int optchar;
   bool do_help = false;
   bool do_version = false;
   const char *output_file = "-";
@@ -139,13 +110,41 @@ main (int argc, char **argv)
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
-  while ((optchar = getopt_long (argc, argv, "d:eEhijl:o:pr:svVw:",
-                                 long_options, NULL))
-         != EOF)
+  /* Parse command line options.  */
+  BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
+  static const struct program_option options[] =
+  {
+    { "color",              CHAR_MAX + 6, optional_argument },
+    { "csharp",             CHAR_MAX + 4, no_argument       },
+    { "csharp-resources",   CHAR_MAX + 5, no_argument       },
+    { "escape",             'E',          no_argument       },
+    { "force-po",           0,            no_argument,      &force_po, 1 },
+    { "help",               'h',          no_argument       },
+    { "indent",             'i',          no_argument       },
+    { "java",               'j',          no_argument       },
+    { "locale",             'l',          required_argument },
+    { "no-escape",          'e',          no_argument       },
+    { "no-wrap",            CHAR_MAX + 2, no_argument       },
+    { "output-file",        'o',          required_argument },
+    { "properties-output",  'p',          no_argument       },
+    { "resource",           'r',          required_argument },
+    { "sort-output",        's',          no_argument       },
+    { "strict",             CHAR_MAX + 8, no_argument       },
+    { "stringtable-output", CHAR_MAX + 3, no_argument       },
+    { "style",              CHAR_MAX + 7, required_argument },
+    { "tcl",                CHAR_MAX + 1, no_argument       },
+    { "verbose",            'v',          no_argument       },
+    { "version",            'V',          no_argument       },
+    { "width",              'w',          required_argument },
+    { NULL,                 'd',          required_argument },
+  };
+  END_ALLOW_OMITTING_FIELD_INITIALIZERS
+  start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
+  int optchar;
+  while ((optchar = get_next_option ()) != -1)
     switch (optchar)
       {
-      case '\0':
-        /* long option */
+      case '\0':                /* Long option with key == 0.  */
         break;
 
       case 'd':
@@ -196,7 +195,7 @@ main (int argc, char **argv)
         sort_by_msgid = true;
         break;
 
-      case 'S':
+      case CHAR_MAX + 8: /* --strict */
         message_print_style_uniforum ();
         break;
 
index a085152a81bf63001fc87e65ddaaea8aab60b9ff..38be7b8c0b813626cf98fe4470d42df34c17a389 100644 (file)
@@ -20,7 +20,6 @@
 # include "config.h"
 #endif
 
-#include <getopt.h>
 #include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -29,6 +28,7 @@
 #include <textstyle.h>
 
 #include <error.h>
+#include "options.h"
 #include "noreturn.h"
 #include "closeout.h"
 #include "dir-list.h"
@@ -60,37 +60,6 @@ static int force_po;
 /* Target encoding.  */
 static const char *to_code;
 
-/* Long options.  */
-static const struct option long_options[] =
-{
-  { "add-location", optional_argument, NULL, 'n' },
-  { "color", optional_argument, NULL, CHAR_MAX + 5 },
-  { "directory", required_argument, NULL, 'D' },
-  { "escape", no_argument, NULL, 'E' },
-  { "force-po", no_argument, &force_po, 1 },
-  { "help", no_argument, NULL, 'h' },
-  { "indent", no_argument, NULL, 'i' },
-  { "no-escape", no_argument, NULL, 'e' },
-  { "no-location", no_argument, NULL, CHAR_MAX + 7 },
-  { "no-wrap", no_argument, NULL, CHAR_MAX + 2 },
-  { "output-file", required_argument, NULL, 'o' },
-  { "properties-input", no_argument, NULL, 'P' },
-  { "properties-output", no_argument, NULL, 'p' },
-  { "repeated", no_argument, NULL, 'd' },
-  { "sort-by-file", no_argument, NULL, 'F' },
-  { "sort-output", no_argument, NULL, 's' },
-  { "strict", no_argument, NULL, 'S' },
-  { "stringtable-input", no_argument, NULL, CHAR_MAX + 3 },
-  { "stringtable-output", no_argument, NULL, CHAR_MAX + 4 },
-  { "style", required_argument, NULL, CHAR_MAX + 6 },
-  { "to-code", required_argument, NULL, 't' },
-  { "unique", no_argument, NULL, 'u' },
-  { "use-first", no_argument, NULL, CHAR_MAX + 1 },
-  { "version", no_argument, NULL, 'V' },
-  { "width", required_argument, NULL, 'w' },
-  { NULL, 0, NULL, 0 }
-};
-
 
 /* Forward declaration of local functions.  */
 _GL_NORETURN_FUNC static void usage (int status);
@@ -99,7 +68,6 @@ _GL_NORETURN_FUNC static void usage (int status);
 int
 main (int argc, char **argv)
 {
-  int optchar;
   bool do_help;
   bool do_version;
   char *output_file;
@@ -137,11 +105,44 @@ main (int argc, char **argv)
   less_than = INT_MAX;
   use_first = false;
 
-  while ((optchar = getopt_long (argc, argv, "dD:eEFhino:pPst:uVw:",
-                                 long_options, NULL)) != EOF)
+  /* Parse command line options.  */
+  BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
+  static const struct program_option options[] =
+  {
+    { "add-location",       CHAR_MAX + 'n', optional_argument },
+    { NULL,                 'n',            no_argument       },
+    { "color",              CHAR_MAX + 5,   optional_argument },
+    { "directory",          'D',            required_argument },
+    { "escape",             'E',            no_argument       },
+    { "force-po",           0,              no_argument,      &force_po, 1 },
+    { "help",               'h',            no_argument       },
+    { "indent",             'i',            no_argument       },
+    { "no-escape",          'e',            no_argument       },
+    { "no-location",        CHAR_MAX + 7,   no_argument       },
+    { "no-wrap",            CHAR_MAX + 2,   no_argument       },
+    { "output-file",        'o',            required_argument },
+    { "properties-input",   'P',            no_argument       },
+    { "properties-output",  'p',            no_argument       },
+    { "repeated",           'd',            no_argument       },
+    { "sort-by-file",       'F',            no_argument       },
+    { "sort-output",        's',            no_argument       },
+    { "strict",             CHAR_MAX + 8,   no_argument       },
+    { "stringtable-input",  CHAR_MAX + 3,   no_argument       },
+    { "stringtable-output", CHAR_MAX + 4,   no_argument       },
+    { "style",              CHAR_MAX + 6,   required_argument },
+    { "to-code",            't',            required_argument },
+    { "unique",             'u',            no_argument       },
+    { "use-first",          CHAR_MAX + 1,   no_argument       },
+    { "version",            'V',            no_argument       },
+    { "width",              'w',            required_argument },
+  };
+  END_ALLOW_OMITTING_FIELD_INITIALIZERS
+  start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
+  int optchar;
+  while ((optchar = get_next_option ()) != -1)
     switch (optchar)
       {
-      case '\0':                /* Long option.  */
+      case '\0':                /* Long option with key == 0.  */
         break;
 
       case 'd':
@@ -173,7 +174,8 @@ main (int argc, char **argv)
         message_print_style_indent ();
         break;
 
-      case 'n':
+      case 'n':            /* -n */
+      case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
         if (handle_filepos_comment_option (optarg))
           usage (EXIT_FAILURE);
         break;
@@ -194,7 +196,7 @@ main (int argc, char **argv)
         sort_by_msgid = true;
         break;
 
-      case 'S':
+      case CHAR_MAX + 8: /* --strict */
         message_print_style_uniforum ();
         break;
 
index 50292ce97313b92a48a592874910d916abda32cd..0ff4162b43c0f6ea25e6c6ac98eb4837e34ae965 100644 (file)
@@ -20,7 +20,6 @@
 #endif
 
 #include <errno.h>
-#include <getopt.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -31,6 +30,7 @@
 #endif
 
 #include <error.h>
+#include "options.h"
 #include "noreturn.h"
 #include "closeout.h"
 #include "progname.h"
 #define _(str) gettext (str)
 
 
-/* Long options.  */
-static const struct option long_options[] =
-{
-  { "help", no_argument, NULL, 'h' },
-  { "version", no_argument, NULL, 'V' },
-  { NULL, 0, NULL, 0 }
-};
-
 /* Forward declaration of local functions.  */
 _GL_NORETURN_FUNC static void usage (int status);
 static void process (FILE *stream);
@@ -66,8 +58,6 @@ main (int argc, char *argv[])
   bool do_help = false;
   bool do_version = false;
 
-  int opt;
-
   /* Set program name for message texts.  */
   set_program_name (argv[0]);
 
@@ -83,10 +73,19 @@ main (int argc, char *argv[])
   atexit (close_stdout);
 
   /* Parse command line options.  */
-  while ((opt = getopt_long (argc, argv, "hV", long_options, NULL)) != EOF)
+  BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
+  static const struct program_option options[] =
+  {
+    { "help",    'h', no_argument },
+    { "version", 'V', no_argument },
+  };
+  END_ALLOW_OMITTING_FIELD_INITIALIZERS
+  start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
+  int opt;
+  while ((opt = get_next_option ()) != -1)
     switch (opt)
       {
-      case '\0':          /* Long option.  */
+      case '\0':          /* Long option with key == 0.  */
         break;
       case 'h':
         do_help = true;
index c1ade19eb733c64eb38eeab1555e5bc781a2a4a5..16941294d6a49ae5c5d33d7091852ad081891904 100644 (file)
@@ -22,7 +22,6 @@
 
 #include <errno.h>
 #include <fcntl.h>
-#include <getopt.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -30,6 +29,7 @@
 #include <unistd.h>
 
 #include <error.h>
+#include "options.h"
 #include "noreturn.h"
 #include "closeout.h"
 #include "error-progname.h"
    produces no output for more than 10 seconds for no apparent reason.  */
 static bool verbose = true;
 
-/* Long options.  */
-static const struct option long_options[] =
-{
-  { "help", no_argument, NULL, 'h' },
-  { "quiet", no_argument, NULL, 'q' },
-  { "silent", no_argument, NULL, 'q' },
-  { "version", no_argument, NULL, 'V' },
-  { NULL, 0, NULL, 0 }
-};
-
 
 /* Forward declaration of local functions.  */
 _GL_NORETURN_FUNC static void usage (int status);
@@ -88,7 +78,6 @@ static void fetch (const char *url, const char *file);
 int
 main (int argc, char *argv[])
 {
-  int optchar;
   bool do_help;
   bool do_version;
 
@@ -112,10 +101,21 @@ main (int argc, char *argv[])
   do_version = false;
 
   /* Parse command line options.  */
-  while ((optchar = getopt_long (argc, argv, "hqV", long_options, NULL)) != EOF)
+  BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
+  static const struct program_option options[] =
+  {
+    { "help",    'h', no_argument },
+    { "quiet",   'q', no_argument },
+    { "silent",  'q', no_argument },
+    { "version", 'V', no_argument },
+  };
+  END_ALLOW_OMITTING_FIELD_INITIALIZERS
+  start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
+  int optchar;
+  while ((optchar = get_next_option ()) != -1)
     switch (optchar)
       {
-      case '\0':          /* Long option.  */
+      case '\0':          /* Long option with key == 0.  */
         break;
       case 'h':           /* --help */
         do_help = true;
index 1671ff96cabc14e621b777d6140d80c297b43151..c10186db12519534a25a48530d21b591f14d1703 100644 (file)
@@ -25,7 +25,6 @@
 
 #include <ctype.h>
 #include <errno.h>
-#include <getopt.h>
 #include <stdio.h>
 #include <time.h>
 #include <stdlib.h>
@@ -43,6 +42,7 @@
 #include <textstyle.h>
 
 #include <error.h>
+#include "options.h"
 #include "noreturn.h"
 #include "rc-str-list.h"
 #include "xg-encoding.h"
@@ -260,66 +260,6 @@ static string_list_ty files_for_vc_mtime;
    shall be ignored.  */
 static gl_set_t generated_files;
 
-/* Long options.  */
-static const struct option long_options[] =
-{
-  { "add-comments", optional_argument, NULL, 'c' },
-  { "add-location", optional_argument, NULL, 'n' },
-  { "boost", no_argument, NULL, CHAR_MAX + 11 },
-  { "c++", no_argument, NULL, 'C' },
-  { "check", required_argument, NULL, CHAR_MAX + 17 },
-  { "color", optional_argument, NULL, CHAR_MAX + 14 },
-  { "copyright-holder", required_argument, NULL, CHAR_MAX + 1 },
-  { "debug", no_argument, &do_debug, 1 },
-  { "default-domain", required_argument, NULL, 'd' },
-  { "directory", required_argument, NULL, 'D' },
-  { "escape", no_argument, NULL, 'E' },
-  { "exclude-file", required_argument, NULL, 'x' },
-  { "extract-all", no_argument, NULL, 'a' },
-  { "files-from", required_argument, NULL, 'f' },
-  { "flag", required_argument, NULL, CHAR_MAX + 8 },
-  { "force-po", no_argument, &force_po, 1 },
-  { "foreign-user", no_argument, NULL, CHAR_MAX + 2 },
-  { "from-code", required_argument, NULL, CHAR_MAX + 3 },
-  { "generated", required_argument, NULL, CHAR_MAX + 24 },
-  { "help", no_argument, NULL, 'h' },
-  { "indent", no_argument, NULL, 'i' },
-  { "its", required_argument, NULL, CHAR_MAX + 20 },
-  { "itstool", no_argument, NULL, CHAR_MAX + 19 },
-  { "join-existing", no_argument, NULL, 'j' },
-  { "kde", no_argument, NULL, CHAR_MAX + 10 },
-  { "keyword", optional_argument, NULL, 'k' },
-  { "language", required_argument, NULL, 'L' },
-  { "msgid-bugs-address", required_argument, NULL, CHAR_MAX + 5 },
-  { "msgstr-prefix", optional_argument, NULL, 'm' },
-  { "msgstr-suffix", optional_argument, NULL, 'M' },
-  { "no-escape", no_argument, NULL, 'e' },
-  { "no-git", no_argument, NULL, CHAR_MAX + 23 },
-  { "no-location", no_argument, NULL, CHAR_MAX + 16 },
-  { "no-wrap", no_argument, NULL, CHAR_MAX + 4 },
-  { "omit-header", no_argument, &xgettext_omit_header, 1 },
-  { "output", required_argument, NULL, 'o' },
-  { "output-dir", required_argument, NULL, 'p' },
-  { "package-name", required_argument, NULL, CHAR_MAX + 12 },
-  { "package-version", required_argument, NULL, CHAR_MAX + 13 },
-  { "properties-output", no_argument, NULL, CHAR_MAX + 6 },
-  { "qt", no_argument, NULL, CHAR_MAX + 9 },
-  { "reference", required_argument, NULL, CHAR_MAX + 22 },
-  { "sentence-end", required_argument, NULL, CHAR_MAX + 18 },
-  { "sort-by-file", no_argument, NULL, 'F' },
-  { "sort-output", no_argument, NULL, 's' },
-  { "strict", no_argument, NULL, 'S' },
-  { "string-limit", required_argument, NULL, 'l' },
-  { "stringtable-output", no_argument, NULL, CHAR_MAX + 7 },
-  { "style", required_argument, NULL, CHAR_MAX + 15 },
-  { "tag", required_argument, NULL, CHAR_MAX + 21 },
-  { "trigraphs", no_argument, NULL, 'T' },
-  { "verbose", no_argument, NULL, 'v' },
-  { "version", no_argument, NULL, 'V' },
-  { "width", required_argument, NULL, 'w' },
-  { NULL, 0, NULL, 0 }
-};
-
 
 /* The extractors must all be functions returning void and taking as arguments
    - the file name or file stream,
@@ -364,7 +304,6 @@ static const char *extension_to_language (const char *extension);
 int
 main (int argc, char *argv[])
 {
-  int optchar;
   bool do_help = false;
   bool do_version = false;
   msgdomain_list_ty *mdlp;
@@ -437,12 +376,74 @@ main (int argc, char *argv[])
   init_flag_table_gcc_internal ();
   init_flag_table_ycp ();
 
-  while ((optchar = getopt_long (argc, argv,
-                                 "ac::Cd:D:eEf:Fhijk::l:L:m::M::no:p:sTvVw:x:",
-                                 long_options, NULL)) != EOF)
+  /* Parse command line options.  */
+  BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
+  static const struct program_option options[] =
+  {
+    { "add-comments",       'c',            optional_argument },
+    { "add-location",       CHAR_MAX + 'n', optional_argument },
+    { NULL,                 'n',            no_argument       },
+    { "boost",              CHAR_MAX + 11,  no_argument       },
+    { "c++",                'C',            no_argument       },
+    { "check",              CHAR_MAX + 17,  required_argument },
+    { "color",              CHAR_MAX + 14,  optional_argument },
+    { "copyright-holder",   CHAR_MAX + 1,   required_argument },
+    { "debug",              0,              no_argument,      &do_debug, 1 },
+    { "default-domain",     'd',            required_argument },
+    { "directory",          'D',            required_argument },
+    { "escape",             'E',            no_argument       },
+    { "exclude-file",       'x',            required_argument },
+    { "extract-all",        'a',            no_argument       },
+    { "files-from",         'f',            required_argument },
+    { "flag",               CHAR_MAX + 8,   required_argument },
+    { "force-po",           0,              no_argument,      &force_po, 1 },
+    { "foreign-user",       CHAR_MAX + 2,   no_argument       },
+    { "from-code",          CHAR_MAX + 3,   required_argument },
+    { "generated",          CHAR_MAX + 24,  required_argument },
+    { "help",               'h',            no_argument       },
+    { "indent",             'i',            no_argument       },
+    { "its",                CHAR_MAX + 20,  required_argument },
+    { "itstool",            CHAR_MAX + 19,  no_argument       },
+    { "join-existing",      'j',            no_argument       },
+    { "kde",                CHAR_MAX + 10,  no_argument       },
+    { "keyword",            'k',            optional_argument },
+    { "language",           'L',            required_argument },
+    { "msgid-bugs-address", CHAR_MAX + 5,   required_argument },
+    { "msgstr-prefix",      'm',            optional_argument },
+    { "msgstr-suffix",      'M',            optional_argument },
+    { "no-escape",          'e',            no_argument       },
+    { "no-git",             CHAR_MAX + 23,  no_argument       },
+    { "no-location",        CHAR_MAX + 16,  no_argument       },
+    { "no-wrap",            CHAR_MAX + 4,   no_argument       },
+    { "omit-header",        0,              no_argument,      &xgettext_omit_header, 1 },
+    { "output",             'o',            required_argument },
+    { "output-dir",         'p',            required_argument },
+    { "package-name",       CHAR_MAX + 12,  required_argument },
+    { "package-version",    CHAR_MAX + 13,  required_argument },
+    { "properties-output",  CHAR_MAX + 6,   no_argument       },
+    { "qt",                 CHAR_MAX + 9,   no_argument       },
+    { "reference",          CHAR_MAX + 22,  required_argument },
+    { "sentence-end",       CHAR_MAX + 18,  required_argument },
+    { "sort-by-file",       'F',            no_argument       },
+    { "sort-output",        's',            no_argument       },
+    { "strict",             CHAR_MAX + 25,  no_argument       },
+    { "string-limit",       'l',            required_argument },
+    { "stringtable-output", CHAR_MAX + 7,   no_argument       },
+    { "style",              CHAR_MAX + 15,  required_argument },
+    { "tag",                CHAR_MAX + 21,  required_argument },
+    { "trigraphs",          'T',            no_argument       },
+    { "verbose",            'v',            no_argument       },
+    { "version",            'V',            no_argument       },
+    { "width",              'w',            required_argument },
+    { NULL,                 'W',            required_argument },
+  };
+  END_ALLOW_OMITTING_FIELD_INITIALIZERS
+  start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
+  int optchar;
+  while ((optchar = get_next_option ()) != -1)
     switch (optchar)
       {
-      case '\0':                /* Long option.  */
+      case '\0':                /* Long option with key == 0.  */
         break;
 
       case 'a':
@@ -580,7 +581,8 @@ main (int argc, char *argv[])
         msgstr_suffix = optarg == NULL ? "" : optarg;
         break;
 
-      case 'n':
+      case 'n':            /* -n */
+      case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
         if (handle_filepos_comment_option (optarg))
           usage (EXIT_FAILURE);
         break;
@@ -607,7 +609,7 @@ main (int argc, char *argv[])
         sort_by_msgid = true;
         break;
 
-      case 'S':
+      case CHAR_MAX + 25: /* --strict */
         message_print_style_uniforum ();
         break;
 
index a0989dd2a8575ddd39fec7072b6198f2da5851ce..cd97be1d561977f69f832c8e49798efa38c5b78c 100644 (file)
@@ -1,5 +1,5 @@
 /* gettext - retrieve text string from message catalog and print it.
-   Copyright (C) 1995-2024 Free Software Foundation, Inc.
+   Copyright (C) 1995-2025 Free Software Foundation, Inc.
    Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, May 1995.
 
    This program is free software: you can redistribute it and/or modify
@@ -19,7 +19,7 @@
 # include <config.h>
 #endif
 
-#include <getopt.h>
+#include <limits.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -27,6 +27,7 @@
 #include <locale.h>
 
 #include <error.h>
+#include "options.h"
 #include "attribute.h"
 #include "noreturn.h"
 #include "closeout.h"
@@ -51,18 +52,6 @@ extern char *setlocale (int category, const char *locale);
 
 #define _(str) gettext (str)
 
-/* Long options.  */
-static const struct option long_options[] =
-{
-  { "domain", required_argument, NULL, 'd' },
-  { "env", required_argument, NULL, '=' },
-  { "help", no_argument, NULL, 'h' },
-  { "shell-script", no_argument, NULL, 's' },
-  { "thread", no_argument, NULL, 't' },
-  { "version", no_argument, NULL, 'V' },
-  { NULL, 0, NULL, 0 }
-};
-
 /* Forward declaration of local functions.  */
 _GL_NORETURN_FUNC static void *worker_thread (void *arg);
 _GL_NORETURN_FUNC static void usage (int status);
@@ -86,8 +75,6 @@ struct worker_context
 int
 main (int argc, char *argv[])
 {
-  int optchar;
-
   /* Default values for command line options.  */
   bool do_help = false;
   bool do_thread = false;
@@ -116,11 +103,26 @@ main (int argc, char *argv[])
   atexit (close_stdout);
 
   /* Parse command line options.  */
-  while ((optchar = getopt_long (argc, argv, "+d:eEhnstV", long_options, NULL))
-         != EOF)
+  BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
+  static const struct program_option options[] =
+  {
+    { "domain",       'd',          required_argument },
+    { "env",          CHAR_MAX + 1, required_argument },
+    { "help",         'h',          no_argument       },
+    { "shell-script", 's',          no_argument       },
+    { "thread",       't',          no_argument       },
+    { "version",      'V',          no_argument       },
+    { NULL,           'e',          no_argument       },
+    { NULL,           'E',          no_argument       },
+    { NULL,           'n',          no_argument       },
+  };
+  END_ALLOW_OMITTING_FIELD_INITIALIZERS
+  start_options (argc, argv, options, NON_OPTION_TERMINATES_OPTIONS, 0);
+  int optchar;
+  while ((optchar = get_next_option ()) != -1)
     switch (optchar)
       {
-      case '\0':          /* Long option.  */
+      case '\0':          /* Long option with key == 0.  */
         break;
       case 'd':
         context.domain = optarg;
@@ -146,7 +148,7 @@ main (int argc, char *argv[])
       case 'V':
         do_version = true;
         break;
-      case '=':
+      case CHAR_MAX + 1: /* --env */
         {
           /* Undocumented option --env sets an environment variable.  */
           char *separator = strchr (optarg, '=');
index 7af6c38cd3b79bcc5b12d117ae2a6d371418680a..5efe49d54922e67698aa717cdd6aeea946611454 100644 (file)
@@ -18,7 +18,7 @@
 # include <config.h>
 #endif
 
-#include <getopt.h>
+#include <limits.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -28,6 +28,7 @@
 #include <errno.h>
 
 #include <error.h>
+#include "options.h"
 #include "attribute.h"
 #include "noreturn.h"
 #include "closeout.h"
@@ -50,17 +51,6 @@ extern char *setlocale (int category, const char *locale);
 
 #define _(str) gettext (str)
 
-/* Long options.  */
-static const struct option long_options[] =
-{
-  { "domain", required_argument, NULL, 'd' },
-  { "env", required_argument, NULL, '=' },
-  { "help", no_argument, NULL, 'h' },
-  { "thread", no_argument, NULL, 't' },
-  { "version", no_argument, NULL, 'V' },
-  { NULL, 0, NULL, 0 }
-};
-
 /* Forward declaration of local functions.  */
 _GL_NORETURN_FUNC static void *worker_thread (void *arg);
 _GL_NORETURN_FUNC static void usage (int __status);
@@ -77,8 +67,6 @@ struct worker_context
 int
 main (int argc, char *argv[])
 {
-  int optchar;
-
   /* Default values for command line options.  */
   bool do_help = false;
   bool do_thread = false;
@@ -104,11 +92,22 @@ main (int argc, char *argv[])
   atexit (close_stdout);
 
   /* Parse command line options.  */
-  while ((optchar = getopt_long (argc, argv, "+d:htV", long_options, NULL))
-         != EOF)
+  BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
+  static const struct program_option options[] =
+  {
+    { "domain",  'd',          required_argument },
+    { "env",     CHAR_MAX + 1, required_argument },
+    { "help",    'h',          no_argument       },
+    { "thread",  't',          no_argument       },
+    { "version", 'V',          no_argument       },
+  };
+  END_ALLOW_OMITTING_FIELD_INITIALIZERS
+  start_options (argc, argv, options, NON_OPTION_TERMINATES_OPTIONS, 0);
+  int optchar;
+  while ((optchar = get_next_option ()) != -1)
     switch (optchar)
       {
-      case '\0':          /* Long option.  */
+      case '\0':          /* Long option with key == 0.  */
         break;
       case 'd':
         context.domain = optarg;
@@ -122,7 +121,7 @@ main (int argc, char *argv[])
       case 'V':
         do_version = true;
         break;
-      case '=':
+      case CHAR_MAX + 1: /* --env */
         {
           /* Undocumented option --env sets an environment variable.  */
           char *separator = strchr (optarg, '=');