svn-gvsig-desktop / tags / extI18n-0.1.0-1045_8 / libraries / libjni-ecw / include / NCSUtil.h @ 40799
History | View | Annotate | Download (6.45 KB)
1 | 3538 | nacho | /********************************************************
|
---|---|---|---|
2 | ** Copyright 1999 Earth Resource Mapping Ltd.
|
||
3 | ** This document contains proprietary source code of
|
||
4 | ** Earth Resource Mapping Ltd, and can only be used under
|
||
5 | ** one of the three licenses as described in the
|
||
6 | ** license.txt file supplied with this distribution.
|
||
7 | ** See separate license.txt file for license details
|
||
8 | ** and conditions.
|
||
9 | **
|
||
10 | ** This software is covered by US patent #6,442,298,
|
||
11 | ** #6,102,897 and #6,633,688. Rights to use these patents
|
||
12 | ** is included in the license agreements.
|
||
13 | **
|
||
14 | ** FILE: NCSUtil.h
|
||
15 | ** CREATED: Thu Feb 25 09:19:00 WST 1999
|
||
16 | ** AUTHOR: Simon Cope
|
||
17 | ** PURPOSE: NCS Utility library header.
|
||
18 | ** EDITS:
|
||
19 | ** [01] ny 23May00 Modified NCSGetUserAndDomainName to be cross platform
|
||
20 | ** [02] ny 30Oct00 Merge CE/Palm modification in preparation for Macintosh port
|
||
21 | ** [03] ny 23Nov00 Mac port changes (Added NCSstrcasecmp)
|
||
22 | ** [04] sjc 28Aug01 Added NCSIsService() to detect if running as a service under WinNT/2K/XP Server.
|
||
23 | ** [05] sjc 11Mar02 Added NCSIsWebService() to detect if running as a web service under WinNT/2K/XP Server.
|
||
24 | ** [06] ajd 01Jul02 Added NCSNanVal() to generate NaNs
|
||
25 | ** [07] sjc 12Feb03 Added NCSLog2() to calculate log2() function
|
||
26 | *******************************************************/
|
||
27 | |||
28 | #ifndef NCSUTIL_H
|
||
29 | #define NCSUTIL_H
|
||
30 | |||
31 | // FIXME /**[02]**/
|
||
32 | #ifdef __PALM__ /**[02]**/ |
||
33 | #ifndef EMULATION_LEVEL /**[02]**/ |
||
34 | #define EMULATION_LEVEL 0 /**[02]**/ |
||
35 | #endif /**[02]**/ |
||
36 | #endif /**[02]**/ |
||
37 | |||
38 | #ifndef __PALM__ /**[02]**/ |
||
39 | #include <math.h> |
||
40 | #endif /**[02]**/ |
||
41 | |||
42 | #ifndef NCSTYPES_H
|
||
43 | #include "NCSTypes.h" |
||
44 | #endif
|
||
45 | #ifndef NCSDEFS_H
|
||
46 | #include "NCSDefs.h" |
||
47 | #endif
|
||
48 | #ifndef NCSDYNAMICLIB_H
|
||
49 | #include "NCSDynamicLib.h" |
||
50 | #endif
|
||
51 | #ifndef NCSERRORS_H
|
||
52 | #include "NCSErrors.h" |
||
53 | #endif
|
||
54 | #ifndef NCSMALLOC_H
|
||
55 | #include "NCSMalloc.h" |
||
56 | #endif
|
||
57 | #ifndef NCSARRAY_H
|
||
58 | #include "NCSArray.h" |
||
59 | #endif
|
||
60 | #ifndef NCSTIMESTAMP_H
|
||
61 | #include "NCSTimeStamp.h" |
||
62 | #endif
|
||
63 | #ifndef NCSMUTEX_H
|
||
64 | #include "NCSMutex.h" |
||
65 | #endif
|
||
66 | #ifndef NCSMEMPOOL_H
|
||
67 | #include "NCSMemPool.h" |
||
68 | #endif
|
||
69 | #ifndef NCSUTIL_H
|
||
70 | #include "NCSUtil.h" |
||
71 | #endif
|
||
72 | #ifndef NCSTHREAD_H
|
||
73 | #include "NCSThread.h" |
||
74 | #endif
|
||
75 | #ifndef NCSQUEUE_H
|
||
76 | #include "NCSQueue.h" |
||
77 | #endif
|
||
78 | #ifndef NCSPACKETS_H
|
||
79 | #include "NCSPackets.h" |
||
80 | #endif
|
||
81 | #ifndef NCSTIMER_H
|
||
82 | #include "NCSTimer.h" |
||
83 | #endif
|
||
84 | #ifndef NCSPREFS_H
|
||
85 | #include "NCSPrefs.h" |
||
86 | #endif
|
||
87 | #ifndef NCSFILEIO_H
|
||
88 | #include "NCSFileIO.h" |
||
89 | #endif
|
||
90 | #ifndef NCSMISC_H
|
||
91 | #include "NCSMisc.h" |
||
92 | #endif
|
||
93 | |||
94 | #ifdef MACINTOSH
|
||
95 | #include <extras.h> |
||
96 | #endif
|
||
97 | |||
98 | #ifdef __cplusplus
|
||
99 | extern "C" { |
||
100 | #endif
|
||
101 | |||
102 | INT32 NCSUtilInitialised(); |
||
103 | void NCSUtilInit(void); |
||
104 | void NCSUtilFini(void); |
||
105 | void NCSSleep(NCSTimeStampMs tsSleepTime);
|
||
106 | void NCSdbgOutputNewLeaks(void); |
||
107 | void NCSdbgOutputNewHandles(void); |
||
108 | char *NCSStrDup(char *pString); |
||
109 | NCSError NCSFormatCoordStringsEN(double dEasting, double dNorthing, char **ppEastString, char **ppNorthString); |
||
110 | NCSError NCSFormatCoordStringsLL(double dEasting, double dNorthing, char **ppEastString, char **ppNorthString); |
||
111 | UINT32 NCSGetNumCPUs(void);
|
||
112 | UINT32 NCSGetNumPhysicalCPUs(void);
|
||
113 | #ifdef WIN32
|
||
114 | BOOLEAN NCSGetUserAndDomainName(char *UserName, LPDWORD cchUserName, char* DomainName, LPDWORD cchDomainName); |
||
115 | UINT32 NCSGetWebServerID(const char *szPath, DWORD nPathLen); |
||
116 | #endif
|
||
117 | BOOLEAN NCSIsNaN(IEEE8 dDoubleValue); |
||
118 | BOOLEAN NCSIsService(void); /**[04]**/ |
||
119 | BOOLEAN NCSIsWebService(void); /**[05]**/ |
||
120 | |||
121 | double NCSNanVal(void); /**[06]**/ |
||
122 | BOOLEAN NCSDoubleIsNan(double v);
|
||
123 | |||
124 | #ifdef WIN32
|
||
125 | #ifdef _WIN32_WCE
|
||
126 | |||
127 | #if (_WIN32_WCE <= 211) |
||
128 | #define strnicmp(a, b, c) _memicmp(a, b, c)
|
||
129 | #define stricmp(a, b) _memicmp(a, b, MIN(strlen(a), strlen(b)))
|
||
130 | #else
|
||
131 | #define strnicmp(a, b, c) _strnicmp(a, b, c)
|
||
132 | #define stricmp(a, b) _stricmp(a, b)
|
||
133 | #endif
|
||
134 | |||
135 | #endif /* _WIN32_CE */ |
||
136 | |||
137 | #define vsnprintf _vsnprintf
|
||
138 | #define snprintf _snprintf
|
||
139 | |||
140 | #define NCSMessageBox(Window, Text, Caption, Type) ::MessageBox(Window, Text, Caption, Type)
|
||
141 | |||
142 | #elif defined __PALM__
|
||
143 | |||
144 | #define stricmp(a, b) StrCaselessCompare(a, b)
|
||
145 | #define strnicmp(a, b, c) StrNCaselessCompare(a, b, c)
|
||
146 | #define strcmp(a, b) StrCompare(a, b)
|
||
147 | #define strncmp(a, b) StrNCompare(a, b)
|
||
148 | #define strcpy(a, b) StrCopy(a, (const char*)b) |
||
149 | #define strncpy(a, b, c) StrNCopy(a, (const char*)b, c) |
||
150 | #define strlen(a) StrLen(a)
|
||
151 | #define calloc(a, b) NCSMalloc(a * b, TRUE)
|
||
152 | #define malloc(a) NCSMalloc(a, FALSE)
|
||
153 | #define realloc(a, b) NCSRealloc((void*)a, b, TRUE) |
||
154 | #define free(a) NCSFree(a)
|
||
155 | #define memcpy(a, b, c) MemMove(a, b, c)
|
||
156 | #define memset(a, b, c) MemSet(a, c, b)
|
||
157 | #define isupper(a) ((((a) >= 'A') && ((a) <= 'Z')) ? TRUE : FALSE) |
||
158 | #define tolower(a) ((a) -= ('A' - 'a')) |
||
159 | int sscanf(const char *string, const char *format, ...); |
||
160 | __inline double atof(char *s) |
||
161 | { |
||
162 | double d;
|
||
163 | sscanf(s, "%f", &d);
|
||
164 | return(d);
|
||
165 | } |
||
166 | |||
167 | |||
168 | #elif defined MACINTOSH
|
||
169 | |||
170 | #if TARGET_API_MAC_CARBON
|
||
171 | # define _stricmp stricmp
|
||
172 | # define _strnicmp strnicmp
|
||
173 | # define _itoa itoa
|
||
174 | #else
|
||
175 | # define strncascmp _stricmp
|
||
176 | # define NCSstrcasecmp _stricmp
|
||
177 | # define strnicmp _strnicmp
|
||
178 | # define stricmp _stricmp
|
||
179 | #endif //TARGET_API_MAC_CARBON |
||
180 | |||
181 | #else /* __PALM__ */ |
||
182 | |||
183 | #define stricmp(a, b) strcasecmp(a, b)
|
||
184 | #define strnicmp(a, b, c) strncasecmp(a, b, c)
|
||
185 | |||
186 | #endif /* WIN32 */ |
||
187 | |||
188 | #ifdef UNICODE
|
||
189 | |||
190 | static NCS_INLINE wchar_t *NCSA2WHelper(wchar_t *lpw, const char *lpa, int nChars) |
||
191 | { |
||
192 | lpw[0] = '\0'; |
||
193 | #ifdef WIN32
|
||
194 | MultiByteToWideChar(CP_ACP, 0, (LPSTR)lpa, -1, (LPWSTR)lpw, nChars); |
||
195 | #else
|
||
196 | mbstowcs(lpw, lpa, nChars); |
||
197 | #endif
|
||
198 | return lpw;
|
||
199 | } |
||
200 | |||
201 | static NCS_INLINE char *NCSW2AHelper(char *lpa, const wchar_t *lpw, int nChars) |
||
202 | { |
||
203 | lpa[0] = '\0'; |
||
204 | #ifdef WIN32
|
||
205 | WideCharToMultiByte(CP_ACP, 0, (LPWSTR)lpw, -1, (LPSTR)lpa, nChars, NULL, NULL); |
||
206 | #else
|
||
207 | wcstombs(lpa, lpw, nChars); |
||
208 | #endif
|
||
209 | return lpa;
|
||
210 | } |
||
211 | |||
212 | #define OS_STRING(lpa) (((lpa) == NULL) ? NULL : NCSA2WHelper((wchar_t*) alloca(((int)strlen(lpa)+1)*2*sizeof(wchar_t)), (lpa), ((int)strlen(lpa)+1))) |
||
213 | #define CHAR_STRING(lpw) (((lpw) == NULL) ? NULL : NCSW2AHelper((char*) alloca(((int)wcslen(lpw)+1)*2), (lpw), ((int)wcslen(lpw)+1)*2)) |
||
214 | |||
215 | #ifndef WIN32
|
||
216 | #define _tcscmp wcscmp
|
||
217 | |||
218 | #ifdef SOLARIS
|
||
219 | |||
220 | #include <wchar.h> |
||
221 | |||
222 | static NCS_INLINE int wcsicmp(const wchar_t *s1, const wchar_t *s2) |
||
223 | { |
||
224 | while ((*s2 != L'\0') && (towlower(*s1) == towlower(*s2))) { |
||
225 | s1++; |
||
226 | s2++; |
||
227 | } |
||
228 | return(towlower(*s1) - towlower(*s2));
|
||
229 | } |
||
230 | |||
231 | static NCS_INLINE wchar_t *wcsdup(const wchar_t *s1) |
||
232 | { |
||
233 | size_t len = (wcslen(s1) + 1) * sizeof(wchar_t); |
||
234 | wchar_t *s2 = (wchar_t*)malloc(len); |
||
235 | memcpy(s2, s1, len); |
||
236 | return(s2);
|
||
237 | } |
||
238 | |||
239 | #endif // SOLARIS |
||
240 | |||
241 | #endif //!WIN32 |
||
242 | |||
243 | #else /* UNICODE */ |
||
244 | |||
245 | #define OS_STRING(lpa) (lpa)
|
||
246 | #define CHAR_STRING(lpw) (lpw)
|
||
247 | |||
248 | #ifndef WIN32
|
||
249 | #define _tcscmp strcmp
|
||
250 | #endif //!WIN32 |
||
251 | |||
252 | #endif /* UNICODE */ |
||
253 | |||
254 | #ifdef __cplusplus
|
||
255 | } |
||
256 | #endif
|
||
257 | |||
258 | #endif /* NCSUTIL_H */ |