+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.
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. */
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,
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;
/* 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. */
++optind;
}
- while (domain != NULL)
+ for (domain = domain_list; domain != NULL; domain = domain->next)
{
FILE *output_file;
}
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)
_("error while opening \"%s\" for writing"), fname);
exit_status = EXIT_FAILURE;
}
-
- if (strict_uniforum)
- free ((void *) fname);
}
if (output_file != NULL)
fclose (output_file);
}
}
-
- domain = domain->next;
}
/* Print statistics if requested. */
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;
}
/* Set new domain. */
- current_domain = new_domain (name);
+ current_domain = new_domain (name, add_mo_suffix (name));
}
else
{
/* 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. */
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;
--- /dev/null
+#! /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