change log updated
[public/netxms.git] / include / unicode.h
1 /*
2 ** NetXMS - Network Management System
3 ** Copyright (C) 2003-2010 Victor Kirhenshtein
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU Lesser General Public License as published by
7 ** the Free Software Foundation; either version 3 of the License, or
8 ** (at your option) any later version.
9 **
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.
14 **
15 ** You should have received a copy of the GNU Lesser General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 **
19 ** File: unicode.h
20 **
21 **/
22
23 #ifndef _unicode_h_
24 #define _unicode_h_
25
26 // Undef UNICODE_UCS2 and UNICODE_UCS4 if they are defined to 0
27 #if !UNICODE_UCS2
28 #undef UNICODE_UCS2
29 #endif
30 #if !UNICODE_UCS4
31 #undef UNICODE_UCS4
32 #endif
33
34 #if defined(_WIN32)
35
36 // Ensure that both UNICODE and _UNICODE are defined
37 #ifdef _UNICODE
38 #ifndef UNICODE
39 #define UNICODE
40 #endif
41 #endif
42
43 #ifdef UNICODE
44 #ifndef _UNICODE
45 #define _UNICODE
46 #endif
47 #endif
48
49 #include <tchar.h>
50
51 // Windows always use UCS-2
52 #define UNICODE_UCS2 1
53
54 #define ICONV_DEFAULT_CODEPAGE "ACP"
55
56 #ifdef UNICODE
57
58 #define _tcstoll wcstoll
59 #define _tcstoull wcstoull
60 #define _tcstok_r wcstok_s
61 #define _tcslcpy wcslcpy
62 #define _tcslcat wcslcat
63
64 #define _ERR_error_tstring ERR_error_string_W
65
66 #else /* !UNICODE */
67
68 #define _tcstoll strtoll
69 #define _tcstoull strtoull
70 #define _tcstok_r strtok_s
71 #define _tcslcpy strlcpy
72 #define _tcslcat strlcat
73
74 #define _ERR_error_tstring ERR_error_string
75
76 #endif /* UNICODE */
77
78 #define UCS2CHAR WCHAR
79 #define UCS4CHAR unsigned int
80
81 #else /* not _WIN32 */
82
83 #if HAVE_WCHAR_H
84 #include <wchar.h>
85 #endif
86
87 #if HAVE_STRING_H
88 #include <string.h>
89 #endif
90
91 #if HAVE_WCHAR_T
92
93 #define WCHAR wchar_t
94 #if UNICODE_UCS2
95 #define UCS2CHAR wchar_t
96 #define UCS4CHAR unsigned int
97 #else
98 #define UCS2CHAR unsigned short
99 #define UCS4CHAR wchar_t
100 #endif
101
102 #else /* wchar_t not presented */
103
104 #define WCHAR unsigned short
105 #define UCS2CHAR unsigned short
106 #define UCS4CHAR unsigned int
107 #undef UNICODE_UCS2
108 #undef UNICODE_UCS4
109 #define UNICODE_UCS2 1
110
111 #endif
112
113 // On some old systems, ctype.h defines _T macro, so we include it
114 // before our definition and do an undef
115 #include <ctype.h>
116 #undef _T
117
118 #ifdef UNICODE
119
120 #define _T(x) L##x
121 #define TCHAR wchar_t
122 #define _TINT int
123
124 #define _tcscpy wcscpy
125 #define _tcsncpy wcsncpy
126 #define _tcslcpy wcslcpy
127 #define _tcslen wcslen
128 #define _tcsnlen wcsnlen
129 #define _tcschr wcschr
130 #define _tcsrchr wcsrchr
131 #define _tcscmp wcscmp
132 #define _tcsicmp wcsicmp
133 #define _tcsncmp wcsncmp
134 #define _tcsnicmp wcsnicmp
135 #define _tprintf nx_wprintf
136 #define _ftprintf nx_fwprintf
137 #define _sntprintf nx_swprintf
138 #define _vtprintf nx_vwprintf
139 #define _vftprintf nx_vfwprintf
140 #define _vsntprintf nx_vswprintf
141 #define _tscanf nx_wscanf
142 #define _ftscanf nx_fwscanf
143 #define _stscanf nx_swscanf
144 #define _vtscanf nx_vwscanf
145 #define _vftscanf nx_vfwscanf
146 #define _vstscanf nx_vswscanf
147 #define _tfopen wfopen
148 #define _tfopen64 wfopen64
149 #define _tpopen wpopen
150 #define _fgetts fgetws
151 #define _fputts fputws
152 #if HAVE_DECL_PUTWS && HAVE_PUTWS
153 #define _putts putws
154 #else
155 #define _putts(s) fputws((s), stdout)
156 #endif
157 #define _puttc putwc
158 #define _tcstol wcstol
159 #define _tcstoul wcstoul
160 #define _tcstoll wcstoll
161 #define _tcstoull wcstoull
162 #define _tcstod wcstod
163 #define _tcsdup wcsdup
164 #define _tcsupr wcsupr
165 #define _tcslwr wcslwr
166 #define _tcsspn wcsspn
167 #define _tcscspn wcscspn
168 #define _tcsstr wcsstr
169 #define _tcscat wcscat
170 #define _tcscat_s wcscat_s
171 #define _tcsncat wcsncat
172 #define _tcslcat wcslcat
173 #define _tcspbrk wcspbrk
174 #define _tcstok_r wcstok
175 #define _topen wopen
176 #define _taccess waccess
177 #define _tstat wstat
178 #define _tchmod wchmod
179 #define _tunlink wunlink
180 #define _trename wrename
181 #define _tremove wremove
182 #if HAVE_WCSFTIME && WORKING_WCSFTIME
183 #define _tcsftime wcsftime
184 #else
185 #define _tcsftime nx_wcsftime
186 #endif
187 #define _tctime wctime
188 #define _istspace iswspace
189 #define _istdigit iswdigit
190 #define _istxdigit iswxdigit
191 #define _istalpha iswalpha
192 #define _istalnum iswalnum
193 #define _istupper iswupper
194 #define _istprint iswprint
195 #define _itot _itow
196 #define _tgetenv wgetenv
197 #define _tmkdir wmkdir
198 #define _tchdir wchdir
199 #define _trmdir wrmdir
200 #define _tutime wutime
201 #define _tcserror wcserror
202 #define _tcserror_r wcserror_r
203 #define _tsystem wsystem
204 #define _topendir wopendir
205 #define _treaddir wreaddir
206 #define _tclosedir wclosedir
207 #define _tmkstemp wmkstemp
208 #define _ERR_error_tstring ERR_error_string_W
209
210 #define _TDIR DIRW
211 #define _tdirent dirent_w
212
213 #else
214
215 #define _T(x) x
216 #define TCHAR char
217 #define _TINT int
218
219 #define _tcscpy strcpy
220 #define _tcsncpy strncpy
221 #define _tcslcpy strlcpy
222 #define _tcslen strlen
223 #define _tcsnlen strnlen
224 #define _tcschr strchr
225 #define _tcsrchr strrchr
226 #define _tcscmp strcmp
227 #define _tcsicmp stricmp
228 #define _tcsncmp strncmp
229 #define _tcsnicmp strnicmp
230 #define _tprintf printf
231 #define _stprintf sprintf
232 #define _ftprintf fprintf
233 #define _sntprintf snprintf
234 #define _vtprintf vprintf
235 #define _vstprintf vsprintf
236 #define _vsntprintf vsnprintf
237 #define _tscanf scanf
238 #define _ftscanf fscanf
239 #define _stscanf sscanf
240 #define _vtscanf vscanf
241 #define _vftscanf vfscanf
242 #define _vstscanf vsscanf
243 #define _tfopen fopen
244 #define _tfopen64 fopen64
245 #define _tpopen popen
246 #define _fgetts fgets
247 #define _fputts fputs
248 #define _putts puts
249 #define _puttc putc
250 #define _tcstol strtol
251 #define _tcstoul strtoul
252 #define _tcstoll strtoll
253 #define _tcstoull strtoull
254 #define _tcstod strtod
255 #define _tcsdup strdup
256 #define _tcsupr strupr
257 #define _tcslwr strlwr
258 #define _tcsspn strspn
259 #define _tcscspn strcspn
260 #define _tcsstr strstr
261 #define _tcscat strcat
262 #define _tcscat_s strcat_s
263 #define _tcsncat strncat
264 #define _tcslcat strlcat
265 #define _tcspbrk strpbrk
266 #define _tcstok_r strtok_r
267 #define _topen _open
268 #define _taccess _access
269 #define _tstat stat
270 #define _tchmod chmod
271 #define _tunlink unlink
272 #define _trename rename
273 #define _tremove remove
274 #define _tcsftime strftime
275 #define _tctime ctime
276 #define _istspace isspace
277 #define _istdigit isdigit
278 #define _istxdigit isxdigit
279 #define _istalpha isalpha
280 #define _istalnum isalnum
281 #define _istupper isupper
282 #define _istprint isprint
283 #define _itot _itoa
284 #define _tgetenv getenv
285 #define _tmkdir mkdir
286 #define _tchdir chdir
287 #define _trmdir rmdir
288 #define _tutime utime
289 #define _tcserror strerror
290 #define _tcserror_r strerror_r
291 #define _tsystem system
292 #define _topendir opendir
293 #define _treaddir readdir
294 #define _tclosedir closedir
295 #define _tmkstemp mkstemp
296 #define _ERR_error_tstring ERR_error_string
297
298 #define _TDIR DIR
299 #define _tdirent dirent
300
301 #endif
302
303 #define CP_ACP 0
304 #define CP_UTF8 65001
305 #define MB_PRECOMPOSED 0x00000001
306 #define WC_COMPOSITECHECK 0x00000002
307 #define WC_DEFAULTCHAR 0x00000004
308
309 // Default codepage for iconv()
310 #define ICONV_DEFAULT_CODEPAGE "ASCII"
311
312 #endif /* _WIN32 */
313
314 #ifdef UNICODE
315 #define _t_inet_addr inet_addr_w
316 #else
317 #define _t_inet_addr inet_addr
318 #endif
319
320 // Check that either UNICODE_UCS2 or UNICODE_UCS4 are defined
321 #if !defined(UNICODE_UCS2) && !defined(UNICODE_UCS4)
322 #error Neither UNICODE_UCS2 nor UNICODE_UCS4 are defined
323 #endif
324
325 #endif /* _unicode_h_ */