8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/port/chklocale.c,v 1.3 2007/09/29 00:01:43 tgl Exp $
11
+ * $PostgreSQL: pgsql/src/port/chklocale.c,v 1.4 2007/10/03 17:16:39 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
27
27
#include "mb/pg_wchar.h"
28
28
29
29
30
- #if defined(HAVE_LANGINFO_H ) && defined(CODESET )
31
-
32
30
/*
33
31
* This table needs to recognize all the CODESET spellings for supported
34
32
* backend encodings, as well as frontend-only encodings where possible
35
33
* (the latter case is currently only needed for initdb to recognize
36
- * error situations).
34
+ * error situations). On Windows, we rely on entries for codepage
35
+ * numbers (CPnnn).
37
36
*
38
37
* Note that we search the table with pg_strcasecmp(), so variant
39
38
* capitalizations don't need their own entries.
@@ -49,23 +48,27 @@ static const struct encoding_match encoding_match_list[] = {
49
48
{PG_EUC_JP , "eucJP" },
50
49
{PG_EUC_JP , "IBM-eucJP" },
51
50
{PG_EUC_JP , "sdeckanji" },
51
+ {PG_EUC_JP , "CP20932" },
52
52
53
53
{PG_EUC_CN , "EUC-CN" },
54
54
{PG_EUC_CN , "eucCN" },
55
55
{PG_EUC_CN , "IBM-eucCN" },
56
56
{PG_EUC_CN , "GB2312" },
57
57
{PG_EUC_CN , "dechanzi" },
58
+ {PG_EUC_CN , "CP20936" },
58
59
59
60
{PG_EUC_KR , "EUC-KR" },
60
61
{PG_EUC_KR , "eucKR" },
61
62
{PG_EUC_KR , "IBM-eucKR" },
62
63
{PG_EUC_KR , "deckorean" },
63
64
{PG_EUC_KR , "5601" },
65
+ {PG_EUC_KR , "CP51949" }, /* or 20949 ? */
64
66
65
67
{PG_EUC_TW , "EUC-TW" },
66
68
{PG_EUC_TW , "eucTW" },
67
69
{PG_EUC_TW , "IBM-eucTW" },
68
70
{PG_EUC_TW , "cns11643" },
71
+ /* No codepage for EUC-TW ? */
69
72
70
73
{PG_UTF8 , "UTF-8" },
71
74
{PG_UTF8 , "utf8" },
@@ -111,6 +114,7 @@ static const struct encoding_match encoding_match_list[] = {
111
114
{PG_LATIN10 , "iso885916" },
112
115
113
116
{PG_KOI8R , "KOI8-R" },
117
+ {PG_KOI8R , "CP20866" },
114
118
115
119
{PG_WIN1252 , "CP1252" },
116
120
{PG_WIN1253 , "CP1253" },
@@ -143,23 +147,56 @@ static const struct encoding_match encoding_match_list[] = {
143
147
144
148
{PG_SJIS , "SJIS" },
145
149
{PG_SJIS , "PCK" },
150
+ {PG_SJIS , "CP932" },
146
151
147
152
{PG_BIG5 , "BIG5" },
148
153
{PG_BIG5 , "BIG5HKSCS" },
154
+ {PG_BIG5 , "CP950" },
149
155
150
156
{PG_GBK , "GBK" },
157
+ {PG_GBK , "CP936" },
151
158
152
159
{PG_UHC , "UHC" },
153
160
154
161
{PG_JOHAB , "JOHAB" },
162
+ {PG_JOHAB , "CP1361" },
155
163
156
164
{PG_GB18030 , "GB18030" },
165
+ {PG_GB18030 , "CP54936" },
157
166
158
167
{PG_SHIFT_JIS_2004 , "SJIS_2004" },
159
168
160
169
{PG_SQL_ASCII , NULL } /* end marker */
161
170
};
162
171
172
+ #ifdef WIN32
173
+ /*
174
+ * On Windows, use CP<codepage number> instead of the nl_langinfo() result
175
+ */
176
+ static char *
177
+ win32_langinfo (const char * ctype )
178
+ {
179
+ char * r ;
180
+ char * codepage ;
181
+ int ln ;
182
+
183
+ /*
184
+ * Locale format on Win32 is <Language>_<Country>.<CodePage> .
185
+ * For example, English_USA.1252.
186
+ */
187
+ codepage = strrchr (ctype , '.' );
188
+ if (!codepage )
189
+ return NULL ;
190
+ codepage ++ ;
191
+ ln = strlen (codepage );
192
+ r = malloc (ln + 3 );
193
+ sprintf (r , "CP%s" , codepage );
194
+
195
+ return r ;
196
+ }
197
+ #endif /* WIN32 */
198
+
199
+ #if (defined(HAVE_LANGINFO_H ) && defined(CODESET )) || defined(WIN32 )
163
200
164
201
/*
165
202
* Given a setting for LC_CTYPE, return the Postgres ID of the associated
@@ -181,6 +218,7 @@ pg_get_encoding_from_locale(const char *ctype)
181
218
if (ctype )
182
219
{
183
220
char * save ;
221
+ char * name ;
184
222
185
223
save = setlocale (LC_CTYPE , NULL );
186
224
if (!save )
@@ -190,15 +228,20 @@ pg_get_encoding_from_locale(const char *ctype)
190
228
if (!save )
191
229
return PG_SQL_ASCII ; /* out of memory; unlikely */
192
230
193
- if (!setlocale (LC_CTYPE , ctype ))
231
+ name = setlocale (LC_CTYPE , ctype );
232
+ if (!name )
194
233
{
195
234
free (save );
196
235
return PG_SQL_ASCII ; /* bogus ctype passed in? */
197
236
}
198
237
238
+ #ifndef WIN32
199
239
sys = nl_langinfo (CODESET );
200
240
if (sys )
201
241
sys = strdup (sys );
242
+ #else
243
+ sys = win32_langinfo (name );
244
+ #endif
202
245
203
246
setlocale (LC_CTYPE , save );
204
247
free (save );
@@ -209,9 +252,13 @@ pg_get_encoding_from_locale(const char *ctype)
209
252
ctype = setlocale (LC_CTYPE , NULL );
210
253
if (!ctype )
211
254
return PG_SQL_ASCII ; /* setlocale() broken? */
255
+ #ifndef WIN32
212
256
sys = nl_langinfo (CODESET );
213
257
if (sys )
214
258
sys = strdup (sys );
259
+ #else
260
+ sys = win32_langinfo (ctype );
261
+ #endif
215
262
}
216
263
217
264
if (!sys )
@@ -268,7 +315,7 @@ pg_get_encoding_from_locale(const char *ctype)
268
315
return PG_SQL_ASCII ;
269
316
}
270
317
271
- #else /* ! (HAVE_LANGINFO_H && CODESET) */
318
+ #else /* (HAVE_LANGINFO_H && CODESET) || WIN32 */
272
319
273
320
/*
274
321
* stub if no platform support
@@ -279,4 +326,4 @@ pg_get_encoding_from_locale(const char *ctype)
279
326
return PG_SQL_ASCII ;
280
327
}
281
328
282
- #endif /* HAVE_LANGINFO_H && CODESET */
329
+ #endif /* ( HAVE_LANGINFO_H && CODESET) || WIN32 */
0 commit comments