Fixed problems with default iconv() codepage
[public/netxms.git] / include / unicode.h
1 /*
2 ** NetXMS - Network Management System
3 ** Copyright (C) 2003, 2004 Victor Kirhenshtein
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 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 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 ** $module: unicode.h
20 **
21 **/
22
23 #ifndef _unicode_h_
24 #define _unicode_h_
25
26 #ifdef _WIN32
27
28 // Ensure that both UNICODE and _UNICODE are defined
29 #ifdef _UNICODE
30 #ifndef UNICODE
31 #define UNICODE
32 #endif
33 #endif
34
35 #ifdef UNICODE
36 #ifndef _UNICODE
37 #define _UNICODE
38 #endif
39 #endif
40
41 #include <tchar.h>
42
43 #ifdef UNICODE
44
45 #define _tcstoll wcstoll
46 #define _tcstoull wcstoull
47
48 #else
49
50 #define _tcstoll strtoll
51 #define _tcstoull strtoull
52
53 #endif
54
55 #define ICONV_DEFAULT_CODEPAGE "ACP"
56
57 #else /* not _WIN32 */
58
59 #if HAVE_WCHAR_H
60 #include <wchar.h>
61 #endif
62
63 #if HAVE_STRING_H
64 #include <string.h>
65 #endif
66
67 #ifdef _NETWARE
68 #define WCHAR wchar_t
69 #else
70 #define WCHAR unsigned short
71 #endif
72
73 // Redefine wide character functions if system's wchar_t is not 2 bytes long
74 #if !HAVE_USEABLE_WCHAR
75
76 #define wcslen nx_wcslen
77
78 #endif
79
80 #ifdef UNICODE
81
82 #error UNICODE is not supported on non-Windows platforms
83
84 #else
85
86 // On some old systems, ctype.h defines _T macro, so we include it
87 // before our definition and do an undef
88 #include <ctype.h>
89
90 #undef _T
91 #define _T(x) x
92 #define TCHAR char
93 #define _TINT int
94
95 #define _tcscpy strcpy
96 #define _tcsncpy strncpy
97 #define _tcslen strlen
98 #define _tcschr strchr
99 #define _tcsrchr strrchr
100 #define _tcscmp strcmp
101 #define _tcsicmp stricmp
102 #define _tcsncmp strncmp
103 #define _tprintf printf
104 #define _stprintf sprintf
105 #define _ftprintf fprintf
106 #define _sntprintf snprintf
107 #define _vtprintf vprintf
108 #define _vstprintf vsprintf
109 #define _vsntprintf vsnprintf
110 #define _tfopen fopen
111 #define _fgetts fgets
112 #define _fputts fputs
113 #define _tcstol strtol
114 #define _tcstoul strtoul
115 #define _tcstoll strtoll
116 #define _tcstoull strtoull
117 #define _tcstod strtod
118 #define _tcsdup strdup
119 #define _tcsupr strupr
120 #define _tcsspn strspn
121 #define _tcsstr strstr
122 #define _tcscat strcat
123 #define _topen open
124 #define _taccess access
125 #define _tunlink unlink
126 #define _tcsftime strftime
127 #define _tctime ctime
128 #define _istspace isspace
129 #define _istdigit isdigit
130 #define _istalpha isalpha
131 #define _istupper isupper
132
133 #endif
134
135 #define CP_ACP 0
136 #define CP_UTF8 65001
137 #define MB_PRECOMPOSED 0x00000001
138 #define WC_COMPOSITECHECK 0x00000002
139 #define WC_DEFAULTCHAR 0x00000004
140
141 // Default codepage for iconv()
142 #if HAVE_ICONV_ISO_8859_1
143 #define ICONV_DEFAULT_CODEPAGE "ISO-8859-1"
144 #elif HAVE_ICONV_ISO8859_1
145 #define ICONV_DEFAULT_CODEPAGE "ISO8859-1"
146 #elif HAVE_ICONV_ASCII
147 #define ICONV_DEFAULT_CODEPAGE "ASCII"
148 #else
149 #define ICONV_DEFAULT_CODEPAGE ""
150 #endif
151
152 #endif /* _WIN32 */
153
154
155 #ifdef UNICODE
156 #define _t_inet_addr inet_addr_w
157 #else
158 #define _t_inet_addr inet_addr
159 #endif
160
161
162 #endif /* _unicode_h_ */