From: Bruno Haible Date: Mon, 16 Oct 2006 12:28:26 +0000 (+0000) Subject: Create an object-oriented interface for the catalog output formats. X-Git-Tag: 0.16.x-branchpoint~83 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8f51f17d196ca7c160715194a4943f815060297;p=thirdparty%2Fgettext.git Create an object-oriented interface for the catalog output formats. --- diff --git a/gettext-tools/po/ChangeLog b/gettext-tools/po/ChangeLog index 27e8b0ec0..01887182a 100644 --- a/gettext-tools/po/ChangeLog +++ b/gettext-tools/po/ChangeLog @@ -1,3 +1,7 @@ +2006-10-15 Bruno Haible + + * POTFILES.in: Add src/write-catalog.c. + 2006-10-02 Bruno Haible * fr.po: Update from Christophe Combelles . diff --git a/gettext-tools/po/POTFILES.in b/gettext-tools/po/POTFILES.in index b3a6fdbf5..755bba6e3 100644 --- a/gettext-tools/po/POTFILES.in +++ b/gettext-tools/po/POTFILES.in @@ -83,6 +83,7 @@ src/read-stringtable.c 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 diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 31ade8826..116e89ea4 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,95 @@ +2006-10-15 Bruno Haible + + * 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 * lang-table.c (language_table): Add Adangme, Kashubian. Fix the diff --git a/gettext-tools/src/FILES b/gettext-tools/src/FILES index 3fbd06142..905de77ef 100644 --- a/gettext-tools/src/FILES +++ b/gettext-tools/src/FILES @@ -42,16 +42,21 @@ po-xerror.h 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 diff --git a/gettext-tools/src/Makefile.am b/gettext-tools/src/Makefile.am index 6f0addec2..613f537cd 100644 --- a/gettext-tools/src/Makefile.am +++ b/gettext-tools/src/Makefile.am @@ -40,7 +40,7 @@ noinst_HEADERS = pos.h message.h po-error.h po-xerror.h po-gram.h po-charset.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 \ @@ -123,7 +123,8 @@ format-php.c format-gcc-internal.c format-qt.c format-boost.c # 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) diff --git a/gettext-tools/src/gettext-po.c b/gettext-tools/src/gettext-po.c index 597f14852..1982c3d26 100644 --- a/gettext-tools/src/gettext-po.c +++ b/gettext-tools/src/gettext-po.c @@ -33,6 +33,7 @@ #include "message.h" #include "xalloc.h" #include "read-po.h" +#include "write-catalog.h" #include "write-po.h" #include "error.h" #include "xerror.h" @@ -222,7 +223,7 @@ po_file_write (po_file_t file, const char *filename, po_xerror_handler_t handler (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; diff --git a/gettext-tools/src/msgattrib.c b/gettext-tools/src/msgattrib.c index 276ff098b..aefbcd064 100644 --- a/gettext-tools/src/msgattrib.c +++ b/gettext-tools/src/msgattrib.c @@ -36,7 +36,10 @@ #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" @@ -135,6 +138,7 @@ main (int argc, char **argv) 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; @@ -203,7 +207,7 @@ main (int argc, char **argv) break; case 'p': - message_print_syntax_properties (); + output_syntax = &output_format_properties; break; case 'P': @@ -299,7 +303,7 @@ main (int argc, char **argv) break; case CHAR_MAX + 17: /* --stringtable-output */ - message_print_syntax_stringtable (); + output_syntax = &output_format_stringtable; break; case CHAR_MAX + 18: /* --clear-previous */ @@ -366,7 +370,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ 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); } diff --git a/gettext-tools/src/msgcat.c b/gettext-tools/src/msgcat.c index 26b9f69fa..60346fff5 100644 --- a/gettext-tools/src/msgcat.c +++ b/gettext-tools/src/msgcat.c @@ -38,7 +38,10 @@ #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" @@ -104,7 +107,7 @@ main (int argc, char **argv) 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; @@ -198,8 +201,7 @@ main (int argc, char **argv) break; case 'p': - message_print_syntax_properties (); - output_syntax = syntax_properties; + output_syntax = &output_format_properties; break; case 'P': @@ -249,7 +251,7 @@ main (int argc, char **argv) break; case CHAR_MAX + 4: /* --stringtable-output */ - message_print_syntax_stringtable (); + output_syntax = &output_format_stringtable; break; default: @@ -300,11 +302,9 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ 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); @@ -315,7 +315,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ 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); } diff --git a/gettext-tools/src/msgcomm.c b/gettext-tools/src/msgcomm.c index 933abb95d..6303cc3aa 100644 --- a/gettext-tools/src/msgcomm.c +++ b/gettext-tools/src/msgcomm.c @@ -38,7 +38,10 @@ #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" @@ -104,6 +107,7 @@ main (int argc, char *argv[]) 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; @@ -196,7 +200,7 @@ main (int argc, char *argv[]) break; case 'p': - message_print_syntax_properties (); + output_syntax = &output_format_properties; break; case 'P': @@ -246,7 +250,7 @@ main (int argc, char *argv[]) break; case CHAR_MAX + 4: /* --stringtable-output */ - message_print_syntax_stringtable (); + output_syntax = &output_format_stringtable; break; default: @@ -321,7 +325,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ 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); } diff --git a/gettext-tools/src/msgconv.c b/gettext-tools/src/msgconv.c index 89767a0ac..f98f4cc2d 100644 --- a/gettext-tools/src/msgconv.c +++ b/gettext-tools/src/msgconv.c @@ -36,7 +36,10 @@ #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" @@ -96,7 +99,7 @@ main (int argc, char **argv) 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; @@ -160,8 +163,7 @@ main (int argc, char **argv) break; case 'p': - message_print_syntax_properties (); - output_syntax = syntax_properties; + output_syntax = &output_format_properties; break; case 'P': @@ -203,7 +205,7 @@ main (int argc, char **argv) break; case CHAR_MAX + 3: /* --stringtable-output */ - message_print_syntax_stringtable (); + output_syntax = &output_format_stringtable; break; default: @@ -257,8 +259,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ 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. */ @@ -268,7 +269,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ 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); } diff --git a/gettext-tools/src/msgen.c b/gettext-tools/src/msgen.c index 9280e590f..3b8a4890e 100644 --- a/gettext-tools/src/msgen.c +++ b/gettext-tools/src/msgen.c @@ -37,7 +37,10 @@ #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" @@ -90,6 +93,7 @@ main (int argc, char **argv) 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; @@ -151,7 +155,7 @@ main (int argc, char **argv) break; case 'p': - message_print_syntax_properties (); + output_syntax = &output_format_properties; break; case 'P': @@ -189,7 +193,7 @@ main (int argc, char **argv) break; case CHAR_MAX + 3: /* --stringtable-output */ - message_print_syntax_stringtable (); + output_syntax = &output_format_stringtable; break; default: @@ -246,7 +250,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ 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); } diff --git a/gettext-tools/src/msgfilter.c b/gettext-tools/src/msgfilter.c index 1407b8f77..2120a6d7d 100644 --- a/gettext-tools/src/msgfilter.c +++ b/gettext-tools/src/msgfilter.c @@ -54,7 +54,10 @@ #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" @@ -149,6 +152,7 @@ main (int argc, char **argv) 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; @@ -216,7 +220,7 @@ main (int argc, char **argv) break; case 'p': - message_print_syntax_properties (); + output_syntax = &output_format_properties; break; case 'P': @@ -262,7 +266,7 @@ main (int argc, char **argv) break; case CHAR_MAX + 5: /* --stringtable-output */ - message_print_syntax_stringtable (); + output_syntax = &output_format_stringtable; break; default: @@ -374,7 +378,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ 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); } diff --git a/gettext-tools/src/msggrep.c b/gettext-tools/src/msggrep.c index f9ca9657d..f6823ce25 100644 --- a/gettext-tools/src/msggrep.c +++ b/gettext-tools/src/msggrep.c @@ -47,7 +47,10 @@ #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" @@ -146,6 +149,7 @@ main (int argc, char **argv) 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; @@ -310,7 +314,7 @@ error while reading \"%s\""), optarg); break; case 'p': - message_print_syntax_properties (); + output_syntax = &output_format_properties; break; case 'P': @@ -376,7 +380,7 @@ error while reading \"%s\""), optarg); break; case CHAR_MAX + 8: /* --stringtable-output */ - message_print_syntax_stringtable (); + output_syntax = &output_format_stringtable; break; default: @@ -464,7 +468,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ 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); } diff --git a/gettext-tools/src/msginit.c b/gettext-tools/src/msginit.c index 9d462cebc..05595a4c6 100644 --- a/gettext-tools/src/msginit.c +++ b/gettext-tools/src/msginit.c @@ -60,7 +60,10 @@ #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" @@ -148,6 +151,7 @@ main (int argc, char **argv) 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]); @@ -202,7 +206,7 @@ main (int argc, char **argv) break; case 'p': - message_print_syntax_properties (); + output_syntax = &output_format_properties; break; case 'P': @@ -236,7 +240,7 @@ main (int argc, char **argv) break; case CHAR_MAX + 4: /* --stringtable-output */ - message_print_syntax_stringtable (); + output_syntax = &output_format_stringtable; break; default: @@ -323,7 +327,7 @@ the output .po file through the --output-file option.\n"), 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"); diff --git a/gettext-tools/src/msgmerge.c b/gettext-tools/src/msgmerge.c index 12725879a..181bde660 100644 --- a/gettext-tools/src/msgmerge.c +++ b/gettext-tools/src/msgmerge.c @@ -38,7 +38,10 @@ #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" @@ -159,6 +162,7 @@ main (int argc, char **argv) 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; @@ -236,7 +240,7 @@ main (int argc, char **argv) break; case 'p': - message_print_syntax_properties (); + output_syntax = &output_format_properties; break; case 'P': @@ -294,7 +298,7 @@ main (int argc, char **argv) break; case CHAR_MAX + 6: /* --stringtable-output */ - message_print_syntax_stringtable (); + output_syntax = &output_format_stringtable; break; case CHAR_MAX + 7: /* --previous */ @@ -371,10 +375,10 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ /* 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); @@ -417,13 +421,15 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ } /* 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); diff --git a/gettext-tools/src/msgunfmt.c b/gettext-tools/src/msgunfmt.c index b82602efb..2e0cf236e 100644 --- a/gettext-tools/src/msgunfmt.c +++ b/gettext-tools/src/msgunfmt.c @@ -41,7 +41,10 @@ #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" @@ -117,6 +120,7 @@ main (int argc, char **argv) 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. */ @@ -181,7 +185,7 @@ main (int argc, char **argv) break; case 'p': - message_print_syntax_properties (); + output_syntax = &output_format_properties; break; case 'r': @@ -224,7 +228,7 @@ main (int argc, char **argv) break; case CHAR_MAX + 3: /* --stringtable-output */ - message_print_syntax_stringtable (); + output_syntax = &output_format_stringtable; break; case CHAR_MAX + 4: /* --csharp */ @@ -393,7 +397,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ 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); diff --git a/gettext-tools/src/msguniq.c b/gettext-tools/src/msguniq.c index 379bbdfa7..fe6e1fddd 100644 --- a/gettext-tools/src/msguniq.c +++ b/gettext-tools/src/msguniq.c @@ -37,7 +37,10 @@ #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" @@ -100,6 +103,7 @@ main (int argc, char **argv) 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; @@ -174,7 +178,7 @@ main (int argc, char **argv) break; case 'p': - message_print_syntax_properties (); + output_syntax = &output_format_properties; break; case 'P': @@ -225,7 +229,7 @@ main (int argc, char **argv) break; case CHAR_MAX + 4: /* --stringtable-output */ - message_print_syntax_stringtable (); + output_syntax = &output_format_stringtable; break; default: @@ -288,7 +292,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ 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); } diff --git a/gettext-tools/src/write-po.c b/gettext-tools/src/write-po.c index de35b7b9f..631f2047b 100644 --- a/gettext-tools/src/write-po.c +++ b/gettext-tools/src/write-po.c @@ -44,8 +44,6 @@ #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" @@ -317,28 +315,7 @@ message_print_comment_flags (const message_ty *mp, FILE *fp, bool debug) } -/* =========== 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. @@ -378,27 +355,7 @@ message_print_style_escape (bool flag) } -/* 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. */ @@ -419,7 +376,8 @@ memcpy_small (void *dst, const void *src, size_t n) 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; @@ -838,7 +796,7 @@ print_blank_line (FILE *fp) 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; @@ -867,12 +825,14 @@ message_print (const message_ty *mp, FILE *fp, const char *charset, /* 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 @@ -907,15 +867,16 @@ different from yours. Consider using a pure ASCII msgid instead.\n\ } 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]; @@ -928,7 +889,7 @@ different from yours. Consider using a pure ASCII msgid instead.\n\ { sprintf (prefix_buf, "msgstr[%u]", i); wrap (mp, fp, NULL, extra_indent, prefix_buf, p, mp->do_wrap, - charset); + page_width, charset); } } } @@ -936,7 +897,7 @@ different from yours. Consider using a pure ASCII msgid instead.\n\ 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; @@ -978,12 +939,14 @@ message_print_obsolete (const message_ty *mp, FILE *fp, const char *charset, /* 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 @@ -1017,15 +980,16 @@ different from yours. Consider using a pure ASCII msgid instead.\n\ } 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]; @@ -1038,14 +1002,15 @@ different from yours. Consider using a pure ASCII msgid instead.\n\ { 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; @@ -1108,7 +1073,8 @@ msgdomain_list_print_po (msgdomain_list_ty *mdlp, FILE *fp, bool debug) 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; } @@ -1116,7 +1082,8 @@ msgdomain_list_print_po (msgdomain_list_ty *mdlp, FILE *fp, bool debug) 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; } @@ -1126,265 +1093,14 @@ msgdomain_list_print_po (msgdomain_list_ty *mdlp, FILE *fp, bool debug) } -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 */ +}; diff --git a/gettext-tools/src/write-po.h b/gettext-tools/src/write-po.h index ef947c75a..1095047a8 100644 --- a/gettext-tools/src/write-po.h +++ b/gettext-tools/src/write-po.h @@ -1,5 +1,5 @@ /* 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 @@ -51,9 +51,7 @@ extern void 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 @@ -62,23 +60,9 @@ 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 diff --git a/gettext-tools/src/write-properties.c b/gettext-tools/src/write-properties.c index 0e74f2053..8406a9262 100644 --- a/gettext-tools/src/write-properties.c +++ b/gettext-tools/src/write-properties.c @@ -1,5 +1,5 @@ /* 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 , 2003. This program is free software; you can redistribute it and/or modify @@ -273,7 +273,7 @@ write_properties (FILE *fp, message_list_ty *mlp, const char *canon_encoding, } /* 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) { @@ -285,3 +285,15 @@ msgdomain_list_print_properties (msgdomain_list_ty *mdlp, FILE *fp, 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 */ +}; diff --git a/gettext-tools/src/write-properties.h b/gettext-tools/src/write-properties.h index a866a6987..def010a2f 100644 --- a/gettext-tools/src/write-properties.h +++ b/gettext-tools/src/write-properties.h @@ -1,5 +1,5 @@ /* Writing Java .properties files. - Copyright (C) 2003 Free Software Foundation, Inc. + Copyright (C) 2003, 2006 Free Software Foundation, Inc. Written by Bruno Haible , 2003. This program is free software; you can redistribute it and/or modify @@ -19,15 +19,9 @@ #ifndef _WRITE_PROPERTIES_H #define _WRITE_PROPERTIES_H -#include -#include -#include +#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 */ diff --git a/gettext-tools/src/write-stringtable.c b/gettext-tools/src/write-stringtable.c index 7a5fa5f0e..619a282bc 100644 --- a/gettext-tools/src/write-stringtable.c +++ b/gettext-tools/src/write-stringtable.c @@ -297,7 +297,7 @@ write_stringtable (FILE *fp, message_list_ty *mlp, const char *canon_encoding, } /* 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) { @@ -309,3 +309,15 @@ msgdomain_list_print_stringtable (msgdomain_list_ty *mdlp, FILE *fp, 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 */ +}; diff --git a/gettext-tools/src/write-stringtable.h b/gettext-tools/src/write-stringtable.h index 07dad1689..e2fd6b9a6 100644 --- a/gettext-tools/src/write-stringtable.h +++ b/gettext-tools/src/write-stringtable.h @@ -1,5 +1,5 @@ /* Writing NeXTstep/GNUstep .strings files. - Copyright (C) 2003 Free Software Foundation, Inc. + Copyright (C) 2003, 2006 Free Software Foundation, Inc. Written by Bruno Haible , 2003. This program is free software; you can redistribute it and/or modify @@ -19,15 +19,9 @@ #ifndef _WRITE_STRINGTABLE_H #define _WRITE_STRINGTABLE_H -#include -#include -#include +#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 */ diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c index 6c0c81c24..ac0a46f33 100644 --- a/gettext-tools/src/xgettext.c +++ b/gettext-tools/src/xgettext.c @@ -58,7 +58,10 @@ #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" @@ -132,7 +135,7 @@ static const char *msgstr_suffix; 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; @@ -486,12 +489,10 @@ main (int argc, char *argv[]) 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); @@ -722,7 +723,7 @@ warning: file `%s' extension `%s' is unknown; will try C"), filename, extension) 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); } @@ -2888,9 +2889,7 @@ finalize_header (msgdomain_list_ty *mdlp) 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;