|
NCBI Home IEB Home C Toolkit docs C++ Toolkit source browser C Toolkit source browser (2) |
NCBI C Toolkit Cross ReferenceC/corelib/ncbilang.c |
source navigation diff markup identifier search freetext search file search |
1 /* ncbilang.c
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information (NCBI)
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government do not place any restriction on its use or reproduction.
13 * We would, however, appreciate having the NCBI and the author cited in
14 * any work or product based on this material
15 *
16 * Although all reasonable efforts have been taken to ensure the accuracy
17 * and reliability of the software and data, the NLM and the U.S.
18 * Government do not and cannot warrant the performance or results that
19 * may be obtained by using this software or data. The NLM and the U.S.
20 * Government disclaim all warranties, express or implied, including
21 * warranties of performance, merchantability or fitness for any particular
22 * purpose.
23 *
24 * ===========================================================================
25 *
26 * File Name: ncbilang.c
27 *
28 * Author: T. Koike, DDBJ
29 *
30 * Version Creation Date: 5/27/97
31 *
32 * $Revision: 6.3 $
33 *
34 * File Description:
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * $Log: ncbilang.c,v $
39 * Revision 6.3 2002/06/13 16:14:07 kans
40 * fix includes for OS_UNIX_DARWIN with WIN_MAC (EN)
41 *
42 * Revision 6.2 1999/12/21 17:52:40 kans
43 * removed MPW/THINKC conditional code, starting upgrade to Carbon compatibility - Churchill
44 *
45 * Revision 6.1 1997/11/26 21:26:16 vakatov
46 * Fixed errors and warnings issued by C and C++ (GNU and Sun) compilers
47 *
48 * Revision 6.0 1997/08/25 18:15:35 madden
49 * Revision changed to 6.0
50 *
51 * Revision 5.3 1997/07/16 21:59:00 vakatov
52 * Adopted for 32-bit MS-Win DLLs
53 *
54 * ==========================================================================
55 */
56
57 #include <ncbi.h> /* includes ncbilcl.h for OS macros. */
58 #include <ncbilang.h>
59 #ifdef OS_MAC
60 # include <Script.h>
61 #endif
62 #ifdef OS_UNIX
63 # include <locale.h>
64 #endif
65 #ifdef OS_VMS
66 #endif
67 #ifdef OS_WINNT
68 # include <locale.h>
69 #endif
70
71 static Nlm_LangEnum CheckLanguage(void)
72 {
73 Nlm_LangEnum ret = LangUninit;
74
75 #if defined(OS_MAC) && !defined(OS_UNIX_DARWIN)
76 long script = GetScriptManagerVariable(smSysScript);
77 long lang = GetScriptVariable((short)script, smScriptLang);
78 switch (lang) {
79 case langEnglish : ret = LangEnglish; break;
80 case langJapanese : ret = LangJapanese; break;
81 /* case langFrench : ret = LangFrench; break; */
82 /* case langGerman : ret = LangGerman; break; */
83 /* case langItalian : ret = LangItalian; break; */
84 /* default: ret = LangUnknown; break; */
85 default: ret = LangEnglish; break;
86 }
87 #endif /*OS_MAC && !OS_UNIX_DARWIN*/
88
89 #ifdef WIN16
90 Nlm_Char lang [64];
91 ret = LangEnglish;
92 if (Nlm_GetAppParam ("VIBRANT", "GENERAL", "LANGUAGE", "", lang, sizeof (lang))) {
93 if (Nlm_StringICmp (lang, "JAPANESE") == 0) {
94 ret = LangJapanese;
95 }
96 }
97 #endif /*WIN16*/
98
99 #ifdef OS_WINNT
100 const char* locale = setlocale(LC_ALL, "");
101 if (Nlm_StringICmp(locale, "C") == 0) ret = LangSystem;
102 /* else if (Nlm_StringICmp(locale, "chinese") == 0) ret = LangChinese; */
103 /* else if (Nlm_StringICmp(locale, "chinese-simplified") == 0) ret = LangChinese; */
104 /* else if (Nlm_StringICmp(locale, "chs") == 0) ret = LangChinese; */
105 /* else if (Nlm_StringICmp(locale, "chinese-traditional") == 0) ret = LangChinese; */
106 /* else if (Nlm_StringICmp(locale, "cht") == 0) ret = LangChinese; */
107 /* else if (Nlm_StringICmp(locale, "australian") == 0) ret = LangEnglish; */
108 /* else if (Nlm_StringICmp(locale, "ena") == 0) ret = LangEnglish; */
109 /* else if (Nlm_StringICmp(locale, "english-aus") == 0) ret = LangEnglish; */
110 /* else if (Nlm_StringICmp(locale, "canadian") == 0) ret = LangEnglish; */
111 /* else if (Nlm_StringICmp(locale, "enc") == 0) ret = LangEnglish; */
112 /* else if (Nlm_StringICmp(locale, "english-can") == 0) ret = LangEnglish; */
113 /* else if (Nlm_StringICmp(locale, "english") == 0) ret = LangEnglish; */
114 /* else if (Nlm_StringICmp(locale, "english-nz") == 0) ret = LangEnglish; */
115 /* else if (Nlm_StringICmp(locale, "enz") == 0) ret = LangEnglish; */
116 /* else if (Nlm_StringICmp(locale, "eng") == 0) ret = LangEnglish; */
117 /* else if (Nlm_StringICmp(locale, "english-uk") == 0) ret = LangEnglish; */
118 /* else if (Nlm_StringICmp(locale, "uk") == 0) ret = LangEnglish; */
119 /* else if (Nlm_StringICmp(locale, "american") == 0) ret = LangEnglish; */
120 /* else if (Nlm_StringICmp(locale, "american english") == 0) ret = LangEnglish; */
121 /* else if (Nlm_StringICmp(locale, "american-english") == 0) ret = LangEnglish; */
122 /* else if (Nlm_StringICmp(locale, "english-american") == 0) ret = LangEnglish; */
123 /* else if (Nlm_StringICmp(locale, "english-us") == 0) ret = LangEnglish; */
124 /* else if (Nlm_StringICmp(locale, "english-usa") == 0) ret = LangEnglish; */
125 /* else if (Nlm_StringICmp(locale, "enu") == 0) ret = LangEnglish; */
126 /* else if (Nlm_StringICmp(locale, "us") == 0) ret = LangEnglish; */
127 /* else if (Nlm_StringICmp(locale, "usa") == 0) ret = LangEnglish; */
128 else if (Nlm_StringICmp(locale, "japanese") == 0) ret = LangJapanese;
129 else if (Nlm_StringICmp(locale, "jpn") == 0) ret = LangJapanese;
130 /* else if (Nlm_StringICmp(locale, "korean") == 0) ret = LangKorean; */
131 /* else if (Nlm_StringICmp(locale, "kor") == 0) ret = LangKorean; */
132 /* else ret = LangUnknown; */
133 else ret = LangEnglish;
134 #endif /*OS_WINNT*/
135
136 #ifdef OS_UNIX
137 const char* locale = setlocale(LC_ALL, "");
138 if (Nlm_StringICmp(locale, "C") == 0) ret = LangSystem;
139 else if (Nlm_StringICmp(locale, "iso_8859_1") == 0) ret = LangEnglish; /* ISO Latin-1 */
140 else if (Nlm_StringICmp(locale, "iso_8859_2") == 0) ret = LangEnglish; /* ISO Latin-2 */
141 else if (Nlm_StringICmp(locale, "iso_8859_3") == 0) ret = LangEnglish; /* ISO Latin-3 */
142 else if (Nlm_StringICmp(locale, "iso_8859_4") == 0) ret = LangEnglish; /* ISO Latin-4 */
143
144 #ifdef NOT_IMPLEMENTED_LANG
145 else if (Nlm_StringICmp(locale, "iso_8859_5") == 0) ret = LangCyrillic; /* ISO Cyrillic */
146 else if (Nlm_StringICmp(locale, "iso_8859_6") == 0) ret = LangArabic; /* ISO Arabic */
147 else if (Nlm_StringICmp(locale, "iso_8859_7") == 0) ret = LangGreek; /* ISO Greek */
148 else if (Nlm_StringICmp(locale, "iso_8859_8") == 0) ret = LangHebrew; /* ISO Hebrew */
149 else if (Nlm_StringICmp(locale, "iso_8859_9") == 0) ret = LangEnglish; /* ISO Latin-5 */
150 else if (Nlm_StringICmp(locale, "en") == 0) ret = LangEnglish;
151 else if (Nlm_StringICmp(locale, "en_UK") == 0) ret = LangEnglish;
152 else if (Nlm_StringICmp(locale, "en_US") == 0) ret = LangEnglish;
153 else if (Nlm_StringICmp(locale, "fr") == 0) ret = LangFrench;
154 else if (Nlm_StringICmp(locale, "de") == 0) ret = LangGerman;
155 else if (Nlm_StringICmp(locale, "it") == 0) ret = LangItalian;
156 else if (Nlm_StringICmp(locale, "es") == 0) ret = LangSpanish;
157 #endif /* NOT_IMPLEMENTED_LANG */
158
159 else if (Nlm_StringICmp(locale, "ja") == 0) ret = LangJapanese;
160 else if (Nlm_StringICmp(locale, "ja_JP") == 0) ret = LangJapanese;
161 else if (Nlm_StringICmp(locale, "ja_JP.EUC") == 0) ret = LangJapanese;
162 else if (Nlm_StringICmp(locale, "ja_JP.SJIS") == 0) ret = LangJapanese;
163 else if (Nlm_StringICmp(locale, "japanese") == 0) ret = LangJapanese;
164
165 #ifdef NOT_IMPLEMENTED_LANG
166 else if (Nlm_StringICmp(locale, "ko") == 0) ret = LangKorean;
167 else if (Nlm_StringICmp(locale, "ko_KR") == 0) ret = LangKorean;
168 else if (Nlm_StringICmp(locale, "ko_KR.EUC") == 0) ret = LangKorean;
169 else if (Nlm_StringICmp(locale, "korean") == 0) ret = LangKorean;
170 else if (Nlm_StringICmp(locale, "zh") == 0) ret = LangChinese;
171 else if (Nlm_StringICmp(locale, "chinese") == 0) ret = LangChinese;
172 else if (Nlm_StringICmp(locale, "zh_TW") == 0) ret = LangChinese; /* Taipei */
173 else if (Nlm_StringICmp(locale, "tchinese") == 0) ret = LangChinese; /* Taipei */
174 else ret = LangUnknown;
175 #endif /* NOT_IMPLEMENTED_LANG */
176
177 else ret = LangEnglish;
178 #endif /*OS_UNIX*/
179
180 #ifdef OS_VMS
181 #endif /*OS_VMS*/
182
183 ASSERT(ret != LangUninit);
184 return ret;
185 }
186
187 NLM_EXTERN Nlm_LangEnum Nlm_GetLanguage(void)
188 {
189 static Nlm_LangEnum lang = LangUninit;
190
191 if (lang == LangUninit) {
192 lang = CheckLanguage();
193 }
194
195 return lang;
196 }
197
198 #ifdef WIN16
199 static int SJIS1stByte(unsigned char ch)
200 {
201 return (((ch >= 0x81) && (ch <= 0x9F)) || ((ch >= 0xE0) && (ch <= 0xFC)));
202 }
203
204 static int SJIS2ndByte(unsigned char ch)
205 {
206 return (((ch >= 0x40) && (ch <= 0x7E)) || ((ch >= 0x80) && (ch <= 0xFC)));
207 }
208 #endif
209
210 /* Nlm_LetterByte
211 *
212 * Pass in a pointer to a string and we return the number of bytes
213 * per character that the underlying OS is using...
214 */
215
216 NLM_EXTERN int Nlm_LetterByte(const char* str)
217 {
218 int byte = 0x0F0F; /* magic number to assert. */
219
220 #ifdef OS_MAC
221 /* This should work regardless of the language/script system in use...
222 * if more languages are supported in the future, this function shouldn't need
223 * to be changed. pjc 12/99
224 */
225 if ((str == NULL) || (*str == '\0')) {
226 byte = 0;
227 }
228 else {
229 long script = GetScriptManagerVariable(smSysScript);
230 long lang = GetScriptVariable((short)script, smScriptLang);
231
232 byte = (CharacterType((char*)str, 0, lang) & smChar2byte) ? 2:1;
233 }
234 #endif /*OS_MAC*/
235
236 #ifdef WIN16
237 if ((str == NULL) || (*str == '\0')) {
238 byte = 0;
239 }
240 else {
241 byte = ((IsJapanese() && SJIS1stByte(*str) && SJIS2ndByte(*(str + 1))) ? 2 : 1);
242 }
243 #endif /*WIN16*/
244
245 #ifdef OS_WINNT
246 byte = mblen(str, MB_CUR_MAX);
247 byte = (byte < 0 ? 1 : byte);
248 #endif /*OS_WINNT*/
249
250 #ifdef OS_UNIX
251 byte = mblen(str, MB_CUR_MAX);
252 byte = (byte < 0 ? 1 : byte);
253 #endif /*OS_UNIX*/
254
255 ASSERT(byte != 0x0F0F);
256 return byte;
257 }
258
259
260
261 |
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more information. |