1 --- gnupg-1.4.0/util/strgutil.c 2004-11-17 15:50:58.000000000 +0000
2 +++ /tmp/dpep.GtChya/gnupg-1.4.0/util/strgutil.c 2005-02-05 00:53:22.921264222 +0000
4 /* strgutil.c - string utilities
5 * Copyright (C) 1994, 1998, 1999, 2000, 2001,
6 - * 2003 Free Software Foundation, Inc.
7 + * 2003, 2004, 2005 Free Software Foundation, Inc.
9 * This file is part of GnuPG.
13 log_info (_("error loading `%s': %s\n"),
14 "iconv.dll", dlerror ());
15 + log_info(_("please see http://www.gnupg.org/download/iconv.html "
16 + "for more information\n"));
21 handle_iconv_error (const char *to, const char *from, int use_fallback)
24 - log_error (_("conversion from `%s' to `%s' not available\n"),
27 + static int shown1, shown2;
30 + if (to && !strcmp (to, "utf-8"))
42 + log_info (_("conversion from `%s' to `%s' not available\n"),
46 - log_error (_("iconv_open failed: %s\n"), strerror (errno));
51 + log_info (_("iconv_open failed: %s\n"), strerror (errno));
60 static char codepage[30];
62 + const char *aliases;
64 /* We are a console program thus we need to use the
65 - GetConsoleOutputCP fucntion and not the the GetACP which
66 + GetConsoleOutputCP function and not the the GetACP which
67 would give the codepage for a GUI program. Note this is
68 not a bulletproof detection because GetConsoleCP might
69 - retrun a different one for console input. Not sure how to
71 - sprintf (codepage, "CP%u", (unsigned int)GetConsoleOutputCP ());
72 - /* If it is the Windows name for Latin-1 we use the standard
73 - name instead to avoid loading of iconv.dll. Unfortunately
74 - it is often CP850 and we don't have a custom translation
76 - if (!strcmp (codepage, "CP1252"))
77 - newset = "iso-8859-1";
80 + return a different one for console input. Not sure how to
81 + cope with that. If the console Code page is not known we
82 + fall back to the system code page. */
83 + cpno = GetConsoleOutputCP ();
86 + sprintf (codepage, "CP%u", cpno );
87 + /* Resolve alias. We use a long string string and not the
88 + usual array to optimize if the code is taken to a DSO.
89 + Taken from libiconv 1.9.2. */
91 + for (aliases = ("CP936" "\0" "GBK" "\0"
92 + "CP1361" "\0" "JOHAB" "\0"
93 + "CP20127" "\0" "ASCII" "\0"
94 + "CP20866" "\0" "KOI8-R" "\0"
95 + "CP21866" "\0" "KOI8-RU" "\0"
96 + "CP28591" "\0" "ISO-8859-1" "\0"
97 + "CP28592" "\0" "ISO-8859-2" "\0"
98 + "CP28593" "\0" "ISO-8859-3" "\0"
99 + "CP28594" "\0" "ISO-8859-4" "\0"
100 + "CP28595" "\0" "ISO-8859-5" "\0"
101 + "CP28596" "\0" "ISO-8859-6" "\0"
102 + "CP28597" "\0" "ISO-8859-7" "\0"
103 + "CP28598" "\0" "ISO-8859-8" "\0"
104 + "CP28599" "\0" "ISO-8859-9" "\0"
105 + "CP28605" "\0" "ISO-8859-15" "\0");
107 + aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1)
109 + if (!strcmp (codepage, aliases) ||(*aliases == '*' && !aliases[1]))
111 + newset = aliases + strlen (aliases) + 1;
117 #ifdef HAVE_LANGINFO_CODESET
118 newset = nl_langinfo (CODESET);
120 - newset = "iso-8859-1";
122 +#else /* !HAVE_LANGINFO_CODESET */
123 + /* Try to get the used charset from environment variables. */
124 + static char codepage[30];
125 + const char *lc, *dot, *mod;
127 + strcpy (codepage, "iso-8859-1");
128 + lc = getenv ("LC_ALL");
130 + lc = getenv ("LC_CTYPE");
132 + lc = getenv ("LANG");
135 + dot = strchr (lc, '.');
137 + mod = strchr (++dot, '@');
139 + mod = dot + strlen (dot);
140 + if (mod - dot < sizeof codepage && dot != mod) {
141 + memcpy (codepage, dot, mod - dot);
142 + codepage [mod - dot] = 0;
147 +#endif /* !HAVE_LANGINFO_CODESET */
155 + /* Note that we silently assume that plain ASCII is actually meant
156 + as Latin-1. This makes sense because many Unix system don't
157 + have their locale set up properly and thus would get annoying
158 + error messages and we have to handle all the "bug"
159 + reports. Latin-1 has always been the character set used for 8
160 + bit characters on Unix systems. */
162 || !ascii_strcasecmp (newset, "8859-1" )
163 - || !ascii_strcasecmp (newset, "8859-15" ) ) {
164 + || !ascii_strcasecmp (newset, "646" )
165 + || !ascii_strcasecmp (newset, "ASCII" )
166 + || !ascii_strcasecmp (newset, "ANSI_X3.4-1968" )
168 active_charset_name = "iso-8859-1";
170 active_charset = NULL;
172 if ( iconv (cd, (ICONV_CONST char **)&inptr, &inbytes,
173 &outptr, &outbytes) == (size_t)-1)
175 - log_error (_("conversion from `%s' to `%s' failed: %s\n"),
176 - active_charset_name, "utf-8", strerror (errno));
180 + log_info (_("conversion from `%s' to `%s' failed: %s\n"),
181 + active_charset_name, "utf-8", strerror (errno));
183 /* We don't do any conversion at all but use the strings as is. */
184 strcpy (buffer, string);
186 @@ -919,8 +1007,12 @@
187 outbuf = outptr = m_alloc (outbytes);
188 if ( iconv (cd, (ICONV_CONST char **)&inptr, &inbytes,
189 &outptr, &outbytes) == (size_t)-1) {
190 - log_error (_("conversion from `%s' to `%s' failed: %s\n"),
191 - "utf-8", active_charset_name, strerror (errno));
195 + log_info (_("conversion from `%s' to `%s' failed: %s\n"),
196 + "utf-8", active_charset_name, strerror (errno));
198 /* Didn't worked out. Temporary disable the use of
199 * iconv and fall back to our old code. */