home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / stdpre.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  15.1 KB  |  432 lines

  1. /* Copyright (C) 1993, 1994, 1996, 1997, 1998, 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: stdpre.h,v 1.2 2000/09/19 19:00:51 lpd Exp $ */
  20. /* Standard definitions for Aladdin Enterprises code not needing arch.h */
  21.  
  22. #ifndef stdpre_INCLUDED
  23. #  define stdpre_INCLUDED
  24.  
  25. /*
  26.  * Here we deal with the vagaries of various C compilers.  We assume that:
  27.  *      ANSI-standard Unix compilers define __STDC__.
  28.  *      gcc defines __GNUC__.
  29.  *      Borland Turbo C and Turbo C++ define __MSDOS__ and __TURBOC__.
  30.  *      Borland C++ defines __BORLANDC__, __MSDOS__, and __TURBOC__.
  31.  *      Microsoft C/C++ defines _MSC_VER and _MSDOS.
  32.  *      Watcom C defines __WATCOMC__ and MSDOS.
  33.  *      MetroWerks C defines __MWERKS__.
  34.  *
  35.  * We arrange to define __MSDOS__ on all the MS-DOS platforms.
  36.  */
  37. #if (defined(MSDOS) || defined(_MSDOS)) && !defined(__MSDOS__)
  38. #  define __MSDOS__
  39. #endif
  40. /*
  41.  * Also, not used much here, but used in other header files, we assume:
  42.  *      Unix System V environments define SYSV.
  43.  *      The SCO ODT compiler defines M_SYSV and M_SYS3.
  44.  *      VMS systems define VMS.
  45.  *      OSF/1 compilers define __osf__ or __OSF__.
  46.  *        (The VMS and OSF/1 C compilers handle prototypes and const,
  47.  *        but do not define __STDC__.)
  48.  *      bsd 4.2 or 4.3 systems define BSD4_2.
  49.  *      POSIX-compliant environments define _POSIX_SOURCE.
  50.  *      Motorola 88K BCS/OCS systems defined m88k.
  51.  *
  52.  * We make fairly heroic efforts to confine all uses of these flags to
  53.  * header files, and never to use them in code.
  54.  */
  55. #if defined(__osf__) && !defined(__OSF__)
  56. #  define __OSF__        /* */
  57. #endif
  58. #if defined(M_SYSV) && !defined(SYSV)
  59. #  define SYSV            /* */
  60. #endif
  61. #if defined(M_SYS3) && !defined(__SVR3)
  62. #  define __SVR3        /* */
  63. #endif
  64.  
  65. #if defined(__STDC__) || defined(__MSDOS__) || defined(__convex__) || defined(VMS) || defined(__OSF__) || defined(__WIN32__) || defined(__IBMC__) || defined(M_UNIX) || defined(__GNUC__) || defined(__BORLANDC__)
  66. # if !(defined(M_XENIX) && !defined(__GNUC__))    /* SCO Xenix cc is broken */
  67. #  define __PROTOTYPES__    /* */
  68. # endif
  69. #endif
  70.  
  71. /* Define dummy values for __FILE__ and __LINE__ if the compiler */
  72. /* doesn't provide these.  Note that places that use __FILE__ */
  73. /* must check explicitly for a null pointer. */
  74. #ifndef __FILE__
  75. #  define __FILE__ NULL
  76. #endif
  77. #ifndef __LINE__
  78. #  define __LINE__ 0
  79. #endif
  80.  
  81. /* Disable 'const' and 'volatile' if the compiler can't handle them. */
  82. #ifndef __PROTOTYPES__
  83. #  undef const
  84. #  define const            /* */
  85. #  undef volatile
  86. #  define volatile        /* */
  87. #endif
  88.  
  89. /* Disable 'inline' if the compiler can't handle it. */
  90. #ifdef __DECC
  91. #  undef inline
  92. #  define inline __inline
  93. #else
  94. #  ifdef __GNUC__
  95. /* Define inline as __inline__ so -pedantic won't produce a warning. */
  96. #    undef inline
  97. #    define inline __inline__
  98. #  else
  99. #    if !(defined(__MWERKS__) || defined(inline))
  100. #      define inline        /* */
  101. #    endif
  102. #  endif
  103. #endif
  104.  
  105. /*
  106.  * Some compilers give a warning if a function call that returns a value
  107.  * is used as a statement; a few compilers give an error for the construct
  108.  * (void)0, which is contrary to the ANSI standard.  Since we don't know of
  109.  * any compilers that do both, we define a macro here for discarding
  110.  * the value of an expression statement, which can be defined as either
  111.  * including or not including the cast.  (We don't conditionalize this here,
  112.  * because no commercial compiler gives the error on (void)0, although
  113.  * some give warnings.)
  114.  */
  115. #define DISCARD(expr) ((void)(expr))
  116. /* Backward compatibility */
  117. #define discard(expr) DISCARD(expr)
  118.  
  119. /*
  120.  * Some versions of the Watcom compiler give a "Comparison result always
  121.  * 0/1" message that we want to suppress because it gets in the way of
  122.  * meaningful warnings.
  123.  */
  124. #ifdef __WATCOMC__
  125. #  pragma disable_message(124);
  126. #endif
  127.  
  128. /*
  129.  * Some versions of gcc have a bug such that after
  130.     byte *p;
  131.     ...
  132.     x = *(long *)p;
  133.  * the compiler then thinks that p always points to long-aligned data.
  134.  * Detect this here so it can be handled appropriately in the few places
  135.  * that (we think) matter.
  136.  */
  137. #ifdef __GNUC__
  138. # if __GNUC__ == 2 & (7 < __GNUC_MINOR__ <= 95)
  139. #  define ALIGNMENT_ALIASING_BUG
  140. # endif
  141. #endif
  142.  
  143. /*
  144.  * The SVR4.2 C compiler incorrectly considers the result of << and >>
  145.  * to be unsigned if the left operand is signed and the right operand is
  146.  * unsigned.  We believe this only causes trouble in Ghostscript code when
  147.  * the right operand is a sizeof(...), which is unsigned for this compiler.
  148.  * Therefore, we replace the relevant uses of sizeof with size_of:
  149.  */
  150. #define size_of(x) ((int)(sizeof(x)))
  151.  
  152. /*
  153.  * far_data was formerly used for static data that had to be assigned its
  154.  * own segment on PCs with 64K segments.  This was supported in Borland C++,
  155.  * but none of the other compilers.  Since we no longer support
  156.  * small-segment systems, far_data is vacuous.
  157.  */
  158. #undef far_data
  159. #define far_data /* */
  160.  
  161. /*
  162.  * Get the number of elements of a statically dimensioned array.
  163.  * Note that this also works on array members of structures.
  164.  */
  165. #define countof(a) (sizeof(a) / sizeof((a)[0]))
  166. #define count_of(a) (size_of(a) / size_of((a)[0]))
  167.  
  168. /*
  169.  * Get the offset of a structure member.  Amazingly enough, the simpler
  170.  * definition works on all compilers except for one broken MIPS compiler
  171.  * and the IBM RS/6000.  Unfortunately, because of these two compilers,
  172.  * we have to use the more complex definition.  Even more unfortunately,
  173.  * the more complex definition doesn't work on the MetroWerks
  174.  * CodeWarrior compiler (Macintosh and BeOS).
  175.  */
  176. #ifdef __MWERKS__
  177. #define offset_of(type, memb)\
  178.  ((int) &((type *) 0)->memb)
  179. #else
  180. #define offset_of(type, memb)\
  181.  ((int) ( (char *)&((type *)0)->memb - (char *)((type *)0) ))
  182. #endif
  183.  
  184. /*
  185.  * Get the alignment of a pointer modulo a given power of 2.
  186.  * There is no portable way to do this, but the following definition
  187.  * works on all reasonable systems.
  188.  */
  189. #define ALIGNMENT_MOD(ptr, modu)\
  190.   ((uint)( ((const char *)(ptr) - (const char *)0) & ((modu) - 1) ))
  191.  
  192. /* Define short names for the unsigned types. */
  193. typedef unsigned char byte;
  194. typedef unsigned char uchar;
  195. #ifndef _SYS_TYPES_H_
  196. typedef unsigned short ushort;
  197. typedef unsigned int uint;
  198. #endif
  199. typedef unsigned long ulong;
  200.  
  201. /* Since sys/types.h often defines one or more of these (depending on */
  202. /* the platform), we have to take steps to prevent name clashes. */
  203. /*** NOTE: This requires that you include std.h *before* any other ***/
  204. /*** header file that includes sys/types.h. ***/
  205. #define bool bool_        /* (maybe not needed) */
  206. #define uchar uchar_
  207. #define uint uint_
  208. #define ushort ushort_
  209. #define ulong ulong_
  210. #include <sys/types.h>
  211. #undef bool
  212. #undef uchar
  213. #undef uint
  214. #undef ushort
  215. #undef ulong
  216.  
  217. /*
  218.  * Define a Boolean type.  Even though we would like it to be
  219.  * unsigned char, it pretty well has to be int, because
  220.  * that's what all the relational operators and && and || produce.
  221.  * We can't make it an enumerated type, because ints don't coerce
  222.  * freely to enums (although the opposite is true).
  223.  * Unfortunately, at least some C++ compilers have a built-in bool type,
  224.  * and the MetroWerks C++ compiler insists that bool be equivalent to
  225.  * unsigned char.
  226.  */
  227. #ifndef __cplusplus
  228. #ifdef __BEOS__
  229. typedef unsigned char bool;
  230. #else
  231. typedef int bool;
  232. #endif
  233. #endif
  234. /*
  235.  * MetroWerks CodeWarrior predefines true and false, probably as 1 and 0.
  236.  * We need to cancel those definitions for our own code.
  237.  */
  238. #undef false
  239. #define false ((bool)0)
  240. #undef true
  241. #define true ((bool)1)
  242.  
  243. /*
  244.  * Compilers disagree as to whether macros used in macro arguments
  245.  * should be expanded at the time of the call, or at the time of
  246.  * final expansion.  Even authoritative documents disagree: the ANSI
  247.  * standard says the former, but Harbison and Steele's book says the latter.
  248.  * In order to work around this discrepancy, we have to do some very
  249.  * ugly things in a couple of places.  We mention it here because
  250.  * it might well trip up future developers.
  251.  */
  252.  
  253. /*
  254.  * Define the type to be used for ordering pointers (<, >=, etc.).
  255.  * The Borland and Microsoft large models only compare the offset part
  256.  * of segmented pointers.  Semantically, the right type to use for the
  257.  * comparison is char huge *, but we have no idea how expensive comparing
  258.  * such pointers is, and any type that compares all the bits of the pointer,
  259.  * gives the right result for pointers in the same segment, and keeps
  260.  * different segments disjoint will do.
  261.  */
  262. #if defined(__TURBOC__) || defined(_MSC_VER)
  263. typedef unsigned long ptr_ord_t;
  264. #else
  265. typedef const char *ptr_ord_t;
  266. #endif
  267. /* Define all the pointer comparison operations. */
  268. #define _PTR_CMP(p1, rel, p2)  ((ptr_ord_t)(p1) rel (ptr_ord_t)(p2))
  269. #define PTR_LE(p1, p2) _PTR_CMP(p1, <=, p2)
  270. #define PTR_LT(p1, p2) _PTR_CMP(p1, <, p2)
  271. #define PTR_GE(p1, p2) _PTR_CMP(p1, >=, p2)
  272. #define PTR_GT(p1, p2) _PTR_CMP(p1, >, p2)
  273. #define PTR_BETWEEN(ptr, lo, hi)\
  274.   (PTR_GE(ptr, lo) && PTR_LT(ptr, hi))
  275.  
  276. /* Define  min and max, but make sure to use the identical definition */
  277. /* to the one that all the compilers seem to have.... */
  278. #ifndef min
  279. #  define min(a, b) (((a) < (b)) ? (a) : (b))
  280. #endif
  281. #ifndef max
  282. #  define max(a, b) (((a) > (b)) ? (a) : (b))
  283. #endif
  284.  
  285. /* Define a standard way to round values to a (constant) modulus. */
  286. #define ROUND_DOWN(value, modulus)\
  287.   ( (modulus) & ((modulus) - 1) ?    /* not a power of 2 */\
  288.     (value) - (value) % (modulus) :\
  289.     (value) & -(modulus) )
  290. #define ROUND_UP(value, modulus)\
  291.   ( (modulus) & ((modulus) - 1) ?    /* not a power of 2 */\
  292.     ((value) + ((modulus) - 1)) / (modulus) * (modulus) :\
  293.     ((value) + ((modulus) - 1)) & -(modulus) )
  294. /* Backward compatibility */
  295. #define round_up(v, m) ROUND_UP(v, m)
  296. #define round_down(v, m) ROUND_DOWN(v, m)
  297.  
  298. /*
  299.  * In pre-ANSI C, float parameters get converted to double.
  300.  * However, if we pass a float to a function that has been declared
  301.  * with a prototype, and the parameter has been declared as float,
  302.  * the ANSI standard specifies that the parameter is left as float.
  303.  * To avoid problems caused by missing prototypes,
  304.  * we declare almost all float parameters as double.
  305.  */
  306. typedef double floatp;
  307.  
  308. /*
  309.  * Because of C's strange insistence that ; is a terminator and not a
  310.  * separator, compound statements {...} are not syntactically equivalent to
  311.  * single statements.  Therefore, we define here a compound-statement
  312.  * construct that *is* syntactically equivalent to a single statement.
  313.  * Usage is
  314.  *      BEGIN
  315.  *        ...statements...
  316.  *      END
  317.  */
  318. #define BEGIN    do {
  319. #define END    } while (0)
  320.  
  321. /*
  322.  * Define a handy macro for a statement that does nothing.
  323.  * We can't just use an empty statement, since this upsets some compilers.
  324.  */
  325. #ifndef DO_NOTHING
  326. #  define DO_NOTHING BEGIN END
  327. #endif
  328.  
  329. /*
  330.  * For accountability, debugging, and error messages, we pass a client
  331.  * identification string to alloc and free, and possibly other places as
  332.  * well.  Define the type for these strings.
  333.  */
  334. typedef const char *client_name_t;
  335. /****** WHAT TO DO ABOUT client_name_string ? ******/
  336. #define client_name_string(cname) (cname)
  337.  
  338. /*
  339.  * If we are debugging, make all static variables and procedures public
  340.  * so they get passed through the linker.
  341.  */
  342. #define public            /* */
  343. /*
  344.  * We separate out the definition of private this way so that
  345.  * we can temporarily #undef it to handle the X Windows headers,
  346.  * which define a member named private.
  347.  */
  348. #ifdef NOPRIVATE
  349. # define private_        /* */
  350. #else
  351. # define private_ static
  352. #endif
  353. #define private private_
  354.  
  355. /*
  356.  * Macros for argument templates.  ANSI C has these, as does Turbo C,
  357.  * but older pcc-derived (K&R) Unix compilers don't.  The syntax is
  358.  *      resulttype func(Pn(arg1, ..., argn));
  359.  */
  360.  
  361. #ifdef __PROTOTYPES__
  362. # define P0() void
  363. # define P1(t1) t1
  364. # define P2(t1,t2) t1,t2
  365. # define P3(t1,t2,t3) t1,t2,t3
  366. # define P4(t1,t2,t3,t4) t1,t2,t3,t4
  367. # define P5(t1,t2,t3,t4,t5) t1,t2,t3,t4,t5
  368. # define P6(t1,t2,t3,t4,t5,t6) t1,t2,t3,t4,t5,t6
  369. # define P7(t1,t2,t3,t4,t5,t6,t7) t1,t2,t3,t4,t5,t6,t7
  370. # define P8(t1,t2,t3,t4,t5,t6,t7,t8) t1,t2,t3,t4,t5,t6,t7,t8
  371. # define P9(t1,t2,t3,t4,t5,t6,t7,t8,t9) t1,t2,t3,t4,t5,t6,t7,t8,t9
  372. # define P10(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10) t1,t2,t3,t4,t5,t6,t7,t8,t9,t10
  373. # define P11(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11) t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11
  374. # define P12(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12) t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12
  375. # define P13(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13) t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13
  376. # define P14(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14) t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14
  377. # define P15(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15) t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15
  378. # define P16(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16) t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16
  379. #else
  380. # define P0()            /* */
  381. # define P1(t1)            /* */
  382. # define P2(t1,t2)        /* */
  383. # define P3(t1,t2,t3)        /* */
  384. # define P4(t1,t2,t3,t4)    /* */
  385. # define P5(t1,t2,t3,t4,t5)    /* */
  386. # define P6(t1,t2,t3,t4,t5,t6)    /* */
  387. # define P7(t1,t2,t3,t4,t5,t6,t7)    /* */
  388. # define P8(t1,t2,t3,t4,t5,t6,t7,t8)    /* */
  389. # define P9(t1,t2,t3,t4,t5,t6,t7,t8,t9)        /* */
  390. # define P10(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10)    /* */
  391. # define P11(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11)    /* */
  392. # define P12(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12)    /* */
  393. # define P13(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13)    /* */
  394. # define P14(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14)    /* */
  395. # define P15(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15)    /* */
  396. # define P16(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16)    /* */
  397. #endif
  398.  
  399. /*
  400.  * Define success and failure codes for 'exit'.  The only system on which
  401.  * they are different is VMS with older DEC C versions.  We aren't sure
  402.  * in what version DEC C started being compatible with the rest of the
  403.  * world, and we don't know what the story is with VAX C.  If you have
  404.  * problems, uncomment the following line or add -DOLD_VMS_C to the C
  405.  * command line.
  406.  */
  407. /*#define OLD_VMS_C*/
  408. #if defined(VMS) && (defined(OLD_VMS_C) || !defined(__DECC))
  409. #  define exit_OK 1
  410. #  define exit_FAILED 18
  411. #else
  412. #  define exit_OK 0
  413. #  define exit_FAILED 1
  414. #endif
  415. /*
  416.  * Define the informational exit status.
  417.  * We need to distinguish information returns because under MS Windows,
  418.  * they must return like an error so that the text window stays on the
  419.  * screen, while on other platforms, they must return successfully.
  420.  * Note that we define both gs_exit_INFO (before platform-specific
  421.  * mapping of 0 to exit_OK and 1 to exit_FAILED) and exit_INFO.
  422.  */
  423. #if defined(_WINDOWS) || defined(_Windows)
  424. #  define exit_INFO exit_FAILED
  425. #  define gs_exit_INFO 1
  426. #else
  427. #  define exit_INFO exit_OK
  428. #  define gs_exit_INFO 0
  429. #endif
  430.  
  431. #endif /* stdpre_INCLUDED */
  432.