root/branches/perian-1.1/UniversalDetector/kludge/prtypes.h

Revision 406, 18.8 kB (checked in by astrange, 2 years ago)

Use the (LGPL) Mozilla automatic charset detection library for external subtitles.
Unfortunately, it's quite large...
References #87

Line 
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is the Netscape Portable Runtime (NSPR).
16  *
17  * The Initial Developer of the Original Code is
18  * Netscape Communications Corporation.
19  * Portions created by the Initial Developer are Copyright (C) 1998-2000
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either the GNU General Public License Version 2 or later (the "GPL"), or
26  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27  * in which case the provisions of the GPL or the LGPL are applicable instead
28  * of those above. If you wish to allow use of your version of this file only
29  * under the terms of either the GPL or the LGPL, and not to allow others to
30  * use your version of this file under the terms of the MPL, indicate your
31  * decision by deleting the provisions above and replace them with the notice
32  * and other provisions required by the GPL or the LGPL. If you do not delete
33  * the provisions above, a recipient may use your version of this file under
34  * the terms of any one of the MPL, the GPL or the LGPL.
35  *
36  * ***** END LICENSE BLOCK ***** */
37
38 /*
39 ** File:                prtypes.h
40 ** Description: Definitions of NSPR's basic types
41 **
42 ** Prototypes and macros used to make up for deficiencies that we have found
43 ** in ANSI environments.
44 **
45 ** Since we do not wrap <stdlib.h> and all the other standard headers, authors
46 ** of portable code will not know in general that they need these definitions.
47 ** Instead of requiring these authors to find the dependent uses in their code
48 ** and take the following steps only in those C files, we take steps once here
49 ** for all C files.
50 **/
51
52 #ifndef prtypes_h___
53 #define prtypes_h___
54
55 #ifdef MDCPUCFG
56 #include MDCPUCFG
57 #else
58 #include "prcpucfg.h"
59 #endif
60
61 #include <stddef.h>
62
63 /***********************************************************************
64 ** MACROS:      PR_EXTERN
65 **              PR_IMPLEMENT
66 ** DESCRIPTION:
67 **      These are only for externally visible routines and globals.  For
68 **      internal routines, just use "extern" for type checking and that
69 **      will not export internal cross-file or forward-declared symbols.
70 **      Define a macro for declaring procedures return types. We use this to
71 **      deal with windoze specific type hackery for DLL definitions. Use
72 **      PR_EXTERN when the prototype for the method is declared. Use
73 **      PR_IMPLEMENT for the implementation of the method.
74 **
75 ** Example:
76 **   in dowhim.h
77 **     PR_EXTERN( void ) DoWhatIMean( void );
78 **   in dowhim.c
79 **     PR_IMPLEMENT( void ) DoWhatIMean( void ) { return; }
80 **
81 **
82 ***********************************************************************/
83 #if defined(WIN32)
84
85 #define PR_EXPORT(__type) extern __declspec(dllexport) __type
86 #define PR_EXPORT_DATA(__type) extern __declspec(dllexport) __type
87 #define PR_IMPORT(__type) __declspec(dllimport) __type
88 #define PR_IMPORT_DATA(__type) __declspec(dllimport) __type
89
90 #define PR_EXTERN(__type) extern __declspec(dllexport) __type
91 #define PR_IMPLEMENT(__type) __declspec(dllexport) __type
92 #define PR_EXTERN_DATA(__type) extern __declspec(dllexport) __type
93 #define PR_IMPLEMENT_DATA(__type) __declspec(dllexport) __type
94
95 #define PR_CALLBACK
96 #define PR_CALLBACK_DECL
97 #define PR_STATIC_CALLBACK(__x) static __x
98
99 #elif defined(XP_BEOS)
100
101 #define PR_EXPORT(__type) extern __declspec(dllexport) __type
102 #define PR_EXPORT_DATA(__type) extern __declspec(dllexport) __type
103 #define PR_IMPORT(__type) extern __declspec(dllexport) __type
104 #define PR_IMPORT_DATA(__type) extern __declspec(dllexport) __type
105
106 #define PR_EXTERN(__type) extern __declspec(dllexport) __type
107 #define PR_IMPLEMENT(__type) __declspec(dllexport) __type
108 #define PR_EXTERN_DATA(__type) extern __declspec(dllexport) __type
109 #define PR_IMPLEMENT_DATA(__type) __declspec(dllexport) __type
110
111 #define PR_CALLBACK
112 #define PR_CALLBACK_DECL
113 #define PR_STATIC_CALLBACK(__x) static __x
114
115 #elif defined(WIN16)
116
117 #define PR_CALLBACK_DECL        __cdecl
118
119 #if defined(_WINDLL)
120 #define PR_EXPORT(__type) extern __type _cdecl _export _loadds
121 #define PR_IMPORT(__type) extern __type _cdecl _export _loadds
122 #define PR_EXPORT_DATA(__type) extern __type _export
123 #define PR_IMPORT_DATA(__type) extern __type _export
124
125 #define PR_EXTERN(__type) extern __type _cdecl _export _loadds
126 #define PR_IMPLEMENT(__type) __type _cdecl _export _loadds
127 #define PR_EXTERN_DATA(__type) extern __type _export
128 #define PR_IMPLEMENT_DATA(__type) __type _export
129
130 #define PR_CALLBACK             __cdecl __loadds
131 #define PR_STATIC_CALLBACK(__x) static __x PR_CALLBACK
132
133 #else /* this must be .EXE */
134 #define PR_EXPORT(__type) extern __type _cdecl _export
135 #define PR_IMPORT(__type) extern __type _cdecl _export
136 #define PR_EXPORT_DATA(__type) extern __type _export
137 #define PR_IMPORT_DATA(__type) extern __type _export
138
139 #define PR_EXTERN(__type) extern __type _cdecl _export
140 #define PR_IMPLEMENT(__type) __type _cdecl _export
141 #define PR_EXTERN_DATA(__type) extern __type _export
142 #define PR_IMPLEMENT_DATA(__type) __type _export
143
144 #define PR_CALLBACK             __cdecl __loadds
145 #define PR_STATIC_CALLBACK(__x) __x PR_CALLBACK
146 #endif /* _WINDLL */
147
148 // goafix
149 #elif defined(NOT_XP_MAC)
150
151 #define PR_EXPORT(__type) extern __declspec(export) __type
152 #define PR_EXPORT_DATA(__type) extern __declspec(export) __type
153 #define PR_IMPORT(__type) extern __declspec(export) __type
154 #define PR_IMPORT_DATA(__type) extern __declspec(export) __type
155
156 #define PR_EXTERN(__type) extern __declspec(export) __type
157 #define PR_IMPLEMENT(__type) __declspec(export) __type
158 #define PR_EXTERN_DATA(__type) extern __declspec(export) __type
159 #define PR_IMPLEMENT_DATA(__type) __declspec(export) __type
160
161 #define PR_CALLBACK
162 #define PR_CALLBACK_DECL
163 #define PR_STATIC_CALLBACK(__x) static __x
164
165 #elif defined(XP_OS2_VACPP)
166
167 #define PR_EXPORT(__type) extern __type
168 #define PR_EXPORT_DATA(__type) extern __type
169 #define PR_IMPORT(__type) extern __type
170 #define PR_IMPORT_DATA(__type) extern __type
171
172 #define PR_EXTERN(__type) extern __type
173 #define PR_IMPLEMENT(__type) __type
174 #define PR_EXTERN_DATA(__type) extern __type
175 #define PR_IMPLEMENT_DATA(__type) __type
176 #define PR_CALLBACK _Optlink
177 #define PR_CALLBACK_DECL
178 #define PR_STATIC_CALLBACK(__x) static __x PR_CALLBACK
179
180 #else /* Unix */
181
182 #ifdef HAVE_VISIBILITY_PRAGMA
183 #define PR_VISIBILITY_DEFAULT __attribute__((visibility("default")))
184 #else
185 #define PR_VISIBILITY_DEFAULT
186 #endif
187
188 #define PR_EXPORT(__type) extern PR_VISIBILITY_DEFAULT __type
189 #define PR_EXPORT_DATA(__type) extern PR_VISIBILITY_DEFAULT __type
190 #define PR_IMPORT(__type) extern PR_VISIBILITY_DEFAULT __type
191 #define PR_IMPORT_DATA(__type) extern PR_VISIBILITY_DEFAULT __type
192
193 #define PR_EXTERN(__type) extern PR_VISIBILITY_DEFAULT __type
194 #define PR_IMPLEMENT(__type) PR_VISIBILITY_DEFAULT __type
195 #define PR_EXTERN_DATA(__type) extern PR_VISIBILITY_DEFAULT __type
196 #define PR_IMPLEMENT_DATA(__type) PR_VISIBILITY_DEFAULT __type
197 #define PR_CALLBACK
198 #define PR_CALLBACK_DECL
199 #define PR_STATIC_CALLBACK(__x) static __x
200
201 #endif
202
203 #if defined(_NSPR_BUILD_)
204 #define NSPR_API(__type) PR_EXPORT(__type)
205 #define NSPR_DATA_API(__type) PR_EXPORT_DATA(__type)
206 #else
207 #define NSPR_API(__type) PR_IMPORT(__type)
208 #define NSPR_DATA_API(__type) PR_IMPORT_DATA(__type)
209 #endif
210
211 /***********************************************************************
212 ** MACROS:      PR_BEGIN_MACRO
213 **              PR_END_MACRO
214 ** DESCRIPTION:
215 **      Macro body brackets so that macros with compound statement definitions
216 **      behave syntactically more like functions when called.
217 ***********************************************************************/
218 #define PR_BEGIN_MACRO  do {
219 #define PR_END_MACRO    } while (0)
220
221 /***********************************************************************
222 ** MACROS:      PR_BEGIN_EXTERN_C
223 **              PR_END_EXTERN_C
224 ** DESCRIPTION:
225 **      Macro shorthands for conditional C++ extern block delimiters.
226 ***********************************************************************/
227 #ifdef __cplusplus
228 #define PR_BEGIN_EXTERN_C       extern "C" {
229 #define PR_END_EXTERN_C         }
230 #else
231 #define PR_BEGIN_EXTERN_C
232 #define PR_END_EXTERN_C
233 #endif
234
235 /***********************************************************************
236 ** MACROS:      PR_BIT
237 **              PR_BITMASK
238 ** DESCRIPTION:
239 ** Bit masking macros.  XXX n must be <= 31 to be portable
240 ***********************************************************************/
241 #define PR_BIT(n)       ((PRUint32)1 << (n))
242 #define PR_BITMASK(n)   (PR_BIT(n) - 1)
243
244 /***********************************************************************
245 ** MACROS:      PR_ROUNDUP
246 **              PR_MIN
247 **              PR_MAX
248 **              PR_ABS
249 ** DESCRIPTION:
250 **      Commonly used macros for operations on compatible types.
251 ***********************************************************************/
252 #define PR_ROUNDUP(x,y) ((((x)+((y)-1))/(y))*(y))
253 #define PR_MIN(x,y)     ((x)<(y)?(x):(y))
254 #define PR_MAX(x,y)     ((x)>(y)?(x):(y))
255 #define PR_ABS(x)       ((x)<0?-(x):(x))
256
257 PR_BEGIN_EXTERN_C
258
259 /************************************************************************
260 ** TYPES:       PRUint8
261 **              PRInt8
262 ** DESCRIPTION:
263 **  The int8 types are known to be 8 bits each. There is no type that
264 **      is equivalent to a plain "char".
265 ************************************************************************/
266 #if PR_BYTES_PER_BYTE == 1
267 typedef unsigned char PRUint8;
268 /*
269 ** Some cfront-based C++ compilers do not like 'signed char' and
270 ** issue the warning message:
271 **     warning: "signed" not implemented (ignored)
272 ** For these compilers, we have to define PRInt8 as plain 'char'.
273 ** Make sure that plain 'char' is indeed signed under these compilers.
274 */
275 #if (defined(HPUX) && defined(__cplusplus) \
276         && !defined(__GNUC__) && __cplusplus < 199707L) \
277     || (defined(SCO) && defined(__cplusplus) \
278         && !defined(__GNUC__) && __cplusplus == 1L)
279 typedef char PRInt8;
280 #else
281 typedef signed char PRInt8;
282 #endif
283 #else
284 #error No suitable type for PRInt8/PRUint8
285 #endif
286
287 /************************************************************************
288  * MACROS:      PR_INT8_MAX
289  *              PR_INT8_MIN
290  *              PR_UINT8_MAX
291  * DESCRIPTION:
292  *  The maximum and minimum values of a PRInt8 or PRUint8.
293 ************************************************************************/
294
295 #define PR_INT8_MAX 127
296 #define PR_INT8_MIN (-128)
297 #define PR_UINT8_MAX 255U
298
299 /************************************************************************
300 ** TYPES:       PRUint16
301 **              PRInt16
302 ** DESCRIPTION:
303 **  The int16 types are known to be 16 bits each.
304 ************************************************************************/
305 #if PR_BYTES_PER_SHORT == 2
306 typedef unsigned short PRUint16;
307 typedef short PRInt16;
308 #else
309 #error No suitable type for PRInt16/PRUint16
310 #endif
311
312 /************************************************************************
313  * MACROS:      PR_INT16_MAX
314  *              PR_INT16_MIN
315  *              PR_UINT16_MAX
316  * DESCRIPTION:
317  *  The maximum and minimum values of a PRInt16 or PRUint16.
318 ************************************************************************/
319
320 #define PR_INT16_MAX 32767
321 #define PR_INT16_MIN (-32768)
322 #define PR_UINT16_MAX 65535U
323
324 /************************************************************************
325 ** TYPES:       PRUint32
326 **              PRInt32
327 ** DESCRIPTION:
328 **  The int32 types are known to be 32 bits each.
329 ************************************************************************/
330 #if PR_BYTES_PER_INT == 4
331 typedef unsigned int PRUint32;
332 typedef int PRInt32;
333 #define PR_INT32(x)  x
334 #define PR_UINT32(x) x ## U
335 #elif PR_BYTES_PER_LONG == 4
336 typedef unsigned long PRUint32;
337 typedef long PRInt32;
338 #define PR_INT32(x)  x ## L
339 #define PR_UINT32(x) x ## UL
340 #else
341 #error No suitable type for PRInt32/PRUint32
342 #endif
343
344 /************************************************************************
345  * MACROS:      PR_INT32_MAX
346  *              PR_INT32_MIN
347  *              PR_UINT32_MAX
348  * DESCRIPTION:
349  *  The maximum and minimum values of a PRInt32 or PRUint32.
350 ************************************************************************/
351
352 #define PR_INT32_MAX PR_INT32(2147483647)
353 #define PR_INT32_MIN (-PR_INT32_MAX - 1)
354 #define PR_UINT32_MAX PR_UINT32(4294967295)
355
356 /************************************************************************
357 ** TYPES:       PRUint64
358 **              PRInt64
359 ** DESCRIPTION:
360 **  The int64 types are known to be 64 bits each. Care must be used when
361 **      declaring variables of type PRUint64 or PRInt64. Different hardware
362 **      architectures and even different compilers have varying support for
363 **      64 bit values. The only guaranteed portability requires the use of
364 **      the LL_ macros (see prlong.h).
365 ************************************************************************/
366 #ifdef HAVE_LONG_LONG
367 #if PR_BYTES_PER_LONG == 8
368 typedef long PRInt64;
369 typedef unsigned long PRUint64;
370 #elif defined(WIN16)
371 typedef __int64 PRInt64;
372 typedef unsigned __int64 PRUint64;
373 #elif defined(WIN32) && !defined(__GNUC__)
374 typedef __int64  PRInt64;
375 typedef unsigned __int64 PRUint64;
376 #else
377 typedef long long PRInt64;
378 typedef unsigned long long PRUint64;
379 #endif /* PR_BYTES_PER_LONG == 8 */
380 #else  /* !HAVE_LONG_LONG */
381 typedef struct {
382 #ifdef IS_LITTLE_ENDIAN
383     PRUint32 lo, hi;
384 #else
385     PRUint32 hi, lo;
386 #endif
387 } PRInt64;
388 typedef PRInt64 PRUint64;
389 #endif /* !HAVE_LONG_LONG */
390
391 /************************************************************************
392 ** TYPES:       PRUintn
393 **              PRIntn
394 ** DESCRIPTION:
395 **  The PRIntn types are most appropriate for automatic variables. They are
396 **      guaranteed to be at least 16 bits, though various architectures may
397 **      define them to be wider (e.g., 32 or even 64 bits). These types are
398 **      never valid for fields of a structure.
399 ************************************************************************/
400 #if PR_BYTES_PER_INT >= 2
401 typedef int PRIntn;
402 typedef unsigned int PRUintn;
403 #else
404 #error 'sizeof(int)' not sufficient for platform use
405 #endif
406
407 /************************************************************************
408 ** TYPES:       PRFloat64
409 ** DESCRIPTION:
410 **  NSPR's floating point type is always 64 bits.
411 ************************************************************************/
412 typedef double          PRFloat64;
413
414 /************************************************************************
415 ** TYPES:       PRSize
416 ** DESCRIPTION:
417 **  A type for representing the size of objects.
418 ************************************************************************/
419 typedef size_t PRSize;
420
421
422 /************************************************************************
423 ** TYPES:       PROffset32, PROffset64
424 ** DESCRIPTION:
425 **  A type for representing byte offsets from some location.
426 ************************************************************************/
427 typedef PRInt32 PROffset32;
428 typedef PRInt64 PROffset64;
429
430 /************************************************************************
431 ** TYPES:       PRPtrDiff
432 ** DESCRIPTION:
433 **  A type for pointer difference. Variables of this type are suitable
434 **      for storing a pointer or pointer subtraction.
435 ************************************************************************/
436 typedef ptrdiff_t PRPtrdiff;
437
438 /************************************************************************
439 ** TYPES:       PRUptrdiff
440 ** DESCRIPTION:
441 **  A type for pointer difference. Variables of this type are suitable
442 **      for storing a pointer or pointer sutraction.
443 ************************************************************************/
444 typedef unsigned long PRUptrdiff;
445
446 /************************************************************************
447 ** TYPES:       PRBool
448 ** DESCRIPTION:
449 **  Use PRBool for variables and parameter types. Use PR_FALSE and PR_TRUE
450 **      for clarity of target type in assignments and actual arguments. Use
451 **      'if (bool)', 'while (!bool)', '(bool) ? x : y' etc., to test booleans
452 **      just as you would C int-valued conditions.
453 ************************************************************************/
454 typedef PRIntn PRBool;
455 #define PR_TRUE 1
456 #define PR_FALSE 0
457
458 /************************************************************************
459 ** TYPES:       PRPackedBool
460 ** DESCRIPTION:
461 **  Use PRPackedBool within structs where bitfields are not desirable
462 **      but minimum and consistant overhead matters.
463 ************************************************************************/
464 typedef PRUint8 PRPackedBool;
465
466 /*
467 ** Status code used by some routines that have a single point of failure or
468 ** special status return.
469 */
470 typedef enum { PR_FAILURE = -1, PR_SUCCESS = 0 } PRStatus;
471
472 #ifdef MOZ_UNICODE
473 /*
474  * EXPERIMENTAL: This type may be removed in a future release.
475  */
476 #ifndef __PRUNICHAR__
477 #define __PRUNICHAR__
478 #if defined(WIN32) || defined(XP_MAC)
479 typedef wchar_t PRUnichar;
480 #else
481 typedef PRUint16 PRUnichar;
482 #endif
483 #endif
484 #endif /* MOZ_UNICODE */
485
486 /*
487 ** WARNING: The undocumented data types PRWord and PRUword are
488 ** only used in the garbage collection and arena code.  Do not
489 ** use PRWord and PRUword in new code.
490 **
491 ** A PRWord is an integer that is the same size as a void*.
492 ** It implements the notion of a "word" in the Java Virtual
493 ** Machine.  (See Sec. 3.4 "Words", The Java Virtual Machine
494 ** Specification, Addison-Wesley, September 1996.
495 ** http://java.sun.com/docs/books/vmspec/index.html.)
496 */
497 typedef long PRWord;
498 typedef unsigned long PRUword;
499
500 #if defined(NO_NSPR_10_SUPPORT)
501 #else
502 /********* ???????????????? FIX ME       ??????????????????????????? *****/
503 /********************** Some old definitions until pr=>ds transition is done ***/
504 /********************** Also, we are still using NSPR 1.0. GC ******************/
505 /*
506 ** Fundamental NSPR macros, used nearly everywhere.
507 */
508
509 #define PR_PUBLIC_API           PR_IMPLEMENT
510
511 /*
512 ** Macro body brackets so that macros with compound statement definitions
513 ** behave syntactically more like functions when called.
514 */
515 #define NSPR_BEGIN_MACRO        do {
516 #define NSPR_END_MACRO          } while (0)
517
518 /*
519 ** Macro shorthands for conditional C++ extern block delimiters.
520 */
521 #ifdef NSPR_BEGIN_EXTERN_C
522 #undef NSPR_BEGIN_EXTERN_C
523 #endif
524 #ifdef NSPR_END_EXTERN_C
525 #undef NSPR_END_EXTERN_C
526 #endif
527
528 #ifdef __cplusplus
529 #define NSPR_BEGIN_EXTERN_C     extern "C" {
530 #define NSPR_END_EXTERN_C       }
531 #else
532 #define NSPR_BEGIN_EXTERN_C
533 #define NSPR_END_EXTERN_C
534 #endif
535
536 #ifdef XP_MAC
537 #include "protypes.h"
538 #else
539 #include "obsolete/protypes.h"
540 #endif
541
542 /********* ????????????? End Fix me ?????????????????????????????? *****/
543 #endif /* NO_NSPR_10_SUPPORT */
544
545 PR_END_EXTERN_C
546
547 #endif /* prtypes_h___ */
548
Note: See TracBrowser for help on using the browser.