Further non-Unicode fixes; LoraWAN subagent refactoring
[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
dde96745 61
3d1058ed
VK
62#define _ERR_error_tstring ERR_error_string_W
63
35f836fe 64#else /* !UNICODE */
dde96745
VK
65
66#define _tcstoll strtoll
67#define _tcstoull strtoull
fdb710a7 68#define _tcstok_r strtok_s
dde96745 69
3d1058ed
VK
70#define _ERR_error_tstring ERR_error_string
71
35f836fe 72#endif /* UNICODE */
5e40a69e 73
04dbaf62 74#define UCS2CHAR WCHAR
7768852d 75#define UCS4CHAR unsigned int
8b86c5dc 76
7768852d 77#else /* not _WIN32 */
559127ea 78
556d9c45
VK
79#if HAVE_WCHAR_H
80#include <wchar.h>
81#endif
82
c961fac9
VK
83#if HAVE_STRING_H
84#include <string.h>
85#endif
86
6b93c954
VK
87#if HAVE_WCHAR_T
88
8b86c5dc
VK
89#define WCHAR wchar_t
90#if UNICODE_UCS2
91#define UCS2CHAR wchar_t
7768852d 92#define UCS4CHAR unsigned int
8b86c5dc
VK
93#else
94#define UCS2CHAR unsigned short
7768852d 95#define UCS4CHAR wchar_t
58e7e86f 96#endif
f2fdf1b5 97
6b93c954
VK
98#else /* wchar_t not presented */
99
100#define WCHAR unsigned short
101#define UCS2CHAR unsigned short
7768852d 102#define UCS4CHAR unsigned int
6b93c954
VK
103#undef UNICODE_UCS2
104#undef UNICODE_UCS4
105#define UNICODE_UCS2 1
106
107#endif
108
8b86c5dc
VK
109// On some old systems, ctype.h defines _T macro, so we include it
110// before our definition and do an undef
111#include <ctype.h>
112#undef _T
113
73118723
VK
114#ifdef UNICODE
115
8b86c5dc 116#define _T(x) L##x
04dbaf62 117#define TCHAR wchar_t
8b86c5dc 118#define _TINT int
73118723 119
8b86c5dc
VK
120#define _tcscpy wcscpy
121#define _tcsncpy wcsncpy
122#define _tcslen wcslen
a8ef5461 123#define _tcsnlen wcsnlen
8b86c5dc
VK
124#define _tcschr wcschr
125#define _tcsrchr wcsrchr
126#define _tcscmp wcscmp
127#define _tcsicmp wcsicmp
128#define _tcsncmp wcsncmp
129#define _tcsnicmp wcsnicmp
04dbaf62
VK
130#define _tprintf nx_wprintf
131#define _ftprintf nx_fwprintf
132#define _sntprintf nx_swprintf
133#define _vtprintf nx_vwprintf
134#define _vftprintf nx_vfwprintf
135#define _vsntprintf nx_vswprintf
25575d38
VK
136#define _tscanf nx_wscanf
137#define _ftscanf nx_fwscanf
138#define _stscanf nx_swscanf
139#define _vtscanf nx_vwscanf
140#define _vftscanf nx_vfwscanf
141#define _vstscanf nx_vswscanf
8b86c5dc 142#define _tfopen wfopen
8c2489aa 143#define _tfopen64 wfopen64
a3ad7bf2 144#define _tpopen wpopen
8b86c5dc
VK
145#define _fgetts fgetws
146#define _fputts fputws
465bd4ff 147#if HAVE_DECL_PUTWS && HAVE_PUTWS
0186b5da 148#define _putts putws
465bd4ff
VK
149#else
150#define _putts(s) fputws((s), stdout)
151#endif
3188558a 152#define _puttc putwc
8b86c5dc
VK
153#define _tcstol wcstol
154#define _tcstoul wcstoul
155#define _tcstoll wcstoll
156#define _tcstoull wcstoull
157#define _tcstod wcstod
158#define _tcsdup wcsdup
159#define _tcsupr wcsupr
fdb710a7 160#define _tcslwr wcslwr
8b86c5dc
VK
161#define _tcsspn wcsspn
162#define _tcscspn wcscspn
163#define _tcsstr wcsstr
164#define _tcscat wcscat
9b13553b 165#define _tcscat_s wcscat_s
e2717f44 166#define _tcsncat wcsncat
e02b69b9 167#define _tcspbrk wcspbrk
fdb710a7 168#define _tcstok_r wcstok
8b86c5dc
VK
169#define _topen wopen
170#define _taccess waccess
171#define _tstat wstat
f3387429 172#define _tchmod wchmod
8b86c5dc 173#define _tunlink wunlink
376e15e8 174#define _trename wrename
80ce37ac 175#define _tremove wremove
75b4d48e 176#if HAVE_WCSFTIME && WORKING_WCSFTIME
8b86c5dc 177#define _tcsftime wcsftime
75b4d48e
VK
178#else
179#define _tcsftime nx_wcsftime
180#endif
8b86c5dc
VK
181#define _tctime wctime
182#define _istspace iswspace
183#define _istdigit iswdigit
a8865589 184#define _istxdigit iswxdigit
8b86c5dc 185#define _istalpha iswalpha
18a7c1e9 186#define _istalnum iswalnum
8b86c5dc 187#define _istupper iswupper
f026b346 188#define _istprint iswprint
9138dfe2 189#define _itot _itow
8b86c5dc 190#define _tgetenv wgetenv
bd158b26 191#define _tmkdir wmkdir
17b35ccc 192#define _tchdir wchdir
b7ad6b85 193#define _trmdir wrmdir
7b45b90d 194#define _tutime wutime
d49d7500
VK
195#define _tcserror wcserror
196#define _tcserror_r wcserror_r
17b35ccc 197#define _tsystem wsystem
f026b346
VK
198#define _topendir wopendir
199#define _treaddir wreaddir
200#define _tclosedir wclosedir
37a7a862 201#define _tmkstemp wmkstemp
f026b346
VK
202#define _ERR_error_tstring ERR_error_string_W
203
204#define _TDIR DIRW
205#define _tdirent dirent_w
73118723 206
8b86c5dc 207#else
3c2bbe5f 208
73118723
VK
209#define _T(x) x
210#define TCHAR char
dde96745 211#define _TINT int
73118723 212
f2fdf1b5
VK
213#define _tcscpy strcpy
214#define _tcsncpy strncpy
215#define _tcslen strlen
a8ef5461 216#define _tcsnlen strnlen
f2fdf1b5
VK
217#define _tcschr strchr
218#define _tcsrchr strrchr
219#define _tcscmp strcmp
220#define _tcsicmp stricmp
9ea100d2 221#define _tcsncmp strncmp
5de3893d 222#define _tcsnicmp strnicmp
f2fdf1b5
VK
223#define _tprintf printf
224#define _stprintf sprintf
98d747e1 225#define _ftprintf fprintf
03ef9555 226#define _sntprintf snprintf
1a9fcf74 227#define _vtprintf vprintf
9ea100d2 228#define _vstprintf vsprintf
03ef9555 229#define _vsntprintf vsnprintf
25575d38
VK
230#define _tscanf scanf
231#define _ftscanf fscanf
f65df2b1 232#define _stscanf sscanf
25575d38
VK
233#define _vtscanf vscanf
234#define _vftscanf vfscanf
235#define _vstscanf vsscanf
f2fdf1b5 236#define _tfopen fopen
8c2489aa 237#define _tfopen64 fopen64
a3ad7bf2 238#define _tpopen popen
f2fdf1b5 239#define _fgetts fgets
94ee38a9 240#define _fputts fputs
0186b5da 241#define _putts puts
3188558a 242#define _puttc putc
f2fdf1b5
VK
243#define _tcstol strtol
244#define _tcstoul strtoul
dde96745
VK
245#define _tcstoll strtoll
246#define _tcstoull strtoull
f2fdf1b5
VK
247#define _tcstod strtod
248#define _tcsdup strdup
249#define _tcsupr strupr
fdb710a7 250#define _tcslwr strlwr
f2fdf1b5 251#define _tcsspn strspn
e33fc781 252#define _tcscspn strcspn
6f040d7b 253#define _tcsstr strstr
4507063f 254#define _tcscat strcat
9b13553b 255#define _tcscat_s strcat_s
e2717f44 256#define _tcsncat strncat
e02b69b9 257#define _tcspbrk strpbrk
9e3b4860 258#define _tcstok_r strtok_r
44d4f4f2
VK
259#define _topen _open
260#define _taccess _access
8b86c5dc 261#define _tstat stat
f3387429 262#define _tchmod chmod
1dd2715c 263#define _tunlink unlink
376e15e8 264#define _trename rename
80ce37ac 265#define _tremove remove
c4b88c3d 266#define _tcsftime strftime
98d747e1 267#define _tctime ctime
dde96745
VK
268#define _istspace isspace
269#define _istdigit isdigit
a8865589 270#define _istxdigit isxdigit
dde96745 271#define _istalpha isalpha
18a7c1e9 272#define _istalnum isalnum
dde96745 273#define _istupper isupper
f026b346 274#define _istprint isprint
9138dfe2 275#define _itot _itoa
d99ee887 276#define _tgetenv getenv
bd158b26 277#define _tmkdir mkdir
17b35ccc 278#define _tchdir chdir
b7ad6b85 279#define _trmdir rmdir
7b45b90d 280#define _tutime utime
d49d7500
VK
281#define _tcserror strerror
282#define _tcserror_r strerror_r
17b35ccc 283#define _tsystem system
f026b346
VK
284#define _topendir opendir
285#define _treaddir readdir
286#define _tclosedir closedir
37a7a862 287#define _tmkstemp mkstemp
f026b346 288#define _ERR_error_tstring ERR_error_string
f2fdf1b5 289
f026b346
VK
290#define _TDIR DIR
291#define _tdirent dirent
3d1058ed 292
73118723
VK
293#endif
294
3e39fcde
VK
295#define CP_ACP 0
296#define CP_UTF8 65001
4332e9d8
VK
297#define MB_PRECOMPOSED 0x00000001
298#define WC_COMPOSITECHECK 0x00000002
299#define WC_DEFAULTCHAR 0x00000004
300
5e40a69e 301// Default codepage for iconv()
29dc8792 302#define ICONV_DEFAULT_CODEPAGE "ASCII"
5e40a69e 303
3e39fcde 304#endif /* _WIN32 */
f2fdf1b5 305
268774a0
VK
306#ifdef UNICODE
307#define _t_inet_addr inet_addr_w
308#else
309#define _t_inet_addr inet_addr
310#endif
311
8b86c5dc 312// Check that either UNICODE_UCS2 or UNICODE_UCS4 are defined
8b86c5dc
VK
313#if !defined(UNICODE_UCS2) && !defined(UNICODE_UCS4)
314#error Neither UNICODE_UCS2 nor UNICODE_UCS4 are defined
315#endif
8b86c5dc 316
f2fdf1b5 317#endif /* _unicode_h_ */