+2006-10-15 Bruno Haible <bruno@clisp.org>
+
+ * POTFILES.in: Add src/write-catalog.c.
+
2006-10-02 Bruno Haible <bruno@clisp.org>
* fr.po: Update from Christophe Combelles <ccomb@free.fr>.
src/read-tcl.c
src/recode-sr-latin.c
src/urlget.c
+src/write-catalog.c
src/write-csharp.c
src/write-java.c
src/write-mo.c
+2006-10-15 Bruno Haible <bruno@clisp.org>
+
+ * write-catalog.h: New file.
+ * write-catalog.c: New file, mostly extracted from write-po.c.
+ * write-po.h (message_page_width_set): Move declaration to
+ write-catalog.h.
+ (message_print_syntax_properties, message_print_syntax_stringtable):
+ Remove declarations.
+ (msgdomain_list_print): Move out to write-catalog.h, adding a
+ catalog_output_format_ty argument.
+ (msgdomain_list_sort_by_msgid, msgdomain_list_sort_by_filepos): Move
+ out to write-catalog.h.
+ (output_format_po): New declaration.
+ * write-po.c: Don't include fwriteerror.h, error-progname.h.
+ (page_width, message_page_width_set): Move out to write-catalog.c.
+ (use_syntax_properties): Remove variable.
+ (message_print_syntax_properties): Remove function.
+ (use_syntax_stringtable): Remove variable.
+ (message_print_syntax_stringtable): Remove function.
+ (wrap, message_print, message_print_obsolete, msgdomain_list_print_po):
+ Add page_width argument.
+ (msgdomain_list_print): Move out to write-catalog.c, adding a
+ catalog_output_format_ty argument.
+ (cmp_by_msgid, msgdomain_list_sort_by_msgid,
+ cmp_filepos, msgdomain_list_sort_filepos,
+ cmp_by_filepos, msgdomain_list_sort_by_filepos): Move out to
+ write-catalog.c.
+ (output_format_po): New variable.
+ * write-properties.h (msgdomain_list_print_properties): Remove
+ declaration.
+ (output_format_properties): New declaration.
+ * write-properties.c (msgdomain_list_print_properties): Make static.
+ (output_format_properties): New variable.
+ * write-stringtable.h (msgdomain_list_print_stringtable): Remove
+ declaration.
+ (output_format_stringtable): New declaration.
+ * write-stringtable.c (msgdomain_list_print_stringtable): Make static.
+ (output_format_stringtable): New variable.
+ * msgattrib.c: Include write-catalog.h, write-properties.h,
+ write-stringtable.h.
+ (main): Change handling of --properties-output, --stringtable-output
+ options. Pass the output_syntax to msgdomain_list_print.
+ * msgcat.c: Include write-catalog.h, write-properties.h,
+ write-stringtable.h.
+ (main): Change handling of --properties-output, --stringtable-output
+ options. Pass the output_syntax to msgdomain_list_print.
+ * msgcomm.c: Include write-catalog.h, write-properties.h,
+ write-stringtable.h.
+ (main): Change handling of --properties-output, --stringtable-output
+ options. Pass the output_syntax to msgdomain_list_print.
+ * msgconv.c: Include write-catalog.h, write-properties.h,
+ write-stringtable.h.
+ (main): Change handling of --properties-output, --stringtable-output
+ options. Pass the output_syntax to msgdomain_list_print.
+ * msgen.c: Include write-catalog.h, write-properties.h,
+ write-stringtable.h.
+ (main): Change handling of --properties-output, --stringtable-output
+ options. Pass the output_syntax to msgdomain_list_print.
+ * msgfilter.c: Include write-catalog.h, write-properties.h,
+ write-stringtable.h.
+ (main): Change handling of --properties-output, --stringtable-output
+ options. Pass the output_syntax to msgdomain_list_print.
+ * msggrep.c: Include write-catalog.h, write-properties.h,
+ write-stringtable.h.
+ (main): Change handling of --properties-output, --stringtable-output
+ options. Pass the output_syntax to msgdomain_list_print.
+ * msginit.c: Include write-catalog.h, write-properties.h,
+ write-stringtable.h.
+ (main): Change handling of --properties-output, --stringtable-output
+ options. Pass the output_syntax to msgdomain_list_print.
+ * msgmerge.c: Include write-catalog.h, write-properties.h,
+ write-stringtable.h.
+ (main): Change handling of --properties-output, --stringtable-output
+ options. Pass the output_syntax to msgdomain_list_print.
+ * msgunfmt.c: Include write-catalog.h, write-properties.h,
+ write-stringtable.h.
+ (main): Change handling of --properties-output, --stringtable-output
+ options. Pass the output_syntax to msgdomain_list_print.
+ * msguniq.c: Include write-catalog.h, write-properties.h,
+ write-stringtable.h.
+ (main): Change handling of --properties-output, --stringtable-output
+ options. Pass the output_syntax to msgdomain_list_print.
+ * xgettext.c: Include write-catalog.h, write-properties.h,
+ write-stringtable.h.
+ (output_syntax): Change type to catalog_output_format_ty.
+ (main): Update. Pass the output_syntax to msgdomain_list_print.
+ (finalize_header): Update.
+ * gettext-po.c: Include write-catalog.h.
+ (po_file_write): Specify PO syntax.
+ * Makefile.am (noinst_HEADERS): Add write-catalog.h.
+ (libgettextsrc_la_SOURCES): Add write.catalog.c.
+
2006-10-05 Bruno Haible <bruno@clisp.org>
* lang-table.c (language_table): Add Adangme, Kashubian. Fix the
po-xerror.c
Error handling during writing and reading of PO files.
-write-po.h
-write-po.c
- Output of a list-of-messages to a PO file.
-write-properties.h
-write-properties.c
- Output of a list-of-messages to a Java .properties file.
-write-stringtable.h
-write-stringtable.c
- Output of a list-of-messages to a NeXTstep/GNUstep .strings
- file.
++-------------- Writing PO files
+| write-catalog.h
+| write-catalog.c
+| Output of a list-of-messages.
+| write-po.h
+| write-po.c
+| Output of a list-of-messages to a PO file.
+| write-properties.h
+| write-properties.c
+| Output of a list-of-messages to a Java .properties file.
+| write-stringtable.h
+| write-stringtable.c
+| Output of a list-of-messages to a NeXTstep/GNUstep .strings
+| file.
++-------------- Writing PO files
+-------------- Reading PO files
| open-po.h
po-lex.h open-po.h \
read-po-abstract.h read-po.h read-properties.h read-stringtable.h \
str-list.h \
-write-po.h write-properties.h write-stringtable.h \
+write-catalog.h write-po.h write-properties.h write-stringtable.h \
dir-list.h file-list.h po-gram-gen.h po-gram-gen2.h \
msgl-charset.h msgl-equal.h msgl-iconv.h msgl-ascii.h msgl-cat.h \
msgl-english.h msgl-check.h msgl-fsearch.h msgfmt.h msgunfmt.h \
# libgettextsrc contains all code that is needed by at least two programs.
libgettextsrc_la_SOURCES = \
-$(COMMON_SOURCE) read-po.c write-properties.c write-stringtable.c write-po.c \
+$(COMMON_SOURCE) read-po.c \
+write-catalog.c write-properties.c write-stringtable.c write-po.c \
msgl-ascii.c msgl-iconv.c msgl-equal.c msgl-cat.c msgl-english.c msgl-check.c \
file-list.c msgl-charset.c po-time.c plural-exp.c plural-eval.c plural-table.c \
$(FORMAT_SOURCE)
#include "message.h"
#include "xalloc.h"
#include "read-po.h"
+#include "write-catalog.h"
#include "write-po.h"
#include "error.h"
#include "xerror.h"
(void (*) (int, const message_ty *, const char *, size_t, size_t, int, const char *, const message_ty *, const char *, size_t, size_t, int, const char *))
handler->xerror2;
- msgdomain_list_print (file->mdlp, filename, true, false);
+ msgdomain_list_print (file->mdlp, filename, &output_format_po, true, false);
/* Restore error handler. */
po_xerror = textmode_xerror;
#include "basename.h"
#include "message.h"
#include "read-po.h"
+#include "write-catalog.h"
#include "write-po.h"
+#include "write-properties.h"
+#include "write-stringtable.h"
#include "exit.h"
#include "propername.h"
#include "gettext.h"
msgdomain_list_ty *only_mdlp;
msgdomain_list_ty *ignore_mdlp;
msgdomain_list_ty *result;
+ catalog_output_format_ty output_syntax = &output_format_po;
bool sort_by_msgid = false;
bool sort_by_filepos = false;
break;
case 'p':
- message_print_syntax_properties ();
+ output_syntax = &output_format_properties;
break;
case 'P':
break;
case CHAR_MAX + 17: /* --stringtable-output */
- message_print_syntax_stringtable ();
+ output_syntax = &output_format_stringtable;
break;
case CHAR_MAX + 18: /* --clear-previous */
msgdomain_list_sort_by_msgid (result);
/* Write the PO file. */
- msgdomain_list_print (result, output_file, force_po, false);
+ msgdomain_list_print (result, output_file, output_syntax, force_po, false);
exit (EXIT_SUCCESS);
}
#include "basename.h"
#include "message.h"
#include "read-po.h"
+#include "write-catalog.h"
#include "write-po.h"
+#include "write-properties.h"
+#include "write-stringtable.h"
#include "msgl-cat.h"
#include "exit.h"
#include "propername.h"
const char *files_from;
string_list_ty *file_list;
msgdomain_list_ty *result;
- input_syntax_ty output_syntax = syntax_po;
+ catalog_output_format_ty output_syntax = &output_format_po;
bool sort_by_msgid = false;
bool sort_by_filepos = false;
break;
case 'p':
- message_print_syntax_properties ();
- output_syntax = syntax_properties;
+ output_syntax = &output_format_properties;
break;
case 'P':
break;
case CHAR_MAX + 4: /* --stringtable-output */
- message_print_syntax_stringtable ();
+ output_syntax = &output_format_stringtable;
break;
default:
string_list_append_unique (file_list, argv[cnt]);
/* Read input files, then filter, convert and merge messages. */
- result = catenate_msgdomain_list (file_list,
- output_syntax != syntax_properties
- && output_syntax != syntax_stringtable
- ? to_code
- : "UTF-8");
+ result =
+ catenate_msgdomain_list (file_list,
+ output_syntax->requires_utf8 ? "UTF-8" : to_code);
string_list_free (file_list);
msgdomain_list_sort_by_msgid (result);
/* Write the PO file. */
- msgdomain_list_print (result, output_file, force_po, false);
+ msgdomain_list_print (result, output_file, output_syntax, force_po, false);
exit (EXIT_SUCCESS);
}
#include "basename.h"
#include "message.h"
#include "read-po.h"
+#include "write-catalog.h"
#include "write-po.h"
+#include "write-properties.h"
+#include "write-stringtable.h"
#include "msgl-cat.h"
#include "exit.h"
#include "propername.h"
bool do_help = false;
bool do_version = false;
msgdomain_list_ty *result;
+ catalog_output_format_ty output_syntax = &output_format_po;
bool sort_by_msgid = false;
bool sort_by_filepos = false;
const char *files_from = NULL;
break;
case 'p':
- message_print_syntax_properties ();
+ output_syntax = &output_format_properties;
break;
case 'P':
break;
case CHAR_MAX + 4: /* --stringtable-output */
- message_print_syntax_stringtable ();
+ output_syntax = &output_format_stringtable;
break;
default:
msgdomain_list_sort_by_msgid (result);
/* Write the PO file. */
- msgdomain_list_print (result, output_file, force_po, false);
+ msgdomain_list_print (result, output_file, output_syntax, force_po, false);
exit (EXIT_SUCCESS);
}
#include "basename.h"
#include "message.h"
#include "read-po.h"
+#include "write-catalog.h"
#include "write-po.h"
+#include "write-properties.h"
+#include "write-stringtable.h"
#include "msgl-iconv.h"
#include "localcharset.h"
#include "exit.h"
char *output_file;
const char *input_file;
msgdomain_list_ty *result;
- input_syntax_ty output_syntax = syntax_po;
+ catalog_output_format_ty output_syntax = &output_format_po;
bool sort_by_filepos = false;
bool sort_by_msgid = false;
break;
case 'p':
- message_print_syntax_properties ();
- output_syntax = syntax_properties;
+ output_syntax = &output_format_properties;
break;
case 'P':
break;
case CHAR_MAX + 3: /* --stringtable-output */
- message_print_syntax_stringtable ();
+ output_syntax = &output_format_stringtable;
break;
default:
result = read_po_file (input_file);
/* Convert if and only if the output syntax supports different encodings. */
- if (output_syntax != syntax_properties
- && output_syntax != syntax_stringtable)
+ if (!output_syntax->requires_utf8)
result = iconv_msgdomain_list (result, to_code, input_file);
/* Sort the results. */
msgdomain_list_sort_by_msgid (result);
/* Write the merged message list out. */
- msgdomain_list_print (result, output_file, force_po, false);
+ msgdomain_list_print (result, output_file, output_syntax, force_po, false);
exit (EXIT_SUCCESS);
}
#include "message.h"
#include "read-po.h"
#include "msgl-english.h"
+#include "write-catalog.h"
#include "write-po.h"
+#include "write-properties.h"
+#include "write-stringtable.h"
#include "exit.h"
#include "propername.h"
#include "gettext.h"
bool do_version;
char *output_file;
msgdomain_list_ty *result;
+ catalog_output_format_ty output_syntax = &output_format_po;
bool sort_by_filepos = false;
bool sort_by_msgid = false;
break;
case 'p':
- message_print_syntax_properties ();
+ output_syntax = &output_format_properties;
break;
case 'P':
break;
case CHAR_MAX + 3: /* --stringtable-output */
- message_print_syntax_stringtable ();
+ output_syntax = &output_format_stringtable;
break;
default:
msgdomain_list_sort_by_msgid (result);
/* Write the merged message list out. */
- msgdomain_list_print (result, output_file, force_po, false);
+ msgdomain_list_print (result, output_file, output_syntax, force_po, false);
exit (EXIT_SUCCESS);
}
#include "basename.h"
#include "message.h"
#include "read-po.h"
+#include "write-catalog.h"
#include "write-po.h"
+#include "write-properties.h"
+#include "write-stringtable.h"
#include "msgl-charset.h"
#include "xalloc.h"
#include "exit.h"
char *output_file;
const char *input_file;
msgdomain_list_ty *result;
+ catalog_output_format_ty output_syntax = &output_format_po;
bool sort_by_filepos = false;
bool sort_by_msgid = false;
int i;
break;
case 'p':
- message_print_syntax_properties ();
+ output_syntax = &output_format_properties;
break;
case 'P':
break;
case CHAR_MAX + 5: /* --stringtable-output */
- message_print_syntax_stringtable ();
+ output_syntax = &output_format_stringtable;
break;
default:
msgdomain_list_sort_by_msgid (result);
/* Write the merged message list out. */
- msgdomain_list_print (result, output_file, force_po, false);
+ msgdomain_list_print (result, output_file, output_syntax, force_po, false);
exit (EXIT_SUCCESS);
}
#include "basename.h"
#include "message.h"
#include "read-po.h"
+#include "write-catalog.h"
#include "write-po.h"
+#include "write-properties.h"
+#include "write-stringtable.h"
#include "str-list.h"
#include "msgl-charset.h"
#include "xalloc.h"
const char *input_file;
int grep_pass;
msgdomain_list_ty *result;
+ catalog_output_format_ty output_syntax = &output_format_po;
bool sort_by_filepos = false;
bool sort_by_msgid = false;
size_t i;
break;
case 'p':
- message_print_syntax_properties ();
+ output_syntax = &output_format_properties;
break;
case 'P':
break;
case CHAR_MAX + 8: /* --stringtable-output */
- message_print_syntax_stringtable ();
+ output_syntax = &output_format_stringtable;
break;
default:
msgdomain_list_sort_by_msgid (result);
/* Write the merged message list out. */
- msgdomain_list_print (result, output_file, force_po, false);
+ msgdomain_list_print (result, output_file, output_syntax, force_po, false);
exit (EXIT_SUCCESS);
}
#include "c-strcase.h"
#include "message.h"
#include "read-po.h"
+#include "write-catalog.h"
#include "write-po.h"
+#include "write-properties.h"
+#include "write-stringtable.h"
#include "po-charset.h"
#include "localcharset.h"
#include "po-time.h"
char *output_file;
const char *input_file;
msgdomain_list_ty *result;
+ catalog_output_format_ty output_syntax = &output_format_po;
/* Set program name for messages. */
set_program_name (argv[0]);
break;
case 'p':
- message_print_syntax_properties ();
+ output_syntax = &output_format_properties;
break;
case 'P':
break;
case CHAR_MAX + 4: /* --stringtable-output */
- message_print_syntax_stringtable ();
+ output_syntax = &output_format_stringtable;
break;
default:
result = update_msgstr_plurals (result);
/* Write the modified message list out. */
- msgdomain_list_print (result, output_file, true, false);
+ msgdomain_list_print (result, output_file, output_syntax, true, false);
if (!no_translator)
fprintf (stderr, "\n");
#include "basename.h"
#include "message.h"
#include "read-po.h"
+#include "write-catalog.h"
#include "write-po.h"
+#include "write-properties.h"
+#include "write-stringtable.h"
#include "format.h"
#include "xalloc.h"
#include "xallocsa.h"
char *output_file;
msgdomain_list_ty *def;
msgdomain_list_ty *result;
+ catalog_output_format_ty output_syntax = &output_format_po;
bool sort_by_filepos = false;
bool sort_by_msgid = false;
break;
case 'p':
- message_print_syntax_properties ();
+ output_syntax = &output_format_properties;
break;
case 'P':
break;
case CHAR_MAX + 6: /* --stringtable-output */
- message_print_syntax_stringtable ();
+ output_syntax = &output_format_stringtable;
break;
case CHAR_MAX + 7: /* --previous */
/* In update mode, --properties-input implies --properties-output. */
if (update_mode && input_syntax == syntax_properties)
- message_print_syntax_properties ();
+ output_syntax = &output_format_properties;
/* In update mode, --stringtable-input implies --stringtable-output. */
if (update_mode && input_syntax == syntax_stringtable)
- message_print_syntax_stringtable ();
+ output_syntax = &output_format_stringtable;
/* Merge the two files. */
result = merge (argv[optind], argv[optind + 1], &def);
}
/* Write the merged message list out. */
- msgdomain_list_print (result, output_file, true, false);
+ msgdomain_list_print (result, output_file, output_syntax, true,
+ false);
}
}
else
{
/* Write the merged message list out. */
- msgdomain_list_print (result, output_file, force_po, false);
+ msgdomain_list_print (result, output_file, output_syntax, force_po,
+ false);
}
exit (EXIT_SUCCESS);
#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 "propername.h"
#include "gettext.h"
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. */
break;
case 'p':
- message_print_syntax_properties ();
+ output_syntax = &output_format_properties;
break;
case 'r':
break;
case CHAR_MAX + 3: /* --stringtable-output */
- message_print_syntax_stringtable ();
+ output_syntax = &output_format_stringtable;
break;
case CHAR_MAX + 4: /* --csharp */
msgdomain_list_sort_by_msgid (result);
/* Write the resulting message list to the given .po file. */
- msgdomain_list_print (result, output_file, force_po, false);
+ msgdomain_list_print (result, output_file, output_syntax, force_po, false);
/* No problems. */
exit (EXIT_SUCCESS);
#include "basename.h"
#include "message.h"
#include "read-po.h"
+#include "write-catalog.h"
#include "write-po.h"
+#include "write-properties.h"
+#include "write-stringtable.h"
#include "msgl-cat.h"
#include "exit.h"
#include "propername.h"
const char *input_file;
string_list_ty *file_list;
msgdomain_list_ty *result;
+ catalog_output_format_ty output_syntax = &output_format_po;
bool sort_by_msgid = false;
bool sort_by_filepos = false;
break;
case 'p':
- message_print_syntax_properties ();
+ output_syntax = &output_format_properties;
break;
case 'P':
break;
case CHAR_MAX + 4: /* --stringtable-output */
- message_print_syntax_stringtable ();
+ output_syntax = &output_format_stringtable;
break;
default:
msgdomain_list_sort_by_msgid (result);
/* Write the PO file. */
- msgdomain_list_print (result, output_file, force_po, false);
+ msgdomain_list_print (result, output_file, output_syntax, force_po, false);
exit (EXIT_SUCCESS);
}
#include "xalloc.h"
#include "xallocsa.h"
#include "c-strstr.h"
-#include "fwriteerror.h"
-#include "error-progname.h"
#include "xvasprintf.h"
#include "po-xerror.h"
#include "gettext.h"
}
-/* =========== Some parameters for use by 'msgdomain_list_print'. ========== */
-
-
-/* This variable controls the page width when printing messages.
- Defaults to PAGE_WIDTH if not set. Zero (0) given to message_page_-
- width_set will result in no wrapping being performed. */
-static size_t page_width = PAGE_WIDTH;
-
-void
-message_page_width_set (size_t n)
-{
- if (n == 0)
- {
- page_width = INT_MAX;
- return;
- }
-
- if (n < 20)
- n = 20;
-
- page_width = n;
-}
+/* ========= Some parameters for use by 'msgdomain_list_print_po'. ========= */
/* This variable controls the extent to which the page width applies.
}
-/* Whether to output a file in Java .properties syntax. */
-static bool use_syntax_properties = false;
-
-void
-message_print_syntax_properties ()
-{
- use_syntax_properties = true;
-}
-
-
-/* Whether to output a file in NeXTstep/GNUstep .strings syntax. */
-static bool use_syntax_stringtable = false;
-
-void
-message_print_syntax_stringtable ()
-{
- use_syntax_stringtable = true;
-}
-
-
-/* ================ msgdomain_list_print() and subroutines. ================ */
+/* =============== msgdomain_list_print_po() and subroutines. =============== */
/* A version of memcpy optimized for the case n <= 1. */
static void
wrap (const message_ty *mp, FILE *fp, const char *line_prefix, int extra_indent,
- const char *name, const char *value, enum is_wrap do_wrap,
+ const char *name, const char *value,
+ enum is_wrap do_wrap, size_t page_width,
const char *charset)
{
const char *canon_charset;
static void
message_print (const message_ty *mp, FILE *fp, const char *charset,
- bool blank_line, bool debug)
+ size_t page_width, bool blank_line, bool debug)
{
int extra_indent;
/* Print the previous msgid. This helps the translator when the msgid has
only slightly changed. */
if (mp->prev_msgctxt != NULL)
- wrap (mp, fp, "#| ", 0, "msgctxt", mp->prev_msgctxt, mp->do_wrap, charset);
+ wrap (mp, fp, "#| ", 0, "msgctxt", mp->prev_msgctxt, mp->do_wrap,
+ page_width, charset);
if (mp->prev_msgid != NULL)
- wrap (mp, fp, "#| ", 0, "msgid", mp->prev_msgid, mp->do_wrap, charset);
+ wrap (mp, fp, "#| ", 0, "msgid", mp->prev_msgid, mp->do_wrap, page_width,
+ charset);
if (mp->prev_msgid_plural != NULL)
wrap (mp, fp, "#| ", 0, "msgid_plural", mp->prev_msgid_plural, mp->do_wrap,
- charset);
+ page_width, charset);
extra_indent = (mp->prev_msgctxt != NULL || mp->prev_msgid != NULL
|| mp->prev_msgid_plural != NULL
? 3
}
if (mp->msgctxt != NULL)
wrap (mp, fp, NULL, extra_indent, "msgctxt", mp->msgctxt, mp->do_wrap,
- charset);
- wrap (mp, fp, NULL, extra_indent, "msgid", mp->msgid, mp->do_wrap, charset);
+ page_width, charset);
+ wrap (mp, fp, NULL, extra_indent, "msgid", mp->msgid, mp->do_wrap,
+ page_width, charset);
if (mp->msgid_plural != NULL)
wrap (mp, fp, NULL, extra_indent, "msgid_plural", mp->msgid_plural,
- mp->do_wrap, charset);
+ mp->do_wrap, page_width, charset);
if (mp->msgid_plural == NULL)
wrap (mp, fp, NULL, extra_indent, "msgstr", mp->msgstr, mp->do_wrap,
- charset);
+ page_width, charset);
else
{
char prefix_buf[20];
{
sprintf (prefix_buf, "msgstr[%u]", i);
wrap (mp, fp, NULL, extra_indent, prefix_buf, p, mp->do_wrap,
- charset);
+ page_width, charset);
}
}
}
static void
message_print_obsolete (const message_ty *mp, FILE *fp, const char *charset,
- bool blank_line)
+ size_t page_width, bool blank_line)
{
int extra_indent;
/* Print the previous msgid. This helps the translator when the msgid has
only slightly changed. */
if (mp->prev_msgctxt != NULL)
- wrap (mp, fp, "#~| ", 0, "msgctxt", mp->prev_msgctxt, mp->do_wrap, charset);
+ wrap (mp, fp, "#~| ", 0, "msgctxt", mp->prev_msgctxt, mp->do_wrap,
+ page_width, charset);
if (mp->prev_msgid != NULL)
- wrap (mp, fp, "#~| ", 0, "msgid", mp->prev_msgid, mp->do_wrap, charset);
+ wrap (mp, fp, "#~| ", 0, "msgid", mp->prev_msgid, mp->do_wrap, page_width,
+ charset);
if (mp->prev_msgid_plural != NULL)
wrap (mp, fp, "#~| ", 0, "msgid_plural", mp->prev_msgid_plural, mp->do_wrap,
- charset);
+ page_width, charset);
extra_indent = (mp->prev_msgctxt != NULL || mp->prev_msgid != NULL
|| mp->prev_msgid_plural != NULL
? 1
}
if (mp->msgctxt != NULL)
wrap (mp, fp, "#~ ", extra_indent, "msgctxt", mp->msgctxt, mp->do_wrap,
- charset);
- wrap (mp, fp, "#~ ", extra_indent, "msgid", mp->msgid, mp->do_wrap, charset);
+ page_width, charset);
+ wrap (mp, fp, "#~ ", extra_indent, "msgid", mp->msgid, mp->do_wrap,
+ page_width, charset);
if (mp->msgid_plural != NULL)
wrap (mp, fp, "#~ ", extra_indent, "msgid_plural", mp->msgid_plural,
- mp->do_wrap, charset);
+ mp->do_wrap, page_width, charset);
if (mp->msgid_plural == NULL)
wrap (mp, fp, "#~ ", extra_indent, "msgstr", mp->msgstr, mp->do_wrap,
- charset);
+ page_width, charset);
else
{
char prefix_buf[20];
{
sprintf (prefix_buf, "msgstr[%u]", i);
wrap (mp, fp, "#~ ", extra_indent, prefix_buf, p, mp->do_wrap,
- charset);
+ page_width, charset);
}
}
}
static void
-msgdomain_list_print_po (msgdomain_list_ty *mdlp, FILE *fp, bool debug)
+msgdomain_list_print_po (msgdomain_list_ty *mdlp, FILE *fp, size_t page_width,
+ bool debug)
{
size_t j, k;
bool blank_line;
for (j = 0; j < mlp->nitems; ++j)
if (!mlp->item[j]->obsolete)
{
- message_print (mlp->item[j], fp, charset, blank_line, debug);
+ message_print (mlp->item[j], fp, charset, page_width, blank_line,
+ debug);
blank_line = true;
}
for (j = 0; j < mlp->nitems; ++j)
if (mlp->item[j]->obsolete)
{
- message_print_obsolete (mlp->item[j], fp, charset, blank_line);
+ message_print_obsolete (mlp->item[j], fp, charset, page_width,
+ blank_line);
blank_line = true;
}
}
-void
-msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename,
- bool force, bool debug)
-{
- FILE *fp;
-
- /* We will not write anything if, for every domain, we have no message
- or only the header entry. */
- if (!force)
- {
- bool found_nonempty = false;
- size_t k;
-
- for (k = 0; k < mdlp->nitems; k++)
- {
- message_list_ty *mlp = mdlp->item[k]->messages;
-
- if (!(mlp->nitems == 0
- || (mlp->nitems == 1 && is_header (mlp->item[0]))))
- {
- found_nonempty = true;
- break;
- }
- }
-
- if (!found_nonempty)
- return;
- }
-
- /* Check whether the output format can accomodate all messages. */
- if (use_syntax_properties || use_syntax_stringtable)
- {
- if (mdlp->nitems > 1)
- {
- if (use_syntax_properties)
- po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, _("\
-Cannot output multiple translation domains into a single file with Java .properties syntax. Try using PO file syntax instead."));
- if (use_syntax_stringtable)
- po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, _("\
-Cannot output multiple translation domains into a single file with NeXTstep/GNUstep .strings syntax."));
- }
- if (mdlp->nitems == 1)
- {
- message_list_ty *mlp = mdlp->item[0]->messages;
- const lex_pos_ty *has_context;
- const lex_pos_ty *has_plural;
- size_t j;
-
- has_context = NULL;
- for (j = 0; j < mlp->nitems; j++)
- {
- message_ty *mp = mlp->item[j];
-
- if (mp->msgctxt != NULL)
- {
- has_context = &mp->pos;
- break;
- }
- }
-
- if (has_context != NULL)
- {
- error_with_progname = false;
- po_xerror (PO_SEVERITY_FATAL_ERROR, NULL,
- has_context->file_name, has_context->line_number,
- (size_t)(-1), false, _("\
-message catalog has context dependent translations, but the output format does not support them."));
- error_with_progname = true;
- }
-
- has_plural = NULL;
- for (j = 0; j < mlp->nitems; j++)
- {
- message_ty *mp = mlp->item[j];
-
- if (mp->msgid_plural != NULL)
- {
- has_plural = &mp->pos;
- break;
- }
- }
-
- if (has_plural != NULL)
- {
- error_with_progname = false;
- if (use_syntax_properties)
- po_xerror (PO_SEVERITY_FATAL_ERROR, NULL,
- has_plural->file_name, has_plural->line_number,
- (size_t)(-1), false, _("\
-message catalog has plural form translations, but the output format does not support them. Try generating a Java class using \"msgfmt --java\", instead of a properties file."));
- if (use_syntax_stringtable)
- po_xerror (PO_SEVERITY_FATAL_ERROR, NULL,
- has_plural->file_name, has_plural->line_number,
- (size_t)(-1), false, _("\
-message catalog has plural form translations, but the output format does not support them."));
- error_with_progname = true;
- }
- }
- }
-
- /* Open the output file. */
- if (filename != NULL && strcmp (filename, "-") != 0
- && strcmp (filename, "/dev/stdout") != 0)
- {
- fp = fopen (filename, "w");
- if (fp == NULL)
- {
- const char *errno_description = strerror (errno);
- po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false,
- xasprintf ("%s: %s",
- xasprintf (_("cannot create output file \"%s\""),
- filename),
- errno_description));
- }
- }
- else
- {
- fp = stdout;
- /* xgettext:no-c-format */
- filename = _("standard output");
- }
-
- if (use_syntax_properties)
- msgdomain_list_print_properties (mdlp, fp, page_width, debug);
- else if (use_syntax_stringtable)
- msgdomain_list_print_stringtable (mdlp, fp, page_width, debug);
- else
- msgdomain_list_print_po (mdlp, fp, debug);
-
- /* Make sure nothing went wrong. */
- if (fwriteerror (fp))
- {
- const char *errno_description = strerror (errno);
- po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false,
- xasprintf ("%s: %s",
- xasprintf (_("error while writing \"%s\" file"),
- filename),
- errno_description));
- }
-}
-
-
-/* =============================== Sorting. ================================ */
-
-
-static int
-cmp_by_msgid (const void *va, const void *vb)
-{
- const message_ty *a = *(const message_ty **) va;
- const message_ty *b = *(const message_ty **) vb;
- /* Because msgids normally contain only ASCII characters, it is OK to
- sort them as if we were in the C locale. And strcoll() in the C locale
- is the same as strcmp(). */
- return strcmp (a->msgid, b->msgid);
-}
-
-
-void
-msgdomain_list_sort_by_msgid (msgdomain_list_ty *mdlp)
-{
- size_t k;
-
- for (k = 0; k < mdlp->nitems; k++)
- {
- message_list_ty *mlp = mdlp->item[k]->messages;
-
- if (mlp->nitems > 0)
- qsort (mlp->item, mlp->nitems, sizeof (mlp->item[0]), cmp_by_msgid);
- }
-}
-
-
-/* Sort the file positions of every message. */
-
-static int
-cmp_filepos (const void *va, const void *vb)
-{
- const lex_pos_ty *a = (const lex_pos_ty *) va;
- const lex_pos_ty *b = (const lex_pos_ty *) vb;
- int cmp;
-
- cmp = strcmp (a->file_name, b->file_name);
- if (cmp == 0)
- cmp = (int) a->line_number - (int) b->line_number;
-
- return cmp;
-}
-
-static void
-msgdomain_list_sort_filepos (msgdomain_list_ty *mdlp)
-{
- size_t j, k;
-
- for (k = 0; k < mdlp->nitems; k++)
- {
- message_list_ty *mlp = mdlp->item[k]->messages;
-
- for (j = 0; j < mlp->nitems; j++)
- {
- message_ty *mp = mlp->item[j];
-
- if (mp->filepos_count > 0)
- qsort (mp->filepos, mp->filepos_count, sizeof (mp->filepos[0]),
- cmp_filepos);
- }
- }
-}
-
-
-/* Sort the messages according to the file position. */
-
-static int
-cmp_by_filepos (const void *va, const void *vb)
+/* Describes a PO file in .po syntax. */
+const struct catalog_output_format output_format_po =
{
- const message_ty *a = *(const message_ty **) va;
- const message_ty *b = *(const message_ty **) vb;
- int cmp;
-
- /* No filepos is smaller than any other filepos. */
- if (a->filepos_count == 0)
- {
- if (b->filepos_count != 0)
- return -1;
- }
- if (b->filepos_count == 0)
- return 1;
-
- /* Compare on the file names... */
- cmp = strcmp (a->filepos[0].file_name, b->filepos[0].file_name);
- if (cmp != 0)
- return cmp;
-
- /* If they are equal, compare on the line numbers... */
- cmp = a->filepos[0].line_number - b->filepos[0].line_number;
- if (cmp != 0)
- return cmp;
-
- /* If they are equal, compare on the msgid strings. */
- /* Because msgids normally contain only ASCII characters, it is OK to
- sort them as if we were in the C locale. And strcoll() in the C locale
- is the same as strcmp(). */
- return strcmp (a->msgid, b->msgid);
-}
-
-
-void
-msgdomain_list_sort_by_filepos (msgdomain_list_ty *mdlp)
-{
- size_t k;
-
- /* It makes sense to compare filepos[0] of different messages only after
- the filepos[] array of each message has been sorted. Sort it now. */
- msgdomain_list_sort_filepos (mdlp);
-
- for (k = 0; k < mdlp->nitems; k++)
- {
- message_list_ty *mlp = mdlp->item[k]->messages;
-
- if (mlp->nitems > 0)
- qsort (mlp->item, mlp->nitems, sizeof (mlp->item[0]), cmp_by_filepos);
- }
-}
+ msgdomain_list_print_po, /* print */
+ false, /* requires_utf8 */
+ true, /* supports_multiple_domains */
+ true, /* supports_contexts */
+ true, /* supports_plurals */
+ false, /* alternative_is_po */
+ false /* alternative_is_java_class */
+};
/* GNU gettext - internationalization aids
- Copyright (C) 1995-1998, 2000-2003 Free Software Foundation, Inc.
+ Copyright (C) 1995-1998, 2000-2003, 2006 Free Software Foundation, Inc.
This file was written by Peter Miller <millerp@canb.auug.org.au>
message_print_comment_flags (const message_ty *mp, FILE *fp,
bool debug);
-/* These functions set some parameters for use by 'msgdomain_list_print'. */
-extern void
- message_page_width_set (size_t width);
+/* These functions set some parameters for use by 'output_format_po.print'. */
extern void
message_page_width_ignore (void);
extern void
message_print_style_uniforum (void);
extern void
message_print_style_escape (bool flag);
-extern void
- message_print_syntax_properties (void);
-extern void
- message_print_syntax_stringtable (void);
-/* Output MDLP into a PO file with the given FILENAME, according to the
- parameters set by the functions above. */
-extern void
- msgdomain_list_print (msgdomain_list_ty *mdlp,
- const char *filename,
- bool force, bool debug);
-
-/* Sort MDLP destructively according to the given criterion. */
-extern void
- msgdomain_list_sort_by_msgid (msgdomain_list_ty *mdlp);
-extern void
- msgdomain_list_sort_by_filepos (msgdomain_list_ty *mdlp);
+/* Describes a PO file in .po syntax. */
+extern const struct catalog_output_format output_format_po;
#ifdef __cplusplus
/* Writing Java .properties files.
- Copyright (C) 2003, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2005-2006 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2003.
This program is free software; you can redistribute it and/or modify
}
/* Output the contents of a PO file in Java .properties syntax. */
-void
+static void
msgdomain_list_print_properties (msgdomain_list_ty *mdlp, FILE *fp,
size_t page_width, bool debug)
{
mlp = message_list_alloc (false);
write_properties (fp, mlp, mdlp->encoding, page_width, debug);
}
+
+/* Describes a PO file in Java .properties syntax. */
+const struct catalog_output_format output_format_properties =
+{
+ msgdomain_list_print_properties, /* print */
+ true, /* requires_utf8 */
+ false, /* supports_multiple_domains */
+ false, /* supports_contexts */
+ false, /* supports_plurals */
+ true, /* alternative_is_po */
+ true /* alternative_is_java_class */
+};
/* Writing Java .properties files.
- Copyright (C) 2003 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2006 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2003.
This program is free software; you can redistribute it and/or modify
#ifndef _WRITE_PROPERTIES_H
#define _WRITE_PROPERTIES_H
-#include <stdbool.h>
-#include <stdio.h>
-#include <stddef.h>
+#include "write-catalog.h"
-#include "message.h"
-
-/* Output the contents of a PO file in Java .properties syntax. */
-extern void
- msgdomain_list_print_properties (msgdomain_list_ty *mdlp, FILE *fp,
- size_t page_width, bool debug);
+/* Describes a PO file in Java .properties syntax. */
+extern const struct catalog_output_format output_format_properties;
#endif /* _WRITE_PROPERTIES_H */
}
/* Output the contents of a PO file in .strings syntax. */
-void
+static void
msgdomain_list_print_stringtable (msgdomain_list_ty *mdlp, FILE *fp,
size_t page_width, bool debug)
{
mlp = message_list_alloc (false);
write_stringtable (fp, mlp, mdlp->encoding, page_width, debug);
}
+
+/* Describes a PO file in .strings syntax. */
+const struct catalog_output_format output_format_stringtable =
+{
+ msgdomain_list_print_stringtable, /* print */
+ true, /* requires_utf8 */
+ false, /* supports_multiple_domains */
+ false, /* supports_contexts */
+ false, /* supports_plurals */
+ false, /* alternative_is_po */
+ false /* alternative_is_java_class */
+};
/* Writing NeXTstep/GNUstep .strings files.
- Copyright (C) 2003 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2006 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2003.
This program is free software; you can redistribute it and/or modify
#ifndef _WRITE_STRINGTABLE_H
#define _WRITE_STRINGTABLE_H
-#include <stdbool.h>
-#include <stdio.h>
-#include <stddef.h>
+#include "write-catalog.h"
-#include "message.h"
-
-/* Output the contents of a PO file in .strings syntax. */
-extern void
- msgdomain_list_print_stringtable (msgdomain_list_ty *mdlp, FILE *fp,
- size_t page_width, bool debug);
+/* Describes a PO file in .strings syntax. */
+extern const struct catalog_output_format output_format_stringtable;
#endif /* _WRITE_STRINGTABLE_H */
#include "msgl-iconv.h"
#include "msgl-ascii.h"
#include "po-time.h"
+#include "write-catalog.h"
#include "write-po.h"
+#include "write-properties.h"
+#include "write-stringtable.h"
#include "format.h"
#include "propername.h"
#include "gettext.h"
static char *output_dir;
/* The output syntax: .pot or .properties or .strings. */
-static input_syntax_ty output_syntax = syntax_po;
+static catalog_output_format_ty output_syntax = &output_format_po;
/* If nonzero omit header with information about this run. */
int xgettext_omit_header;
msgid_bugs_address = optarg;
break;
case CHAR_MAX + 6: /* --properties-output */
- message_print_syntax_properties ();
- output_syntax = syntax_properties;
+ output_syntax = &output_format_properties;
break;
case CHAR_MAX + 7: /* --stringtable-output */
- message_print_syntax_stringtable ();
- output_syntax = syntax_stringtable;
+ output_syntax = &output_format_stringtable;
break;
case CHAR_MAX + 8: /* --flag */
xgettext_record_flag (optarg);
msgdomain_list_sort_by_msgid (mdlp);
/* Write the PO file. */
- msgdomain_list_print (mdlp, file_name, force_po, do_debug);
+ msgdomain_list_print (mdlp, file_name, output_syntax, force_po, do_debug);
exit (EXIT_SUCCESS);
}
has_nonascii = true;
}
- if (has_nonascii
- || output_syntax == syntax_properties
- || output_syntax == syntax_stringtable)
+ if (has_nonascii || output_syntax->requires_utf8)
{
message_list_ty *mlp = mdlp->item[0]->messages;