No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / gettext / gettext-tools / src / msgl-charset.c
blob114f877e1a22d11627508e1052fac84af0fd8b8b
1 /* Message list charset and locale charset handling.
2 Copyright (C) 2001-2003 Free Software Foundation, Inc.
3 Written by Bruno Haible <haible@clisp.cons.org>, 2001.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 #endif
23 #include <alloca.h>
25 /* Specification. */
26 #include "msgl-charset.h"
28 #include <stddef.h>
29 #include <string.h>
31 #include "po-charset.h"
32 #include "localcharset.h"
33 #include "error.h"
34 #include "progname.h"
35 #include "basename.h"
36 #include "xallocsa.h"
37 #include "xerror.h"
38 #include "message.h"
39 #include "strstr.h"
40 #include "exit.h"
41 #include "gettext.h"
43 #define _(str) gettext (str)
45 void
46 compare_po_locale_charsets (const msgdomain_list_ty *mdlp)
48 const char *locale_code;
49 const char *canon_locale_code;
50 bool warned;
51 size_t j, k;
53 /* Check whether the locale encoding and the PO file's encoding are the
54 same. Otherwise emit a warning. */
55 locale_code = locale_charset ();
56 canon_locale_code = po_charset_canonicalize (locale_code);
57 warned = false;
58 for (k = 0; k < mdlp->nitems; k++)
60 const message_list_ty *mlp = mdlp->item[k]->messages;
62 for (j = 0; j < mlp->nitems; j++)
63 if (mlp->item[j]->msgid[0] == '\0' && !mlp->item[j]->obsolete)
65 const char *header = mlp->item[j]->msgstr;
67 if (header != NULL)
69 const char *charsetstr = strstr (header, "charset=");
71 if (charsetstr != NULL)
73 size_t len;
74 char *charset;
75 const char *canon_charset;
77 charsetstr += strlen ("charset=");
78 len = strcspn (charsetstr, " \t\n");
79 charset = (char *) xallocsa (len + 1);
80 memcpy (charset, charsetstr, len);
81 charset[len] = '\0';
83 canon_charset = po_charset_canonicalize (charset);
84 if (canon_charset == NULL)
85 error (EXIT_FAILURE, 0,
86 _("\
87 present charset \"%s\" is not a portable encoding name"),
88 charset);
89 freesa (charset);
90 if (canon_locale_code != canon_charset)
92 multiline_warning (xasprintf (_("warning: ")),
93 xasprintf (_("\
94 Locale charset \"%s\" is different from\n\
95 input file charset \"%s\".\n\
96 Output of '%s' might be incorrect.\n\
97 Possible workarounds are:\n\
98 "), locale_code, canon_charset, basename (program_name)));
99 multiline_warning (NULL,
100 xasprintf (_("\
101 - Set LC_ALL to a locale with encoding %s.\n\
102 "), canon_charset));
103 if (canon_locale_code != NULL)
104 multiline_warning (NULL,
105 xasprintf (_("\
106 - Convert the translation catalog to %s using 'msgconv',\n\
107 then apply '%s',\n\
108 then convert back to %s using 'msgconv'.\n\
109 "), canon_locale_code, basename (program_name), canon_charset));
110 if (strcmp (canon_charset, "UTF-8") != 0
111 && (canon_locale_code == NULL
112 || strcmp (canon_locale_code, "UTF-8") != 0))
113 multiline_warning (NULL,
114 xasprintf (_("\
115 - Set LC_ALL to a locale with encoding %s,\n\
116 convert the translation catalog to %s using 'msgconv',\n\
117 then apply '%s',\n\
118 then convert back to %s using 'msgconv'.\n\
119 "), "UTF-8", "UTF-8", basename (program_name), canon_charset));
120 warned = true;
126 if (canon_locale_code == NULL && !warned)
127 multiline_warning (xasprintf (_("warning: ")),
128 xasprintf (_("\
129 Locale charset \"%s\" is not a portable encoding name.\n\
130 Output of '%s' might be incorrect.\n\
131 A possible workaround is to set LC_ALL=C.\n\
132 "), locale_code, basename (program_name)));