1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
|
/* msgunfmt - converts binary .mo files to Uniforum style .po files
Copyright (C) 1995-1998, 2000-2007, 2009-2010, 2012, 2015 Free
Software Foundation, Inc.
Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, April 1995.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <getopt.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include "closeout.h"
#include "error.h"
#include "error-progname.h"
#include "progname.h"
#include "relocatable.h"
#include "basename.h"
#include "message.h"
#include "msgunfmt.h"
#include "read-mo.h"
#include "read-java.h"
#include "read-csharp.h"
#include "read-resources.h"
#include "read-tcl.h"
#include "write-catalog.h"
#include "write-po.h"
#include "write-properties.h"
#include "write-stringtable.h"
#include "color.h"
#include "propername.h"
#include "gettext.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;
/* C# mode input file specification. */
static bool csharp_mode;
static const char *csharp_resource_name;
static const char *csharp_locale_name;
static const char *csharp_base_directory;
/* C# resources mode input file specification. */
static bool csharp_resources_mode;
/* Tcl mode input file specification. */
static bool tcl_mode;
static const char *tcl_locale_name;
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. */
static void usage (int status)
#if defined __GNUC__ && ((__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2)
__attribute__ ((noreturn))
#endif
;
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 = "-";
msgdomain_list_ty *result;
catalog_output_format_ty output_syntax = &output_format_po;
bool sort_by_msgid = false;
/* Set program name for messages. */
set_program_name (argv[0]);
error_print_progname = maybe_print_progname;
#ifdef HAVE_SETLOCALE
/* Set locale via LC_ALL. */
setlocale (LC_ALL, "");
#endif
/* Set the text message domain. */
bindtextdomain (PACKAGE, relocate (LOCALEDIR));
bindtextdomain ("bison-runtime", relocate (BISON_LOCALEDIR));
textdomain (PACKAGE);
/* 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)
switch (optchar)
{
case '\0':
/* long option */
break;
case 'd':
csharp_base_directory = optarg;
tcl_base_directory = optarg;
break;
case 'e':
message_print_style_escape (false);
break;
case 'E':
message_print_style_escape (true);
break;
case 'h':
do_help = true;
break;
case 'i':
message_print_style_indent ();
break;
case 'j':
java_mode = true;
break;
case 'l':
java_locale_name = optarg;
csharp_locale_name = optarg;
tcl_locale_name = optarg;
break;
case 'o':
output_file = optarg;
break;
case 'p':
output_syntax = &output_format_properties;
break;
case 'r':
java_resource_name = optarg;
csharp_resource_name = optarg;
break;
case 's':
sort_by_msgid = true;
break;
case 'S':
message_print_style_uniforum ();
break;
case 'v':
verbose = true;
break;
case 'V':
do_version = true;
break;
case 'w':
{
int value;
char *endp;
value = strtol (optarg, &endp, 10);
if (endp != optarg)
message_page_width_set (value);
}
break;
case CHAR_MAX + 1: /* --tcl */
tcl_mode = true;
break;
case CHAR_MAX + 2: /* --no-wrap */
message_page_width_ignore ();
break;
case CHAR_MAX + 3: /* --stringtable-output */
output_syntax = &output_format_stringtable;
break;
case CHAR_MAX + 4: /* --csharp */
csharp_mode = true;
break;
case CHAR_MAX + 5: /* --csharp-resources */
csharp_resources_mode = true;
break;
case CHAR_MAX + 6: /* --color */
if (handle_color_option (optarg) || color_test_mode)
usage (EXIT_FAILURE);
break;
case CHAR_MAX + 7: /* --style */
handle_style_option (optarg);
break;
default:
usage (EXIT_FAILURE);
break;
}
/* Version information is requested. */
if (do_version)
{
printf ("%s (GNU %s) %s\n", basename (program_name), PACKAGE, VERSION);
/* xgettext: no-wrap */
printf (_("Copyright (C) %s Free Software Foundation, Inc.\n\
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n\
This is free software: you are free to change and redistribute it.\n\
There is NO WARRANTY, to the extent permitted by law.\n\
"),
"1995-1998, 2000-2010");
printf (_("Written by %s.\n"), proper_name ("Ulrich Drepper"));
exit (EXIT_SUCCESS);
}
/* Help is requested. */
if (do_help)
usage (EXIT_SUCCESS);
/* Check for contradicting options. */
{
unsigned int modes =
(java_mode ? 1 : 0)
| (csharp_mode ? 2 : 0)
| (csharp_resources_mode ? 4 : 0)
| (tcl_mode ? 8 : 0);
static const char *mode_options[] =
{ "--java", "--csharp", "--csharp-resources", "--tcl" };
/* More than one bit set? */
if (modes & (modes - 1))
{
const char *first_option;
const char *second_option;
unsigned int i;
for (i = 0; ; i++)
if (modes & (1 << i))
break;
first_option = mode_options[i];
for (i = i + 1; ; i++)
if (modes & (1 << i))
break;
second_option = mode_options[i];
error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"),
first_option, second_option);
}
}
if (java_mode)
{
if (optind < argc)
{
error (EXIT_FAILURE, 0,
_("%s and explicit file names are mutually exclusive"),
"--java");
}
}
else if (csharp_mode)
{
if (optind < argc)
{
error (EXIT_FAILURE, 0,
_("%s and explicit file names are mutually exclusive"),
"--csharp");
}
if (csharp_locale_name == NULL)
{
error (EXIT_SUCCESS, 0,
_("%s requires a \"-l locale\" specification"),
"--csharp");
usage (EXIT_FAILURE);
}
if (csharp_base_directory == NULL)
{
error (EXIT_SUCCESS, 0,
_("%s requires a \"-d directory\" specification"),
"--csharp");
usage (EXIT_FAILURE);
}
}
else if (tcl_mode)
{
if (optind < argc)
{
error (EXIT_FAILURE, 0,
_("%s and explicit file names are mutually exclusive"),
"--tcl");
}
if (tcl_locale_name == NULL)
{
error (EXIT_SUCCESS, 0,
_("%s requires a \"-l locale\" specification"),
"--tcl");
usage (EXIT_FAILURE);
}
if (tcl_base_directory == NULL)
{
error (EXIT_SUCCESS, 0,
_("%s requires a \"-d directory\" specification"),
"--tcl");
usage (EXIT_FAILURE);
}
}
else
{
if (java_resource_name != NULL)
{
error (EXIT_SUCCESS, 0, _("%s is only valid with %s or %s"),
"--resource", "--java", "--csharp");
usage (EXIT_FAILURE);
}
if (java_locale_name != NULL)
{
error (EXIT_SUCCESS, 0, _("%s is only valid with %s or %s"),
"--locale", "--java", "--csharp");
usage (EXIT_FAILURE);
}
}
/* Read the given .mo file. */
if (java_mode)
{
result = msgdomain_read_java (java_resource_name, java_locale_name);
}
else if (csharp_mode)
{
result = msgdomain_read_csharp (csharp_resource_name, csharp_locale_name,
csharp_base_directory);
}
else if (tcl_mode)
{
result = msgdomain_read_tcl (tcl_locale_name, tcl_base_directory);
}
else
{
message_list_ty *mlp;
mlp = message_list_alloc (false);
if (optind < argc)
{
do
read_one_file (mlp, argv[optind]);
while (++optind < argc);
}
else
read_one_file (mlp, "-");
result = msgdomain_list_alloc (false);
result->item[0]->messages = mlp;
}
/* Sorting the list of messages. */
if (sort_by_msgid)
msgdomain_list_sort_by_msgid (result);
/* Write the resulting message list to the given .po file. */
msgdomain_list_print (result, output_file, output_syntax, force_po, false);
/* No problems. */
exit (EXIT_SUCCESS);
}
/* Display usage information and exit. */
static void
usage (int status)
{
if (status != EXIT_SUCCESS)
fprintf (stderr, _("Try '%s --help' for more information.\n"),
program_name);
else
{
printf (_("\
Usage: %s [OPTION] [FILE]...\n\
"), program_name);
printf ("\n");
printf (_("\
Convert binary message catalog to Uniforum style .po file.\n\
"));
printf ("\n");
printf (_("\
Mandatory arguments to long options are mandatory for short options too.\n"));
printf ("\n");
printf (_("\
Operation mode:\n"));
printf (_("\
-j, --java Java mode: input is a Java ResourceBundle class\n"));
printf (_("\
--csharp C# mode: input is a .NET .dll file\n"));
printf (_("\
--csharp-resources C# resources mode: input is a .NET .resources file\n"));
printf (_("\
--tcl Tcl mode: input is a tcl/msgcat .msg file\n"));
printf ("\n");
printf (_("\
Input file location:\n"));
printf (_("\
FILE ... input .mo files\n"));
printf (_("\
If no input file is given or if it is -, standard input is read.\n"));
printf ("\n");
printf (_("\
Input file location in Java mode:\n"));
printf (_("\
-r, --resource=RESOURCE resource name\n"));
printf (_("\
-l, --locale=LOCALE locale name, either language or language_COUNTRY\n"));
printf (_("\
The class name is determined by appending the locale name to the resource name,\n\
separated with an underscore. The class is located using the CLASSPATH.\n\
"));
printf ("\n");
printf (_("\
Input file location in C# mode:\n"));
printf (_("\
-r, --resource=RESOURCE resource name\n"));
printf (_("\
-l, --locale=LOCALE locale name, either language or language_COUNTRY\n"));
printf (_("\
-d DIRECTORY base directory for locale dependent .dll files\n"));
printf (_("\
The -l and -d options are mandatory. The .dll file is located in a\n\
subdirectory of the specified directory whose name depends on the locale.\n"));
printf ("\n");
printf (_("\
Input file location in Tcl mode:\n"));
printf (_("\
-l, --locale=LOCALE locale name, either language or language_COUNTRY\n"));
printf (_("\
-d DIRECTORY base directory of .msg message catalogs\n"));
printf (_("\
The -l and -d options are mandatory. The .msg file is located in the\n\
specified directory.\n"));
printf ("\n");
printf (_("\
Output file location:\n"));
printf (_("\
-o, --output-file=FILE write output to specified file\n"));
printf (_("\
The results are written to standard output if no output file is specified\n\
or if it is -.\n"));
printf ("\n");
printf (_("\
Output details:\n"));
printf (_("\
--color use colors and other text attributes always\n\
--color=WHEN use colors and other text attributes if WHEN.\n\
WHEN may be 'always', 'never', 'auto', or 'html'.\n"));
printf (_("\
--style=STYLEFILE specify CSS style rule file for --color\n"));
printf (_("\
-e, --no-escape do not use C escapes in output (default)\n"));
printf (_("\
-E, --escape use C escapes in output, no extended chars\n"));
printf (_("\
--force-po write PO file even if empty\n"));
printf (_("\
-i, --indent write indented output style\n"));
printf (_("\
--strict write strict uniforum style\n"));
printf (_("\
-p, --properties-output write out a Java .properties file\n"));
printf (_("\
--stringtable-output write out a NeXTstep/GNUstep .strings file\n"));
printf (_("\
-w, --width=NUMBER set output page width\n"));
printf (_("\
--no-wrap do not break long message lines, longer than\n\
the output page width, into several lines\n"));
printf (_("\
-s, --sort-output generate sorted output\n"));
printf ("\n");
printf (_("\
Informative output:\n"));
printf (_("\
-h, --help display this help and exit\n"));
printf (_("\
-V, --version output version information and exit\n"));
printf (_("\
-v, --verbose increase verbosity level\n"));
printf ("\n");
/* TRANSLATORS: The placeholder indicates the bug-reporting address
for this package. Please add _another line_ saying
"Report translation bugs to <...>\n" with the address for translation
bugs (typically your translation team's web or email address). */
fputs (_("Report bugs to <bug-gnu-gettext@gnu.org>.\n"),
stdout);
}
exit (status);
}
static void
read_one_file (message_list_ty *mlp, const char *filename)
{
if (csharp_resources_mode)
read_resources_file (mlp, filename);
else
read_mo_file (mlp, filename);
}
|