• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*---------------------------------------------------------------------------*
2  *  ptypes.h  *
3  *                                                                           *
4  *  Copyright 2007, 2008 Nuance Communciations, Inc.                               *
5  *                                                                           *
6  *  Licensed under the Apache License, Version 2.0 (the 'License');          *
7  *  you may not use this file except in compliance with the License.         *
8  *                                                                           *
9  *  You may obtain a copy of the License at                                  *
10  *      http://www.apache.org/licenses/LICENSE-2.0                           *
11  *                                                                           *
12  *  Unless required by applicable law or agreed to in writing, software      *
13  *  distributed under the License is distributed on an 'AS IS' BASIS,        *
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
15  *  See the License for the specific language governing permissions and      *
16  *  limitations under the License.                                           *
17  *                                                                           *
18  *---------------------------------------------------------------------------*/
19 
20 #ifndef __PTYPES_H
21 #define __PTYPES_H
22 
23 
24 
25 #include <string.h>
26 #include <ctype.h>
27 #include "limits.h"
28 #include "PortPrefix.h"
29 
30 #ifndef MAX
31 #define MAX(A,B) ((A)>(B)?(A):(B))
32 #endif
33 #ifndef MIN
34 #define MIN(A,B) ((A)<(B)?(A):(B))
35 #endif
36 
37 
38 /**
39  * Boolean definition.
40  */
41 typedef enum ESR_BOOL
42 {
43   ESR_FALSE = 0,
44   ESR_TRUE = 1
45 } ESR_BOOL;
46 
47 /**
48  * @addtogroup ESR_PortableModule ESR_Portable API functions
49  *
50  * @{
51  */
52 
53 #ifdef _WIN32
54 
55 #pragma warning (disable: 4100 4127)
56 #pragma warning (error: 4133 4020)
57 
58 #ifndef WIN32_LEAN_AND_MEAN
59 #define WIN32_LEAN_AND_MEAN
60 #endif
61 #include <windows.h>
62 
63 /**
64  * Portable 32-bit unsigned integer.
65  */
66 typedef unsigned int   asr_uint32_t;
67 
68 /**
69  * Portable 32-bit signed integer.
70  */
71 typedef int            asr_int32_t;
72 
73 /**
74  * Portable 16-bit unsigned integer.
75  */
76 typedef unsigned short asr_uint16_t;
77 
78 /**
79  * Portable 16-bit signed integer.
80  */
81 typedef short          asr_int16_t;
82 
83 /**
84  * Portable 8-bit unsigned integer.
85  */
86 typedef unsigned char asr_uint8_t;
87 
88 /**
89  * Portable 8-bit signed integer.
90  */
91 typedef signed char   asr_int8_t;
92 
93 #else
94 
95 
96 /**
97  * Portable 32-bit unsigned integer.
98  */
99 typedef unsigned int   asr_uint32_t;
100 
101 /**
102  * Portable 32-bit signed integer.
103  */
104 typedef int            asr_int32_t;
105 
106 /**
107  * Portable 16-bit unsigned integer.
108  */
109 typedef unsigned short asr_uint16_t;
110 
111 /**
112  * Portable 16-bit signed integer.
113  */
114 typedef short          asr_int16_t;
115 
116 /**
117  * Portable 8-bit unsigned integer.
118  */
119 typedef unsigned char asr_uint8_t;
120 
121 /**
122  * Portable 8-bit signed integer.
123  */
124 typedef signed char   asr_int8_t;
125 
126 ///**
127 // * Boolean definition.
128 // */
129 //#ifdef __vxworks
130 ///* VxWorks defines BOOL as: typedef int BOOL in vxTypesOld.h */
131 //#include <vxWorks.h>
132 //#define FALSE 0
133 //#define TRUE  1
134 //#endif
135 
136 #ifdef _solaris_
137 #include <sys/int_types.h>
138 #elif defined(_decunix_)
139 #include <inttypes.h>
140 #elif defined(POSIX)
141 
142 #include <time.h>
143 #include <errno.h>
144 
145 #if (CPU != SIMNT)
146 typedef void * HANDLE;
147 #endif /*  (CPU != SIMNT) */
148 
149 #if defined(__vxworks)  /* VxWorks */
150 #include <sys/times.h>
151 #include <types.h>
152 /* VxWorks does not support recursive mutex in POSIX.4 */
153 #define OS_NO_RECURSIVE_MUTEX_SUPPORT
154 #elif defined(_QNX_) /* QNX */
155 #include <sys/time.h>
156 #include <inttypes.h>
157 #elif (OS == OS_UNIX)
158 #include <string.h>
159 #include <pthread.h>
160 #else
161 #error "New OS support here"
162 #endif
163 
164 #ifndef _POSIX_SOURCE
165 #define _POSIX_SOURCE
166 #endif
167 
168 /* Both POSIX.1 and POSIX.4 (POSIX1003.1c) are supported */
169 #ifndef _POSIX_C_SOURCE
170 #define _POSIX_C_SOURCE 199309
171 #endif
172 
173 #include <unistd.h>
174 /*
175 #ifndef _POSIX_VERSION
176 #error "POSIX is not supported!")
177 #elif _POSIX_VERSION == 199009
178 #pragma message("POSIX.1 is supported only")
179 #elif _POSIX_VERSION == 199309
180 #pragma message("POSIX.1 and POSIX.4 are supported")
181 #elif _POSIX_VERSION > 199309
182 #pragma message("Version is newer than POSIX.4")
183 #endif // _POSIX_VERSION
184 */
185 #else
186 /* Linux, maybe others too */
187 #endif
188 #endif
189 
190 /**
191  * Minimum value of UINT16_T.
192  */
193 #define UINT16_TMIN 0
194 
195 /**
196  * Maximum value of UINT16_T.
197  */
198 #define UINT16_TMAX 65535
199 
200 /*
201  * These should be platform-dependent.  But for the moment, we will assume
202  * narrow character.
203  */
204 #ifndef USE_NARROW_CHAR
205 #define USE_NARROW_CHAR
206 #endif
207 
208 #ifdef USE_NARROW_CHAR
209 /**
210  * Locale-independant character.
211  */
212 typedef char LCHAR;
213 
214 /**
215  * Locale-independant integer-representation of a character. Used by fgetc() and others.
216  */
217 typedef int LINT;
218 
219 /**
220  * LCHAR version of string-constant
221  */
222 #define L(x) x
223 
224 /**
225  * LCHAR version of strcat()
226  */
227 #define LSTRCAT strcat
228 
229 /**
230  * LCHAR version of strchr()
231  */
232 #define LSTRCHR strchr
233 
234 /**
235  * LCHAR version of strrchr()
236  */
237 #define LSTRRCHR strrchr
238 
239 /**
240  * LCHAR version of strcmp()
241  */
242 #define LSTRCMP strcmp
243 
244 /**
245  * LCHAR version of strncmp()
246  */
247 #define LSTRNCMP strncmp
248 
249 /**
250  * LCHAR version of strcpy()
251  */
252 #define LSTRCPY strcpy
253 
254 /**
255  * LCHAR version of strftime()
256  */
257 #define LSTRFTIME strftime
258 
259 /**
260  * LCHAR version of strlen()
261  */
262 #define LSTRLEN strlen
263 
264 /**
265  * LCHAR version of strncpy()
266  */
267 #define LSTRNCPY strncpy
268 
269 /**
270  * LCHAR version of memmove()
271  */
272 #define LMEMMOVE memmove
273 
274 /**
275  * LCHAR version of strstr()
276  */
277 #define LSTRSTR strstr
278 
279 /**
280  * LCHAR version of strlwr() which converts a string to lowercase.
281  */
282 #define LSTRLWR lstrlwr
283 
284 /**
285  * LCHAR version of strupr() which converts a string to lowercase.
286  */
287 #define LSTRUPR lstrupr
288 
289 /**
290  * LCHAR version of strtod()
291  */
292 #define LSTRTOD strtod
293 
294 /**
295  * LCHAR version of strtol()
296  */
297 #define LSTRTOL strtol
298 
299 /**
300  * LCHAR version of strtoul()
301  */
302 #define LSTRTOUL strtoul
303 
304 /**
305  * LCHAR version of isspace()
306  */
307 #define LISSPACE(c) isspace((unsigned char) c)
308 
309 /**
310  * LCHAR version of strcspn()
311  */
312 #define LSTRCSPN strcspn
313 
314 /**
315  * LCHAR version of isalpha()
316  */
317 #define LISALPHA isalpha
318 
319 /**
320  * LCHAR version of isalnum()
321  */
322 #define LISALNUM isalnum
323 
324 /**
325  * LCHAR version of isdigit()
326  */
327 #define LISDIGIT isdigit
328 
329 /**
330  * LCHAR version of strtok()
331  */
332 #define LSTRTOK strtok
333 
334 /**
335  * LCHAR version of getenv()
336  */
337 #define LGETENV getenv
338 
339 /**
340  * Converts LCHAR character to uppercase.
341  */
342 #define LTOUPPER toupper
343 
344 /**
345  * Converts LCHAR character to lowercase.
346  */
347 #define LTOLOWER tolower
348 
349 /**
350  * Portable printf().
351  */
352 #define LPRINTF   printf
353 /**
354  * Portable fprintf().
355  */
356 #define LFPRINTF fprintf
357 /**
358  * Portable sprintf().
359  */
360 #define LSPRINTF sprintf
361 
362 /**
363  * Portable sprintf().
364  */
365 #define psprintf sprintf
366 
367 /**
368  * Portable svprintf().
369  */
370 #define pvsprintf vsprintf
371 
372 #else
373 
374 #include <wchar.h>
375 typedef wchar_t LCHAR;
376 /**
377 * Locale-independant integer-representation of a character. Used by fgetc() and others.
378 */
379 typedef wint_t LINT;
380 #define L(x) L ## x
381 #define LSTRCAT wcscat
382 #define LSTRCHR wcschr
383 #define LSTRRCHR wcsrchr
384 #define LSTRCMP wcscmp
385 #define LSTRNCMP wcsncmp
386 #define LSTRCPY wcscpy
387 #define LSTRFTIME wcsftime
388 
389 #define LPRINTF   wprintf
390 #define LFPRINTF fwprintf
391 #define LSPRINTF swprintf
392 
393 #ifdef _WIN32
394 
395 /**
396 * LCHAR version of getenv()
397 */
398 #define LGETENV wgetenv
399 
400 /**
401 * LCHAR version of strlwr() which converts a string to lowercase.
402 */
403 #define LSTRLWR _wcslwr
404 
405 /**
406 * LCHAR version of strtok()
407 */
408 #define LSTRTOK wcstok
409 
410 /**
411 * LCHAR version of strupr() which converts a string to lowercase.
412 */
413 #define LSTRUPR _wcsupr
414 #else
415 #define LSTRCASECMP wcscasecmp
416 #define LSTRLWR #error LSTRLWR not defined.
417 #define LSTRUPR #error LSTRUPR not defined.
418 #endif /* _WIN32 */
419 
420 #define LSTRLEN wcslen
421 #define LSTRNCPY wcsncpy
422 #define LMEMMOVE wmemmove
423 #define LSTRSTR wcsstr
424 #define LSTRTOD wcstod
425 #define LSTRTOL wcstol
426 #define LSTRTOUL wcstoul
427 #define LISSPACE iswspace
428 #define LSTRCSPN wcscspn
429 #define LISALPHA iswalpha
430 #define LISALNUM iswalnum
431 #define LISDIGIT iswdigit
432 
433 /**
434 * Converts LCHAR character to uppercase.
435 */
436 #define LTOUPPER towupper
437 
438 /**
439 * Converts LCHAR character to lowercase.
440 */
441 #define LTOLOWER towlower
442 
443 /**
444 * Portable sprintf().
445 */
446 #define psprintf sprintf
447 
448 /**
449 * Portable svprintf().
450 */
451 #define pvsprintf vsprintf
452 
453 #endif /* USE_NARROW_CHAR */
454 
455 /**
456  * Log of 2 in base 10.
457  */
458 #define LOG_10_2 (0.30102999566398)
459 
460 
461 /**
462  * Maximum number of digits used to represent an unsigned int as a string in
463  * base 10.  The +1 is for taking into account the fact that the fractional
464  * part is removed and that we really need to take the ceiling.
465  */
466 #define MAX_UINT_DIGITS ((size_t) ((CHAR_BIT * sizeof(int) * LOG_10_2) + 1))
467 
468 /**
469  * Maximum number of digits used to represent an int as a string in base 10.
470  * +1 for sign character [+, -]
471  */
472 #define MAX_INT_DIGITS ((size_t) (MAX_UINT_DIGITS + 1))
473 
474 /**
475  * Indicates if text contains a number (and nothing else).
476  *
477  * @param text String to check
478  * @return ESR_TRUE if text is a number, ESR_FALSE otherwise.
479  */
480 PORTABLE_API ESR_BOOL isNumber(const LCHAR* text);
481 
482 /**
483  * @}
484  */
485 
486 
487 #include "ESR_ReturnCode.h"
488 
489 
490 #include "pstdio.h"
491 
492 #endif
493 
494 
495