1 /* Creates an English translation catalog.
2 Copyright (C) 2001-2005 Free Software Foundation, Inc.
3 Written by Bruno Haible <haible@clisp.cons.org>, 2001.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
33 #include "error-progname.h"
35 #include "relocatable.h"
39 #include "msgl-english.h"
44 #define _(str) gettext (str)
47 /* Force output of PO file even if empty. */
51 static const struct option long_options
[] =
53 { "add-location", no_argument
, &line_comment
, 1 },
54 { "directory", required_argument
, NULL
, 'D' },
55 { "escape", no_argument
, NULL
, 'E' },
56 { "force-po", no_argument
, &force_po
, 1 },
57 { "help", no_argument
, NULL
, 'h' },
58 { "indent", no_argument
, NULL
, 'i' },
59 { "no-escape", no_argument
, NULL
, 'e' },
60 { "no-location", no_argument
, &line_comment
, 0 },
61 { "no-wrap", no_argument
, NULL
, CHAR_MAX
+ 1 },
62 { "output-file", required_argument
, NULL
, 'o' },
63 { "properties-input", no_argument
, NULL
, 'P' },
64 { "properties-output", no_argument
, NULL
, 'p' },
65 { "sort-by-file", no_argument
, NULL
, 'F' },
66 { "sort-output", no_argument
, NULL
, 's' },
67 { "strict", no_argument
, NULL
, 'S' },
68 { "stringtable-input", no_argument
, NULL
, CHAR_MAX
+ 2 },
69 { "stringtable-output", no_argument
, NULL
, CHAR_MAX
+ 3 },
70 { "version", no_argument
, NULL
, 'V' },
71 { "width", required_argument
, NULL
, 'w', },
76 /* Forward declaration of local functions. */
77 static void usage (int status
)
78 #if defined __GNUC__ && ((__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2)
79 __attribute__ ((noreturn
))
85 main (int argc
, char **argv
)
91 msgdomain_list_ty
*result
;
92 bool sort_by_filepos
= false;
93 bool sort_by_msgid
= false;
95 /* Set program name for messages. */
96 set_program_name (argv
[0]);
97 error_print_progname
= maybe_print_progname
;
100 /* Set locale via LC_ALL. */
101 setlocale (LC_ALL
, "");
104 /* Set the text message domain. */
105 bindtextdomain (PACKAGE
, relocate (LOCALEDIR
));
106 textdomain (PACKAGE
);
108 /* Ensure that write errors on stdout are detected. */
109 atexit (close_stdout
);
111 /* Set default values for variables. */
116 while ((opt
= getopt_long (argc
, argv
, "D:eEFhio:pPsVw:", long_options
, NULL
))
120 case '\0': /* Long option. */
124 dir_list_append (optarg
);
128 message_print_style_escape (false);
132 message_print_style_escape (true);
136 sort_by_filepos
= true;
144 message_print_style_indent ();
148 output_file
= optarg
;
152 message_print_syntax_properties ();
156 input_syntax
= syntax_properties
;
160 sort_by_msgid
= true;
164 message_print_style_uniforum ();
175 value
= strtol (optarg
, &endp
, 10);
177 message_page_width_set (value
);
181 case CHAR_MAX
+ 1: /* --no-wrap */
182 message_page_width_ignore ();
185 case CHAR_MAX
+ 2: /* --stringtable-input */
186 input_syntax
= syntax_stringtable
;
189 case CHAR_MAX
+ 3: /* --stringtable-output */
190 message_print_syntax_stringtable ();
194 usage (EXIT_FAILURE
);
198 /* Version information is requested. */
201 printf ("%s (GNU %s) %s\n", basename (program_name
), PACKAGE
, VERSION
);
202 /* xgettext: no-wrap */
203 printf (_("Copyright (C) %s Free Software Foundation, Inc.\n\
204 This is free software; see the source for copying conditions. There is NO\n\
205 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
208 printf (_("Written by %s.\n"), "Bruno Haible");
212 /* Help is requested. */
214 usage (EXIT_SUCCESS
);
216 /* Test whether we have an .po file name as argument. */
219 error (EXIT_SUCCESS
, 0, _("no input file given"));
220 usage (EXIT_FAILURE
);
222 if (optind
+ 1 != argc
)
224 error (EXIT_SUCCESS
, 0, _("exactly one input file required"));
225 usage (EXIT_FAILURE
);
228 /* Verify selected options. */
229 if (!line_comment
&& sort_by_filepos
)
230 error (EXIT_FAILURE
, 0, _("%s and %s are mutually exclusive"),
231 "--no-location", "--sort-by-file");
233 if (sort_by_msgid
&& sort_by_filepos
)
234 error (EXIT_FAILURE
, 0, _("%s and %s are mutually exclusive"),
235 "--sort-output", "--sort-by-file");
237 /* Read input file and add English translations. */
238 result
= msgdomain_list_english (read_po_file (argv
[optind
]));
240 /* Sort the results. */
242 msgdomain_list_sort_by_filepos (result
);
243 else if (sort_by_msgid
)
244 msgdomain_list_sort_by_msgid (result
);
246 /* Write the merged message list out. */
247 msgdomain_list_print (result
, output_file
, force_po
, false);
253 /* Display usage information and exit. */
257 if (status
!= EXIT_SUCCESS
)
258 fprintf (stderr
, _("Try `%s --help' for more information.\n"),
263 Usage: %s [OPTION] INPUTFILE\n\
266 /* xgettext: no-wrap */
268 Creates an English translation catalog. The input file is the last\n\
269 created English PO file, or a PO Template file (generally created by\n\
270 xgettext). Untranslated entries are assigned a translation that is\n\
271 identical to the msgid.\n\
275 Mandatory arguments to long options are mandatory for short options too.\n"));
278 Input file location:\n"));
280 INPUTFILE input PO or POT file\n"));
282 -D, --directory=DIRECTORY add DIRECTORY to list for input files search\n"));
284 If input file is -, standard input is read.\n"));
287 Output file location:\n"));
289 -o, --output-file=FILE write output to specified file\n"));
291 The results are written to standard output if no output file is specified\n\
295 Input file syntax:\n"));
297 -P, --properties-input input file is in Java .properties syntax\n"));
299 --stringtable-input input file is in NeXTstep/GNUstep .strings syntax\n"));
302 Output details:\n"));
304 -e, --no-escape do not use C escapes in output (default)\n"));
306 -E, --escape use C escapes in output, no extended chars\n"));
308 --force-po write PO file even if empty\n"));
310 -i, --indent indented output style\n"));
312 --no-location suppress '#: filename:line' lines\n"));
314 --add-location preserve '#: filename:line' lines (default)\n"));
316 --strict strict Uniforum output style\n"));
318 -p, --properties-output write out a Java .properties file\n"));
320 --stringtable-output write out a NeXTstep/GNUstep .strings file\n"));
322 -w, --width=NUMBER set output page width\n"));
324 --no-wrap do not break long message lines, longer than\n\
325 the output page width, into several lines\n"));
327 -s, --sort-output generate sorted output\n"));
329 -F, --sort-by-file sort output by file location\n"));
332 Informative output:\n"));
334 -h, --help display this help and exit\n"));
336 -V, --version output version information and exit\n"));
338 fputs (_("Report bugs to <bug-gnu-gettext@gnu.org>.\n"),