From: Bruno Haible Date: Wed, 22 May 2002 12:37:46 +0000 (+0000) Subject: Make it possible to use msgcat and msgconv on POT files. X-Git-Tag: v0.11.3~47 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=60bde90ee3ff5e61f1f6b4f078436f840e0deda5;p=thirdparty%2Fgettext.git Make it possible to use msgcat and msgconv on POT files. --- diff --git a/src/ChangeLog b/src/ChangeLog index 21d8e70c2..fc498fd7d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,20 @@ +2002-05-22 Bruno Haible + + * msgl-iconv.h (iconv_message_list): Add from_filename argument. + (iconv_msgdomain_list): Likewise. + * msgl-iconv.c (iconv_message_list): Add from_filename argument. + Don't give an error for POT files containing charset=CHARSET. + (iconv_msgdomain_list): Add from_filename argument. + * msgl-cat.c (catenate_msgdomain_list): Don't give an error for + POT files containing charset=CHARSET. Pass input file name to + iconv_message_list. + * msgconv.c (main): Pass input file name to iconv_msgdomain_list. + * write-java.c (msgdomain_write_java): Update. + * write-tcl.c (msgdomain_write_tcl): Update. + * x-glade.c (do_extract_glade): Update. + * x-python.c (extract_python): Update. + * x-tcl.c (extract_tcl): Update. + 2002-05-18 Bruno Haible * Makefile.am (RM): New variable. diff --git a/src/msgconv.c b/src/msgconv.c index 49c2ccc08..4447aef50 100644 --- a/src/msgconv.c +++ b/src/msgconv.c @@ -223,7 +223,8 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ to_code = locale_charset (); /* Read input file and convert. */ - result = iconv_msgdomain_list (read_po_file (input_file), to_code); + result = iconv_msgdomain_list (read_po_file (input_file), to_code, + input_file); /* Sort the results. */ if (sort_by_filepos) diff --git a/src/msgl-cat.c b/src/msgl-cat.c index c0a23b98e..d1807e378 100644 --- a/src/msgl-cat.c +++ b/src/msgl-cat.c @@ -1,5 +1,5 @@ /* Message list concatenation and duplicate handling. - Copyright (C) 2001 Free Software Foundation, Inc. + Copyright (C) 2001-2002 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software; you can redistribute it and/or modify @@ -170,10 +170,24 @@ catenate_msgdomain_list (file_list, to_code) canon_charset = po_charset_canonicalize (charset); if (canon_charset == NULL) - error (EXIT_FAILURE, 0, - _("\ + { + /* Don't give an error for POT files, because + POT files usually contain only ASCII + msgids. */ + const char *filename = files[n]; + size_t filenamelen = strlen (filename); + + if (filenamelen >= 4 + && memcmp (filename + filenamelen - 4, + ".pot", 4) == 0 + && strcmp (charset, "CHARSET") == 0) + canon_charset = po_charset_ascii; + else + error (EXIT_FAILURE, 0, + _("\ present charset \"%s\" is not a portable encoding name"), - charset); + charset); + } if (canon_from_code == NULL) canon_from_code = canon_charset; @@ -448,7 +462,7 @@ To select a different output encoding, use the --to-code option.\n\ header entry with its canonical equivalent. */ if (!(to_code == NULL && canon_charsets[n][k] == canon_to_code)) iconv_message_list (mdlp->item[k]->messages, canon_charsets[n][k], - canon_to_code); + canon_to_code, files[n]); } /* Fill the resulting messages. */ diff --git a/src/msgl-iconv.c b/src/msgl-iconv.c index 28d1f1747..6620cfdd2 100644 --- a/src/msgl-iconv.c +++ b/src/msgl-iconv.c @@ -260,10 +260,11 @@ convert_msgstr (cd, mp) void -iconv_message_list (mlp, canon_from_code, canon_to_code) +iconv_message_list (mlp, canon_from_code, canon_to_code, from_filename) message_list_ty *mlp; const char *canon_from_code; const char *canon_to_code; + const char *from_filename; { bool canon_from_code_overridden = (canon_from_code != NULL); size_t j; @@ -300,10 +301,24 @@ iconv_message_list (mlp, canon_from_code, canon_to_code) if (canon_charset == NULL) { if (!canon_from_code_overridden) - error (EXIT_FAILURE, 0, - _("\ + { + /* Don't give an error for POT files, because POT + files usually contain only ASCII msgids. */ + const char *filename = from_filename; + size_t filenamelen; + + if (filename != NULL + && (filenamelen = strlen (filename)) >= 4 + && memcmp (filename + filenamelen - 4, ".pot", 4) + == 0 + && strcmp (charset, "CHARSET") == 0) + canon_charset = po_charset_ascii; + else + error (EXIT_FAILURE, 0, + _("\ present charset \"%s\" is not a portable encoding name"), - charset); + charset); + } } else { @@ -376,9 +391,10 @@ This version was built without iconv()."), } msgdomain_list_ty * -iconv_msgdomain_list (mdlp, to_code) +iconv_msgdomain_list (mdlp, to_code, from_filename) msgdomain_list_ty *mdlp; const char *to_code; + const char *from_filename; { const char *canon_to_code; size_t k; @@ -391,7 +407,8 @@ iconv_msgdomain_list (mdlp, to_code) to_code); for (k = 0; k < mdlp->nitems; k++) - iconv_message_list (mdlp->item[k]->messages, NULL, canon_to_code); + iconv_message_list (mdlp->item[k]->messages, NULL, canon_to_code, + from_filename); return mdlp; } diff --git a/src/msgl-iconv.h b/src/msgl-iconv.h index 66e9a15d9..45cd5def3 100644 --- a/src/msgl-iconv.h +++ b/src/msgl-iconv.h @@ -1,5 +1,5 @@ /* Message list character set conversion. - Copyright (C) 2001 Free Software Foundation, Inc. + Copyright (C) 2001-2002 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software; you can redistribute it and/or modify @@ -28,11 +28,13 @@ extern void iconv_message_list PARAMS ((message_list_ty *mlp, const char *canon_from_code, - const char *canon_to_code)); + const char *canon_to_code, + const char *from_filename)); /* Converts all the message lists in MDLP to the encoding TO_CODE. */ extern msgdomain_list_ty * iconv_msgdomain_list PARAMS ((msgdomain_list_ty *mdlp, - const char *to_code)); + const char *to_code, + const char *from_filename)); #endif /* _MSGL_ICONV_H */ diff --git a/src/write-java.c b/src/write-java.c index 21a244a2c..c53370ecd 100644 --- a/src/write-java.c +++ b/src/write-java.c @@ -1,5 +1,5 @@ /* Writing Java ResourceBundles. - Copyright (C) 2001 Free Software Foundation, Inc. + Copyright (C) 2001-2002 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software; you can redistribute it and/or modify @@ -1094,7 +1094,7 @@ msgdomain_write_java (mlp, resource_name, locale_name, directory, assume_java2) retval = 1; /* Convert the messages to Unicode. */ - iconv_message_list (mlp, NULL, po_charset_canonicalize ("UTF-8")); + iconv_message_list (mlp, NULL, po_charset_canonicalize ("UTF-8"), NULL); cleanup_list.tmpdir = NULL; cleanup_list.subdir_count = 0; diff --git a/src/write-tcl.c b/src/write-tcl.c index 0ba0337e4..9533a1108 100644 --- a/src/write-tcl.c +++ b/src/write-tcl.c @@ -174,7 +174,7 @@ but the Tcl message catalog format doesn't support plural handling\n"))); } /* Convert the messages to Unicode. */ - iconv_message_list (mlp, NULL, po_charset_canonicalize ("UTF-8")); + iconv_message_list (mlp, NULL, po_charset_canonicalize ("UTF-8"), NULL); /* Now create the file. */ { diff --git a/src/x-glade.c b/src/x-glade.c index 10d1f2fe9..715c0599d 100644 --- a/src/x-glade.c +++ b/src/x-glade.c @@ -418,7 +418,7 @@ error while reading \"%s\""), real_filename); if (!is_ascii_message_list (mlp)) { const char *canon_utf_8 = po_charset_canonicalize ("UTF-8"); - iconv_message_list (mlp, canon_utf_8, canon_utf_8); + iconv_message_list (mlp, canon_utf_8, canon_utf_8, NULL); } /* Close scanner. */ diff --git a/src/x-python.c b/src/x-python.c index da76b5200..6f719ccd3 100644 --- a/src/x-python.c +++ b/src/x-python.c @@ -1181,7 +1181,7 @@ extract_python (f, real_filename, logical_filename, mdlp) if (!is_ascii_message_list (mlp)) { const char *canon_utf_8 = po_charset_canonicalize ("UTF-8"); - iconv_message_list (mlp, canon_utf_8, canon_utf_8); + iconv_message_list (mlp, canon_utf_8, canon_utf_8, NULL); } fp = NULL; diff --git a/src/x-tcl.c b/src/x-tcl.c index c23843b67..a942796de 100644 --- a/src/x-tcl.c +++ b/src/x-tcl.c @@ -1023,7 +1023,7 @@ extract_tcl (f, real_filename, logical_filename, mdlp) if (!is_ascii_message_list (mlp)) { const char *canon_utf_8 = po_charset_canonicalize ("UTF-8"); - iconv_message_list (mlp, canon_utf_8, canon_utf_8); + iconv_message_list (mlp, canon_utf_8, canon_utf_8, NULL); } fp = NULL;