diff options
Diffstat (limited to 'src/msgunfmt.c')
-rw-r--r-- | src/msgunfmt.c | 102 |
1 files changed, 92 insertions, 10 deletions
diff --git a/src/msgunfmt.c b/src/msgunfmt.c index c44aba4..14c8a8b 100644 --- a/src/msgunfmt.c +++ b/src/msgunfmt.c @@ -21,6 +21,7 @@ #endif #include <getopt.h> +#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <locale.h> @@ -29,13 +30,23 @@ #include "progname.h" #include "system.h" #include "message.h" +#include "msgunfmt.h" #include "read-mo.h" +#include "read-java.h" #include "write-po.h" #include "libgettext.h" #define _(str) gettext (str) +/* Be more verbose. */ +bool verbose; + +/* Java mode input file specification. */ +static bool java_mode; +static const char *java_resource_name; +static const char *java_locale_name; + /* Force output of PO file even if empty. */ static int force_po; @@ -46,10 +57,14 @@ static const struct option long_options[] = { "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' }, { "output-file", required_argument, NULL, 'o' }, + { "resource", required_argument, NULL, 'r' }, { "sort-output", no_argument, NULL, 's' }, { "strict", no_argument, NULL, 'S' }, + { "verbose", no_argument, NULL, 'v' }, { "version", no_argument, NULL, 'V' }, { "width", required_argument, NULL, 'w', }, { NULL, 0, NULL, 0 } @@ -70,7 +85,6 @@ main (argc, argv) bool do_help = false; bool do_version = false; const char *output_file = "-"; - message_list_ty *mlp; msgdomain_list_ty *result; bool sort_by_msgid = false; @@ -87,7 +101,8 @@ main (argc, argv) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); - while ((optchar = getopt_long (argc, argv, "eEhio:sVw:", long_options, NULL)) + while ((optchar = getopt_long (argc, argv, "eEhijl:o:r:svVw:", long_options, + NULL)) != EOF) switch (optchar) { @@ -111,10 +126,22 @@ main (argc, argv) message_print_style_indent (); break; + case 'j': + java_mode = true; + break; + + case 'l': + java_locale_name = optarg; + break; + case 'o': output_file = optarg; break; + case 'r': + java_resource_name = optarg; + break; + case 's': sort_by_msgid = true; break; @@ -123,6 +150,10 @@ main (argc, argv) message_print_style_uniforum (); break; + case 'v': + verbose = true; + break; + case 'V': do_version = true; break; @@ -160,19 +191,54 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ if (do_help) usage (EXIT_SUCCESS); + /* Check for contradicting options. */ + if (java_mode) + { + if (optind < argc) + { + error (EXIT_FAILURE, 0, + _("%s and explicit file names are mutually exclusive"), + "--java-mode"); + } + } + else + { + if (java_resource_name != NULL) + { + error (EXIT_SUCCESS, 0, _("%s is only valid with %s"), + "--resource", "--java-mode"); + usage (EXIT_FAILURE); + } + if (java_locale_name != NULL) + { + error (EXIT_SUCCESS, 0, _("%s is only valid with %s"), + "--locale", "--java-mode"); + usage (EXIT_FAILURE); + } + } + /* Read the given .mo file. */ - mlp = message_list_alloc (); - if (optind < argc) + if (java_mode) { - do - read_mo_file (mlp, argv[optind]); - while (++optind < argc); + result = msgdomain_read_java (java_resource_name, java_locale_name); } else - read_mo_file (mlp, "-"); + { + message_list_ty *mlp; - result = msgdomain_list_alloc (); - result->item[0]->messages = mlp; + mlp = message_list_alloc (); + if (optind < argc) + { + do + read_mo_file (mlp, argv[optind]); + while (++optind < argc); + } + else + read_mo_file (mlp, "-"); + + result = msgdomain_list_alloc (); + result->item[0]->messages = mlp; + } /* Sorting the list of messages. */ if (sort_by_msgid) @@ -213,6 +279,12 @@ Mandatory arguments to long options are mandatory for short options too.\n\ printf ("\n"); /* xgettext: no-wrap */ printf (_("\ +Operation mode:\n\ + -j, --java Java mode: generate a Java ResourceBundle class\n\ +")); + printf ("\n"); + /* xgettext: no-wrap */ + printf (_("\ Input file location:\n\ FILE ... input .mo files\n\ If no input file is given or if it is -, standard input is read.\n\ @@ -220,6 +292,15 @@ If no input file is given or if it is -, standard input is read.\n\ printf ("\n"); /* xgettext: no-wrap */ printf (_("\ +Input file location in Java mode: + -r, --resource=RESOURCE resource name + -l, --locale=LOCALE locale name, either language or language_COUNTRY +The class name is determined by appending the locale name to the resource name, +separated with an underscore. The class is located using the CLASSPATH. +")); + printf ("\n"); + /* xgettext: no-wrap */ + printf (_("\ Output file location:\n\ -o, --output-file=FILE write output to specified file\n\ The results are written to standard output if no output file is specified\n\ @@ -243,6 +324,7 @@ Output details:\n\ Informative output:\n\ -h, --help display this help and exit\n\ -V, --version output version information and exit\n\ + -v, --verbose increase verbosity level ")); printf ("\n"); fputs (_("Report bugs to <bug-gnu-gettext@gnu.org>.\n"), |