diff options
author | Bruno Haible <bruno@clisp.org> | 2001-06-11 12:10:46 +0000 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2001-06-11 12:10:46 +0000 |
commit | add265baa4b9434a44ec6777765c0b50c8b9caaf (patch) | |
tree | 08ceebed3c12c7699c70a8206aa3ca1e4a75b1a0 | |
parent | b495b3ff383bbcdde01f052f020b282183261766 (diff) | |
download | external_gettext-add265baa4b9434a44ec6777765c0b50c8b9caaf.zip external_gettext-add265baa4b9434a44ec6777765c0b50c8b9caaf.tar.gz external_gettext-add265baa4b9434a44ec6777765c0b50c8b9caaf.tar.bz2 |
msgfmt: Add .mo suffix to output files generated for domain directives.
-rw-r--r-- | src/ChangeLog | 15 | ||||
-rw-r--r-- | src/msgfmt.c | 50 | ||||
-rw-r--r-- | tests/ChangeLog | 5 | ||||
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rwxr-xr-x | tests/msgfmt-5 | 74 |
5 files changed, 122 insertions, 24 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 34de819..5eb3bf8 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,18 @@ +2001-06-10 Bruno Haible <haible@clisp.cons.org> + + * msgfmt.c: Change the --strict option to not apply to domain + directives, only to the output filename argument. + (struct msg_domain): Add file_name field. + (domain_list): Renamed from domain. + (new_domain): Add file_name argument. + (main): Pass file name to new_domain(). Use file_name passed to + new_domain() in fopen call; don't free it. + (new_domain): New argument 'file_name'. + (format_directive_domain): Always ensure ".mo" suffix, independently + of --strict. + (format_directive_message): Likewise. + (add_mo_suffix): Don't call xstrdup. + 2001-06-01 Bruno Haible <haible@clisp.cons.org> * Makefile.am (datadir): Remove definition. diff --git a/src/msgfmt.c b/src/msgfmt.c index 338dc52..69951f4 100644 --- a/src/msgfmt.c +++ b/src/msgfmt.c @@ -112,10 +112,12 @@ struct msg_domain hash_table symbol_tab; /* Name of domain these ID/String pairs are part of. */ const char *domain_name; + /* Output file name. */ + const char *file_name; /* Link to the next domain. */ struct msg_domain *next; }; -static struct msg_domain *domain; +static struct msg_domain *domain_list; static struct msg_domain *current_domain; /* If not zero list duplicate message identifiers. */ @@ -178,7 +180,8 @@ static void format_directive_message PARAMS ((po_ty *__pop, char *__msgid, int __obsolete)); static void format_comment_special PARAMS ((po_ty *pop, const char *s)); static void format_debrief PARAMS ((po_ty *)); -static struct msg_domain *new_domain PARAMS ((const char *name)); +static struct msg_domain *new_domain PARAMS ((const char *name, + const char *file_name)); static int compare_id PARAMS ((const void *pval1, const void *pval2)); static void write_table PARAMS ((FILE *output_file, hash_table *tab)); static void check_pair PARAMS ((const char *msgid, const lex_pos_ty *msgid_pos, @@ -197,6 +200,7 @@ main (argc, argv) int do_help = 0; int do_version = 0; int strict_uniforum = 0; + struct msg_domain *domain; /* Set default value for global variables. */ alignment = DEFAULT_OUTPUT_ALIGNMENT; @@ -288,7 +292,10 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ /* The -o option determines the name of the domain and therefore the output file. */ if (output_file_name != NULL) - current_domain = new_domain (output_file_name); + current_domain = + new_domain (output_file_name, + strict_uniforum ? add_mo_suffix (output_file_name) + : output_file_name); /* Prepare PO file reader. We need to see the comments because inexact translations must be reported. */ @@ -309,7 +316,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ ++optind; } - while (domain != NULL) + for (domain = domain_list; domain != NULL; domain = domain->next) { FILE *output_file; @@ -323,10 +330,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ } else { - const char *fname; - - fname = strict_uniforum ? add_mo_suffix (domain->domain_name) - : domain->domain_name; + const char *fname = domain->file_name; output_file = fopen (fname, "wb"); if (output_file == NULL) @@ -335,9 +339,6 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ _("error while opening \"%s\" for writing"), fname); exit_status = EXIT_FAILURE; } - - if (strict_uniforum) - free ((void *) fname); } if (output_file != NULL) @@ -347,8 +348,6 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ fclose (output_file); } } - - domain = domain->next; } /* Print statistics if requested. */ @@ -449,22 +448,26 @@ Giving the -v option more than once increases the verbosity level.\n\ static struct msg_domain * -new_domain (name) +new_domain (name, file_name) const char *name; + const char *file_name; { - struct msg_domain **p_dom = &domain; + struct msg_domain **p_dom = &domain_list; while (*p_dom != NULL && strcmp (name, (*p_dom)->domain_name) != 0) p_dom = &(*p_dom)->next; if (*p_dom == NULL) { - *p_dom = (struct msg_domain *) xmalloc (sizeof (**p_dom)); + struct msg_domain *domain; - if (init_hash (&(*p_dom)->symbol_tab, 100) != 0) + domain = (struct msg_domain *) xmalloc (sizeof (struct msg_domain)); + if (init_hash (&domain->symbol_tab, 100) != 0) error (EXIT_FAILURE, errno, _("while creating hash table")); - (*p_dom)->domain_name = name; - (*p_dom)->next = NULL; + domain->domain_name = name; + domain->file_name = file_name; + domain->next = NULL; + *p_dom = domain; } return *p_dom; @@ -536,7 +539,7 @@ domain name \"%s\" not suitable as file name: will use prefix"), name); } /* Set new domain. */ - current_domain = new_domain (name); + current_domain = new_domain (name, add_mo_suffix (name)); } else { @@ -676,7 +679,8 @@ some header fields still have the initial default value")); /* Check whether already a domain is specified. If not use default domain. */ if (current_domain == NULL) - current_domain = new_domain ("messages"); + current_domain = new_domain (MESSAGE_DOMAIN_DEFAULT, + add_mo_suffix (MESSAGE_DOMAIN_DEFAULT)); /* We insert the ID/string pair into the hashing table. But we have to take care for duplicates. */ @@ -1114,9 +1118,9 @@ add_mo_suffix (fname) len = strlen (fname); if (len > 3 && memcmp (fname + len - 3, ".mo", 3) == 0) - return xstrdup (fname); + return fname; if (len > 4 && memcmp (fname + len - 4, ".gmo", 4) == 0) - return xstrdup (fname); + return fname; result = (char *) xmalloc (len + 4); stpcpy (stpcpy (result, fname), ".mo"); return result; diff --git a/tests/ChangeLog b/tests/ChangeLog index 83f2b56..546d424 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,5 +1,10 @@ 2001-06-10 Bruno Haible <haible@clisp.cons.org> + * msgfmt-5: New file. + * Makefile.am (TESTS): Add it. + +2001-06-10 Bruno Haible <haible@clisp.cons.org> + * msgcmp-2: Add program name prefix to expected output. * msgmerge-2: Likewise. diff --git a/tests/Makefile.am b/tests/Makefile.am index 79e0f42..0d777b5 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -24,7 +24,7 @@ TESTS = gettext-1 gettext-2 \ msgcomm-1 msgcomm-2 msgcomm-3 msgcomm-4 msgcomm-5 msgcomm-6 msgcomm-7 \ msgcomm-8 msgcomm-9 msgcomm-10 msgcomm-11 msgcomm-12 msgcomm-13 \ msgcomm-14 msgcomm-15 msgcomm-16 \ - msgfmt-1 msgfmt-2 msgfmt-3 msgfmt-4 \ + msgfmt-1 msgfmt-2 msgfmt-3 msgfmt-4 msgfmt-5 \ msgmerge-1 msgmerge-2 msgmerge-3 msgmerge-4 msgmerge-5 msgmerge-6 \ msgmerge-7 msgmerge-8 msgmerge-9 \ msgunfmt-1 \ diff --git a/tests/msgfmt-5 b/tests/msgfmt-5 new file mode 100755 index 0000000..f19dbef --- /dev/null +++ b/tests/msgfmt-5 @@ -0,0 +1,74 @@ +#! /bin/sh + +# Test multi-domain handling. + +tmpfiles="" +trap 'rm -fr $tmpfiles' 1 2 3 15 + +tmpfiles="foo.po" +cat <<EOF > foo.po +domain "foo-de" +msgid "" +msgstr "Content-Type: text/plain; charset=ISO-8859-1\n" + +# Das ist ein Kommentar. +msgid "hello" +msgstr "Hallo" + +# Noch einer. +msgid "bye" +msgstr "Tschüß" + +domain "foo-fr" +msgid "" +msgstr "Content-Type: text/plain; charset=ISO-8859-1\n" + +# Ceci est un commentaire. +msgid "hello" +msgstr "Salut" + +# Encore un. +msgid "bye" +msgstr "A bientôt" +EOF + +tmpfiles="$tmpfiles foo-de.mo foo-fr.mo" +: ${MSGFMT=msgfmt} +${MSGFMT} foo.po + +tmpfiles="$tmpfiles foo-de.out foo-fr.out" +: ${MSGUNFMT=msgunfmt} +${MSGUNFMT} foo-de.mo -o foo-de.out +${MSGUNFMT} foo-fr.mo -o foo-fr.out + +tmpfiles="$tmpfiles foo-de.ok" +cat <<EOF > foo-de.ok +msgid "" +msgstr "Content-Type: text/plain; charset=ISO-8859-1\n" + +msgid "bye" +msgstr "Tschüß" + +msgid "hello" +msgstr "Hallo" +EOF + +tmpfiles="$tmpfiles foo-fr.ok" +cat <<EOF > foo-fr.ok +msgid "" +msgstr "Content-Type: text/plain; charset=ISO-8859-1\n" + +msgid "bye" +msgstr "A bientôt" + +msgid "hello" +msgstr "Salut" +EOF + +: ${DIFF=diff} +${DIFF} foo-de.ok foo-de.out && ${DIFF} foo-fr.ok foo-fr.out +result=$? + +rm -fr $tmpfiles + +exit $result |