~ubuntu-branches/ubuntu/utopic/gettext/utopic

« back to all changes in this revision

Viewing changes to gettext-tools/src/msgcat.c

  • Committer: Colin Watson
  • Date: 2010-08-01 21:36:08 UTC
  • mfrom: (2.1.10 sid)
  • Revision ID: cjwatson@canonical.com-20100801213608-yy7vkm8lpatep3ci
merge from Debian 0.18.1.1-1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Concatenates several translation catalogs.
2
 
   Copyright (C) 2001-2007 Free Software Foundation, Inc.
 
2
   Copyright (C) 2001-2007, 2009-2010 Free Software Foundation, Inc.
3
3
   Written by Bruno Haible <haible@clisp.cons.org>, 2001.
4
4
 
5
5
   This program is free software: you can redistribute it and/or modify
46
46
#include "write-stringtable.h"
47
47
#include "color.h"
48
48
#include "msgl-cat.h"
 
49
#include "msgl-header.h"
49
50
#include "propername.h"
50
51
#include "gettext.h"
51
52
 
69
70
  { "force-po", no_argument, &force_po, 1 },
70
71
  { "help", no_argument, NULL, 'h' },
71
72
  { "indent", no_argument, NULL, 'i' },
 
73
  { "lang", required_argument, NULL, CHAR_MAX + 7 },
72
74
  { "no-escape", no_argument, NULL, 'e' },
73
75
  { "no-location", no_argument, &line_comment, 0 },
74
76
  { "no-wrap", no_argument, NULL, CHAR_MAX + 2 },
95
97
/* Forward declaration of local functions.  */
96
98
static void usage (int status)
97
99
#if defined __GNUC__ && ((__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2)
98
 
        __attribute__ ((noreturn))
 
100
        __attribute__ ((noreturn))
99
101
#endif
100
102
;
101
103
 
115
117
  catalog_output_format_ty output_syntax = &output_format_po;
116
118
  bool sort_by_msgid = false;
117
119
  bool sort_by_filepos = false;
 
120
  /* Language (ISO-639 code) and optional territory (ISO-3166 code).  */
 
121
  const char *catalogname = NULL;
118
122
 
119
123
  /* Set program name for messages.  */
120
124
  set_program_name (argv[0]);
143
147
  use_first = false;
144
148
 
145
149
  while ((optchar = getopt_long (argc, argv, "<:>:D:eEf:Fhino:pPst:uVw:",
146
 
                                 long_options, NULL)) != EOF)
 
150
                                 long_options, NULL)) != EOF)
147
151
    switch (optchar)
148
152
      {
149
 
      case '\0':                /* Long option.  */
150
 
        break;
 
153
      case '\0':                /* Long option.  */
 
154
        break;
151
155
 
152
156
      case '>':
153
 
        {
154
 
          int value;
155
 
          char *endp;
156
 
          value = strtol (optarg, &endp, 10);
157
 
          if (endp != optarg)
158
 
            more_than = value;
159
 
        }
160
 
        break;
 
157
        {
 
158
          int value;
 
159
          char *endp;
 
160
          value = strtol (optarg, &endp, 10);
 
161
          if (endp != optarg)
 
162
            more_than = value;
 
163
        }
 
164
        break;
161
165
 
162
166
      case '<':
163
 
        {
164
 
          int value;
165
 
          char *endp;
166
 
          value = strtol (optarg, &endp, 10);
167
 
          if (endp != optarg)
168
 
            less_than = value;
169
 
        }
170
 
        break;
 
167
        {
 
168
          int value;
 
169
          char *endp;
 
170
          value = strtol (optarg, &endp, 10);
 
171
          if (endp != optarg)
 
172
            less_than = value;
 
173
        }
 
174
        break;
171
175
 
172
176
      case 'D':
173
 
        dir_list_append (optarg);
174
 
        break;
 
177
        dir_list_append (optarg);
 
178
        break;
175
179
 
176
180
      case 'e':
177
 
        message_print_style_escape (false);
178
 
        break;
 
181
        message_print_style_escape (false);
 
182
        break;
179
183
 
180
184
      case 'E':
181
 
        message_print_style_escape (true);
182
 
        break;
 
185
        message_print_style_escape (true);
 
186
        break;
183
187
 
184
188
      case 'f':
185
 
        files_from = optarg;
186
 
        break;
 
189
        files_from = optarg;
 
190
        break;
187
191
 
188
192
      case 'F':
189
 
        sort_by_filepos = true;
190
 
        break;
 
193
        sort_by_filepos = true;
 
194
        break;
191
195
 
192
196
      case 'h':
193
 
        do_help = true;
194
 
        break;
 
197
        do_help = true;
 
198
        break;
195
199
 
196
200
      case 'i':
197
 
        message_print_style_indent ();
198
 
        break;
 
201
        message_print_style_indent ();
 
202
        break;
199
203
 
200
204
      case 'n':
201
 
        line_comment = 1;
202
 
        break;
 
205
        line_comment = 1;
 
206
        break;
203
207
 
204
208
      case 'o':
205
 
        output_file = optarg;
206
 
        break;
 
209
        output_file = optarg;
 
210
        break;
207
211
 
208
212
      case 'p':
209
 
        output_syntax = &output_format_properties;
210
 
        break;
 
213
        output_syntax = &output_format_properties;
 
214
        break;
211
215
 
212
216
      case 'P':
213
 
        input_syntax = &input_format_properties;
214
 
        break;
 
217
        input_syntax = &input_format_properties;
 
218
        break;
215
219
 
216
220
      case 's':
217
 
        sort_by_msgid = true;
218
 
        break;
 
221
        sort_by_msgid = true;
 
222
        break;
219
223
 
220
224
      case 'S':
221
 
        message_print_style_uniforum ();
222
 
        break;
 
225
        message_print_style_uniforum ();
 
226
        break;
223
227
 
224
228
      case 't':
225
 
        to_code = optarg;
226
 
        break;
 
229
        to_code = optarg;
 
230
        break;
227
231
 
228
232
      case 'u':
229
 
        less_than = 2;
230
 
        break;
 
233
        less_than = 2;
 
234
        break;
231
235
 
232
236
      case 'V':
233
 
        do_version = true;
234
 
        break;
 
237
        do_version = true;
 
238
        break;
235
239
 
236
240
      case 'w':
237
 
        {
238
 
          int value;
239
 
          char *endp;
240
 
          value = strtol (optarg, &endp, 10);
241
 
          if (endp != optarg)
242
 
            message_page_width_set (value);
243
 
        }
244
 
        break;
 
241
        {
 
242
          int value;
 
243
          char *endp;
 
244
          value = strtol (optarg, &endp, 10);
 
245
          if (endp != optarg)
 
246
            message_page_width_set (value);
 
247
        }
 
248
        break;
245
249
 
246
250
      case CHAR_MAX + 1:
247
 
        use_first = true;
248
 
        break;
 
251
        use_first = true;
 
252
        break;
249
253
 
250
254
      case CHAR_MAX + 2: /* --no-wrap */
251
 
        message_page_width_ignore ();
252
 
        break;
 
255
        message_page_width_ignore ();
 
256
        break;
253
257
 
254
258
      case CHAR_MAX + 3: /* --stringtable-input */
255
 
        input_syntax = &input_format_stringtable;
256
 
        break;
 
259
        input_syntax = &input_format_stringtable;
 
260
        break;
257
261
 
258
262
      case CHAR_MAX + 4: /* --stringtable-output */
259
 
        output_syntax = &output_format_stringtable;
260
 
        break;
 
263
        output_syntax = &output_format_stringtable;
 
264
        break;
261
265
 
262
266
      case CHAR_MAX + 5: /* --color */
263
 
        if (handle_color_option (optarg))
264
 
          usage (EXIT_FAILURE);
265
 
        break;
 
267
        if (handle_color_option (optarg))
 
268
          usage (EXIT_FAILURE);
 
269
        break;
266
270
 
267
271
      case CHAR_MAX + 6: /* --style */
268
 
        handle_style_option (optarg);
269
 
        break;
 
272
        handle_style_option (optarg);
 
273
        break;
 
274
 
 
275
      case CHAR_MAX + 7: /* --lang */
 
276
        catalogname = optarg;
 
277
        break;
270
278
 
271
279
      default:
272
 
        usage (EXIT_FAILURE);
273
 
        /* NOTREACHED */
 
280
        usage (EXIT_FAILURE);
 
281
        /* NOTREACHED */
274
282
      }
275
283
 
276
284
  /* Version information requested.  */
283
291
This is free software: you are free to change and redistribute it.\n\
284
292
There is NO WARRANTY, to the extent permitted by law.\n\
285
293
"),
286
 
              "2001-2007");
 
294
              "2001-2010");
287
295
      printf (_("Written by %s.\n"), proper_name ("Bruno Haible"));
288
296
      exit (EXIT_SUCCESS);
289
297
    }
301
309
  /* Verify selected options.  */
302
310
  if (!line_comment && sort_by_filepos)
303
311
    error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"),
304
 
           "--no-location", "--sort-by-file");
 
312
           "--no-location", "--sort-by-file");
305
313
 
306
314
  if (sort_by_msgid && sort_by_filepos)
307
315
    error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"),
308
 
           "--sort-output", "--sort-by-file");
 
316
           "--sort-output", "--sort-by-file");
309
317
 
310
318
  /* Check the message selection criteria for sanity.  */
311
319
  if (more_than >= less_than || less_than < 2)
312
320
    error (EXIT_FAILURE, 0,
313
 
           _("impossible selection criteria specified (%d < n < %d)"),
314
 
           more_than, less_than);
 
321
           _("impossible selection criteria specified (%d < n < %d)"),
 
322
           more_than, less_than);
315
323
 
316
324
  /* Determine list of files we have to process.  */
317
325
  if (files_from != NULL)
325
333
  /* Read input files, then filter, convert and merge messages.  */
326
334
  result =
327
335
    catenate_msgdomain_list (file_list, input_syntax,
328
 
                             output_syntax->requires_utf8 ? "UTF-8" : to_code);
 
336
                             output_syntax->requires_utf8 ? "UTF-8" : to_code);
329
337
 
330
338
  string_list_free (file_list);
331
339
 
335
343
  else if (sort_by_msgid)
336
344
    msgdomain_list_sort_by_msgid (result);
337
345
 
 
346
  /* Set the Language field in the header.  */
 
347
  if (catalogname != NULL)
 
348
    msgdomain_list_set_header_field (result, "Language:", catalogname);
 
349
 
338
350
  /* Write the PO file.  */
339
351
  msgdomain_list_print (result, output_file, output_syntax, force_po, false);
340
352
 
348
360
{
349
361
  if (status != EXIT_SUCCESS)
350
362
    fprintf (stderr, _("Try `%s --help' for more information.\n"),
351
 
             program_name);
 
363
             program_name);
352
364
  else
353
365
    {
354
366
      printf (_("\
418
430
      --use-first             use first available translation for each\n\
419
431
                              message, don't merge several translations\n"));
420
432
      printf (_("\
 
433
      --lang=CATALOGNAME      set 'Language' field in the header entry\n"));
 
434
      printf (_("\
421
435
      --color                 use colors and other text attributes always\n\
422
436
      --color=WHEN            use colors and other text attributes if WHEN.\n\
423
437
                              WHEN may be 'always', 'never', 'auto', or 'html'.\n"));
463
477
         "Report translation bugs to <...>\n" with the address for translation
464
478
         bugs (typically your translation team's web or email address).  */
465
479
      fputs (_("Report bugs to <bug-gnu-gettext@gnu.org>.\n"),
466
 
             stdout);
 
480
             stdout);
467
481
    }
468
482
 
469
483
  exit (status);