No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / gettext / gettext-tools / src / msgen.c
blob14b82f263971b376b86dbc216d5b9a1ebed1c91c
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)
8 any later version.
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. */
20 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 #endif
24 #include <getopt.h>
25 #include <limits.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <locale.h>
30 #include "closeout.h"
31 #include "dir-list.h"
32 #include "error.h"
33 #include "error-progname.h"
34 #include "progname.h"
35 #include "relocatable.h"
36 #include "basename.h"
37 #include "message.h"
38 #include "read-po.h"
39 #include "msgl-english.h"
40 #include "write-po.h"
41 #include "exit.h"
42 #include "gettext.h"
44 #define _(str) gettext (str)
47 /* Force output of PO file even if empty. */
48 static int force_po;
50 /* Long options. */
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', },
72 { NULL, 0, NULL, 0 }
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))
80 #endif
84 int
85 main (int argc, char **argv)
87 int opt;
88 bool do_help;
89 bool do_version;
90 char *output_file;
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;
99 #ifdef HAVE_SETLOCALE
100 /* Set locale via LC_ALL. */
101 setlocale (LC_ALL, "");
102 #endif
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. */
112 do_help = false;
113 do_version = false;
114 output_file = NULL;
116 while ((opt = getopt_long (argc, argv, "D:eEFhio:pPsVw:", long_options, NULL))
117 != EOF)
118 switch (opt)
120 case '\0': /* Long option. */
121 break;
123 case 'D':
124 dir_list_append (optarg);
125 break;
127 case 'e':
128 message_print_style_escape (false);
129 break;
131 case 'E':
132 message_print_style_escape (true);
133 break;
135 case 'F':
136 sort_by_filepos = true;
137 break;
139 case 'h':
140 do_help = true;
141 break;
143 case 'i':
144 message_print_style_indent ();
145 break;
147 case 'o':
148 output_file = optarg;
149 break;
151 case 'p':
152 message_print_syntax_properties ();
153 break;
155 case 'P':
156 input_syntax = syntax_properties;
157 break;
159 case 's':
160 sort_by_msgid = true;
161 break;
163 case 'S':
164 message_print_style_uniforum ();
165 break;
167 case 'V':
168 do_version = true;
169 break;
171 case 'w':
173 int value;
174 char *endp;
175 value = strtol (optarg, &endp, 10);
176 if (endp != optarg)
177 message_page_width_set (value);
179 break;
181 case CHAR_MAX + 1: /* --no-wrap */
182 message_page_width_ignore ();
183 break;
185 case CHAR_MAX + 2: /* --stringtable-input */
186 input_syntax = syntax_stringtable;
187 break;
189 case CHAR_MAX + 3: /* --stringtable-output */
190 message_print_syntax_stringtable ();
191 break;
193 default:
194 usage (EXIT_FAILURE);
195 break;
198 /* Version information is requested. */
199 if (do_version)
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\
207 "2001-2005");
208 printf (_("Written by %s.\n"), "Bruno Haible");
209 exit (EXIT_SUCCESS);
212 /* Help is requested. */
213 if (do_help)
214 usage (EXIT_SUCCESS);
216 /* Test whether we have an .po file name as argument. */
217 if (optind >= argc)
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. */
241 if (sort_by_filepos)
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);
249 exit (EXIT_SUCCESS);
253 /* Display usage information and exit. */
254 static void
255 usage (int status)
257 if (status != EXIT_SUCCESS)
258 fprintf (stderr, _("Try `%s --help' for more information.\n"),
259 program_name);
260 else
262 printf (_("\
263 Usage: %s [OPTION] INPUTFILE\n\
264 "), program_name);
265 printf ("\n");
266 /* xgettext: no-wrap */
267 printf (_("\
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\
272 "));
273 printf ("\n");
274 printf (_("\
275 Mandatory arguments to long options are mandatory for short options too.\n"));
276 printf ("\n");
277 printf (_("\
278 Input file location:\n"));
279 printf (_("\
280 INPUTFILE input PO or POT file\n"));
281 printf (_("\
282 -D, --directory=DIRECTORY add DIRECTORY to list for input files search\n"));
283 printf (_("\
284 If input file is -, standard input is read.\n"));
285 printf ("\n");
286 printf (_("\
287 Output file location:\n"));
288 printf (_("\
289 -o, --output-file=FILE write output to specified file\n"));
290 printf (_("\
291 The results are written to standard output if no output file is specified\n\
292 or if it is -.\n"));
293 printf ("\n");
294 printf (_("\
295 Input file syntax:\n"));
296 printf (_("\
297 -P, --properties-input input file is in Java .properties syntax\n"));
298 printf (_("\
299 --stringtable-input input file is in NeXTstep/GNUstep .strings syntax\n"));
300 printf ("\n");
301 printf (_("\
302 Output details:\n"));
303 printf (_("\
304 -e, --no-escape do not use C escapes in output (default)\n"));
305 printf (_("\
306 -E, --escape use C escapes in output, no extended chars\n"));
307 printf (_("\
308 --force-po write PO file even if empty\n"));
309 printf (_("\
310 -i, --indent indented output style\n"));
311 printf (_("\
312 --no-location suppress '#: filename:line' lines\n"));
313 printf (_("\
314 --add-location preserve '#: filename:line' lines (default)\n"));
315 printf (_("\
316 --strict strict Uniforum output style\n"));
317 printf (_("\
318 -p, --properties-output write out a Java .properties file\n"));
319 printf (_("\
320 --stringtable-output write out a NeXTstep/GNUstep .strings file\n"));
321 printf (_("\
322 -w, --width=NUMBER set output page width\n"));
323 printf (_("\
324 --no-wrap do not break long message lines, longer than\n\
325 the output page width, into several lines\n"));
326 printf (_("\
327 -s, --sort-output generate sorted output\n"));
328 printf (_("\
329 -F, --sort-by-file sort output by file location\n"));
330 printf ("\n");
331 printf (_("\
332 Informative output:\n"));
333 printf (_("\
334 -h, --help display this help and exit\n"));
335 printf (_("\
336 -V, --version output version information and exit\n"));
337 printf ("\n");
338 fputs (_("Report bugs to <bug-gnu-gettext@gnu.org>.\n"),
339 stdout);
342 exit (status);