change log updated
[public/netxms.git] / include / unicode.h
CommitLineData
7b45b90d 1/*
f2fdf1b5 2** NetXMS - Network Management System
68f384ea 3** Copyright (C) 2003-2010 Victor Kirhenshtein
f2fdf1b5
VK
4**
5** This program is free software; you can redistribute it and/or modify
65d2c384
VK
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
f2fdf1b5
VK
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**
68f384ea 15** You should have received a copy of the GNU Lesser General Public License
f2fdf1b5
VK
16** along with this program; if not, write to the Free Software
17** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18**
164f87f1 19** File: unicode.h
f2fdf1b5
VK
20**
21**/
22
23#ifndef _unicode_h_
24#define _unicode_h_
25
8b86c5dc
VK
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
e647245b 34#if defined(_WIN32)
f2fdf1b5
VK
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
8b86c5dc
VK
51// Windows always use UCS-2
52#define UNICODE_UCS2 1
53
29dc8792 54#define ICONV_DEFAULT_CODEPAGE "ACP"
35f836fe 55
8f7c07b1
VK
56#ifdef UNICODE
57
dde96745
VK
58#define _tcstoll wcstoll
59#define _tcstoull wcstoull
fdb710a7 60#define _tcstok_r wcstok_s
3a4c13cc
VK
61#define _tcslcpy wcslcpy
62#define _tcslcat wcslcat
dde96745 63
3d1058ed
VK
64#define _ERR_error_tstring ERR_error_string_W
65
35f836fe 66#else /* !UNICODE */
dde96745
VK
67
68#define _tcstoll strtoll
69#define _tcstoull strtoull
fdb710a7 70#define _tcstok_r strtok_s
3a4c13cc
VK
71#define _tcslcpy strlcpy
72#define _tcslcat strlcat
dde96745 73
3d1058ed
VK
74#define _ERR_error_tstring ERR_error_string
75
35f836fe 76#endif /* UNICODE */
5e40a69e 77
3a4c13cc
VK
78#define UCS2CHAR WCHAR
79#define UCS4CHAR unsigned int
8b86c5dc 80
7768852d 81#else /* not _WIN32 */
559127ea 82
556d9c45
VK
83#if HAVE_WCHAR_H
84#include <wchar.h>
85#endif
86
c961fac9
VK
87#if HAVE_STRING_H
88#include <string.h>
89#endif
90
6b93c954
VK
91#if HAVE_WCHAR_T
92
8b86c5dc
VK
93#define WCHAR wchar_t
94#if UNICODE_UCS2
95#define UCS2CHAR wchar_t
7768852d 96#define UCS4CHAR unsigned int
8b86c5dc
VK
97#else
98#define UCS2CHAR unsigned short
7768852d 99#define UCS4CHAR wchar_t
58e7e86f 100#endif
f2fdf1b5 101
6b93c954
VK
102#else /* wchar_t not presented */
103
104#define WCHAR unsigned short
105#define UCS2CHAR unsigned short
7768852d 106#define UCS4CHAR unsigned int
6b93c954
VK
107#undef UNICODE_UCS2
108#undef UNICODE_UCS4
109#define UNICODE_UCS2 1
110
111#endif
112
8b86c5dc
VK
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
73118723
VK
118#ifdef UNICODE
119
8b86c5dc 120#define _T(x) L##x
04dbaf62 121#define TCHAR wchar_t
8b86c5dc 122#define _TINT int
73118723 123
8b86c5dc
VK
124#define _tcscpy wcscpy
125#define _tcsncpy wcsncpy
3a4c13cc 126#define _tcslcpy wcslcpy
8b86c5dc 127#define _tcslen wcslen
a8ef5461 128#define _tcsnlen wcsnlen
8b86c5dc
VK
129#define _tcschr wcschr
130#define _tcsrchr wcsrchr
131#define _tcscmp wcscmp
132#define _tcsicmp wcsicmp
133#define _tcsncmp wcsncmp
134#define _tcsnicmp wcsnicmp
04dbaf62
VK
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
25575d38
VK
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
8b86c5dc 147#define _tfopen wfopen
8c2489aa 148#define _tfopen64 wfopen64
a3ad7bf2 149#define _tpopen wpopen
8b86c5dc
VK
150#define _fgetts fgetws
151#define _fputts fputws
465bd4ff 152#if HAVE_DECL_PUTWS && HAVE_PUTWS
0186b5da 153#define _putts putws
465bd4ff
VK
154#else
155#define _putts(s) fputws((s), stdout)
156#endif
3188558a 157#define _puttc putwc
8b86c5dc
VK
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
fdb710a7 165#define _tcslwr wcslwr
8b86c5dc
VK
166#define _tcsspn wcsspn
167#define _tcscspn wcscspn
168#define _tcsstr wcsstr
169#define _tcscat wcscat
9b13553b 170#define _tcscat_s wcscat_s
e2717f44 171#define _tcsncat wcsncat
3a4c13cc 172#define _tcslcat wcslcat
e02b69b9 173#define _tcspbrk wcspbrk
fdb710a7 174#define _tcstok_r wcstok
8b86c5dc
VK
175#define _topen wopen
176#define _taccess waccess
177#define _tstat wstat
f3387429 178#define _tchmod wchmod
8b86c5dc 179#define _tunlink wunlink
376e15e8 180#define _trename wrename
80ce37ac 181#define _tremove wremove
75b4d48e 182#if HAVE_WCSFTIME && WORKING_WCSFTIME
8b86c5dc 183#define _tcsftime wcsftime
75b4d48e
VK
184#else
185#define _tcsftime nx_wcsftime
186#endif
8b86c5dc
VK
187#define _tctime wctime
188#define _istspace iswspace
189#define _istdigit iswdigit
a8865589 190#define _istxdigit iswxdigit
8b86c5dc 191#define _istalpha iswalpha
18a7c1e9 192#define _istalnum iswalnum
8b86c5dc 193#define _istupper iswupper
f026b346 194#define _istprint iswprint
9138dfe2 195#define _itot _itow
8b86c5dc 196#define _tgetenv wgetenv
bd158b26 197#define _tmkdir wmkdir
17b35ccc 198#define _tchdir wchdir
b7ad6b85 199#define _trmdir wrmdir
7b45b90d 200#define _tutime wutime
d49d7500
VK
201#define _tcserror wcserror
202#define _tcserror_r wcserror_r
17b35ccc 203#define _tsystem wsystem
f026b346
VK
204#define _topendir wopendir
205#define _treaddir wreaddir
206#define _tclosedir wclosedir
37a7a862 207#define _tmkstemp wmkstemp
f026b346
VK
208#define _ERR_error_tstring ERR_error_string_W
209
210#define _TDIR DIRW
211#define _tdirent dirent_w
73118723 212
8b86c5dc 213#else
3c2bbe5f 214
73118723
VK
215#define _T(x) x
216#define TCHAR char
dde96745 217#define _TINT int
73118723 218
f2fdf1b5
VK
219#define _tcscpy strcpy
220#define _tcsncpy strncpy
3a4c13cc 221#define _tcslcpy strlcpy
f2fdf1b5 222#define _tcslen strlen
a8ef5461 223#define _tcsnlen strnlen
f2fdf1b5
VK
224#define _tcschr strchr
225#define _tcsrchr strrchr
226#define _tcscmp strcmp
227#define _tcsicmp stricmp
9ea100d2 228#define _tcsncmp strncmp
5de3893d 229#define _tcsnicmp strnicmp
f2fdf1b5
VK
230#define _tprintf printf
231#define _stprintf sprintf
98d747e1 232#define _ftprintf fprintf
03ef9555 233#define _sntprintf snprintf
1a9fcf74 234#define _vtprintf vprintf
9ea100d2 235#define _vstprintf vsprintf
03ef9555 236#define _vsntprintf vsnprintf
25575d38
VK
237#define _tscanf scanf
238#define _ftscanf fscanf
f65df2b1 239#define _stscanf sscanf
25575d38
VK
240#define _vtscanf vscanf
241#define _vftscanf vfscanf
242#define _vstscanf vsscanf
f2fdf1b5 243#define _tfopen fopen
8c2489aa 244#define _tfopen64 fopen64
a3ad7bf2 245#define _tpopen popen
f2fdf1b5 246#define _fgetts fgets
94ee38a9 247#define _fputts fputs
0186b5da 248#define _putts puts
3188558a 249#define _puttc putc
f2fdf1b5
VK
250#define _tcstol strtol
251#define _tcstoul strtoul
dde96745
VK
252#define _tcstoll strtoll
253#define _tcstoull strtoull
f2fdf1b5
VK
254#define _tcstod strtod
255#define _tcsdup strdup
256#define _tcsupr strupr
fdb710a7 257#define _tcslwr strlwr
f2fdf1b5 258#define _tcsspn strspn
e33fc781 259#define _tcscspn strcspn
6f040d7b 260#define _tcsstr strstr
4507063f 261#define _tcscat strcat
9b13553b 262#define _tcscat_s strcat_s
e2717f44 263#define _tcsncat strncat
3a4c13cc 264#define _tcslcat strlcat
e02b69b9 265#define _tcspbrk strpbrk
9e3b4860 266#define _tcstok_r strtok_r
44d4f4f2
VK
267#define _topen _open
268#define _taccess _access
8b86c5dc 269#define _tstat stat
f3387429 270#define _tchmod chmod
1dd2715c 271#define _tunlink unlink
376e15e8 272#define _trename rename
80ce37ac 273#define _tremove remove
c4b88c3d 274#define _tcsftime strftime
98d747e1 275#define _tctime ctime
dde96745
VK
276#define _istspace isspace
277#define _istdigit isdigit
a8865589 278#define _istxdigit isxdigit
dde96745 279#define _istalpha isalpha
18a7c1e9 280#define _istalnum isalnum
dde96745 281#define _istupper isupper
f026b346 282#define _istprint isprint
9138dfe2 283#define _itot _itoa
d99ee887 284#define _tgetenv getenv
bd158b26 285#define _tmkdir mkdir
17b35ccc 286#define _tchdir chdir
b7ad6b85 287#define _trmdir rmdir
7b45b90d 288#define _tutime utime
d49d7500
VK
289#define _tcserror strerror
290#define _tcserror_r strerror_r
17b35ccc 291#define _tsystem system
f026b346
VK
292#define _topendir opendir
293#define _treaddir readdir
294#define _tclosedir closedir
37a7a862 295#define _tmkstemp mkstemp
f026b346 296#define _ERR_error_tstring ERR_error_string
f2fdf1b5 297
f026b346
VK
298#define _TDIR DIR
299#define _tdirent dirent
3d1058ed 300
73118723
VK
301#endif
302
3e39fcde
VK
303#define CP_ACP 0
304#define CP_UTF8 65001
4332e9d8
VK
305#define MB_PRECOMPOSED 0x00000001
306#define WC_COMPOSITECHECK 0x00000002
307#define WC_DEFAULTCHAR 0x00000004
308
5e40a69e 309// Default codepage for iconv()
29dc8792 310#define ICONV_DEFAULT_CODEPAGE "ASCII"
5e40a69e 311
3e39fcde 312#endif /* _WIN32 */
f2fdf1b5 313
268774a0
VK
314#ifdef UNICODE
315#define _t_inet_addr inet_addr_w
316#else
317#define _t_inet_addr inet_addr
318#endif
319
8b86c5dc 320// Check that either UNICODE_UCS2 or UNICODE_UCS4 are defined
8b86c5dc
VK
321#if !defined(UNICODE_UCS2) && !defined(UNICODE_UCS4)
322#error Neither UNICODE_UCS2 nor UNICODE_UCS4 are defined
323#endif
8b86c5dc 324
f2fdf1b5 325#endif /* _unicode_h_ */