#include "read-properties.h"
#include "read-stringtable.h"
#include "msgl-english.h"
+#include "msgl-ascii.h"
#include "msgl-header.h"
+#include "c-strstr.h"
+#include "xalloc.h"
#include "write-catalog.h"
#include "write-po.h"
#include "write-properties.h"
/* Forward declaration of local functions. */
_GL_NORETURN_FUNC static void usage (int status);
+static msgdomain_list_ty *fill_header (msgdomain_list_ty *mdlp);
int
/* Read input file. */
result = read_catalog_file (argv[optind], input_syntax);
+ if (!output_syntax->requires_utf8)
+ /* Fill the header entry. */
+ result = fill_header (result);
+
/* Add English translations. */
result = msgdomain_list_english (result);
exit (status);
}
+
+/* Fill the templates in the most essential fields of the header entry,
+ namely to force a charset name. */
+static msgdomain_list_ty *
+fill_header (msgdomain_list_ty *mdlp)
+{
+ size_t k, j;
+
+ if (mdlp->encoding == NULL
+ && is_ascii_msgdomain_list (mdlp))
+ mdlp->encoding = "ASCII";
+
+ if (mdlp->encoding != NULL)
+ for (k = 0; k < mdlp->nitems; k++)
+ {
+ message_list_ty *mlp = mdlp->item[k]->messages;
+
+ if (mlp->nitems > 0)
+ {
+ message_ty *header_mp = NULL;
+
+ /* Search the header entry. */
+ for (j = 0; j < mlp->nitems; j++)
+ if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete)
+ {
+ header_mp = mlp->item[j];
+ break;
+ }
+
+ /* If it wasn't found, provide one. */
+ if (header_mp == NULL)
+ {
+ static lex_pos_ty pos = { __FILE__, __LINE__ };
+ const char *msgstr =
+ "Content-Type: text/plain; charset=CHARSET\n"
+ "Content-Transfer-Encoding: 8bit\n";
+
+ header_mp =
+ message_alloc (NULL, "", NULL, msgstr, strlen (msgstr), &pos);
+ message_list_prepend (mlp, header_mp);
+ }
+
+ /* Fill in the charset name. */
+ {
+ const char *header = header_mp->msgstr;
+ const char *charsetstr = c_strstr (header, "charset=");
+ if (charsetstr != NULL)
+ {
+ charsetstr += strlen ("charset=");
+ header_set_charset (header_mp, charsetstr, mdlp->encoding);
+ }
+ }
+
+ /* Finally remove the fuzzy attribute. */
+ header_mp->is_fuzzy = false;
+ }
+ }
+
+ return mdlp;
+}
# Test general operation.
-cat <<\EOF > men-test1.po
+cat <<\EOF > men-test1.pot
# HEADER.
#
msgid ""
msgstr ""
-"Content-Type: text/plain; charset=ASCII\n"
+"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "height must be positive"
EOF
: ${MSGEN=msgen}
-${MSGEN} -o men-test1.tmp men-test1.po || Exit 1
+${MSGEN} -o men-test1.tmp men-test1.pot || Exit 1
LC_ALL=C tr -d '\r' < men-test1.tmp > men-test1.out || Exit 1
cat <<\EOF > men-test1.ok
test $result = 0 || exit $result
# Test --lang option.
-${MSGEN} --lang=fr -o men-test1.tmp men-test1.po || Exit 1
+${MSGEN} --lang=fr -o men-test1.tmp men-test1.pot || Exit 1
grep "Language: fr" men-test1.tmp 2>&1 >/dev/null || Exit 1
grep -v "Language: fr" men-test1.tmp | LC_ALL=C tr -d '\r' > men-test1.out || Exit 1