home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / sharewar / dos / program / gs300sr1 / gs300sr1.exe / STDPRE.H < prev    next >
C/C++ Source or Header  |  1994-08-01  |  11KB  |  295 lines

  1. /* Copyright (C) 1993, 1994 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* stdpre.h */
  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.  *    Borland Turbo C and Turbo C++ define __MSDOS__ and __TURBOC__.
  29.  *    Borland C++ defines __BORLANDC__, __MSDOS__, and __TURBOC__.
  30.  *    Microsoft C/C++ defines _MSC_VER and _MSDOS.
  31.  *    Watcom C defines __WATCOMC__ and MSDOS.
  32.  *
  33.  * We arrange to define __MSDOS__ on all the MS-DOS platforms.
  34.  */
  35. #if (defined(MSDOS) || defined(_MSDOS)) && !defined(__MSDOS__)
  36. #  define __MSDOS__
  37. #endif
  38. /*
  39.  * Also, not used much here, but used in other header files, we assume:
  40.  *    Unix System V environments define SYSV.
  41.  *    The SCO ODT compiler defines M_SYSV and M_SYS3.
  42.  *    VMS systems define VMS.
  43.  *    OSF/1 compilers define __osf__ or __OSF__.
  44.  *      (The VMS and OSF/1 C compilers handle prototypes and const,
  45.  *      but do not define __STDC__.)
  46.  *    bsd 4.2 or 4.3 systems define BSD4_2.
  47.  *    POSIX-compliant environments define _POSIX_SOURCE.
  48.  *    Motorola 88K BCS/OCS systems defined m88k.
  49.  *
  50.  * We make fairly heroic efforts to confine all uses of these flags to
  51.  * header files, and never to use them in code.
  52.  */
  53. #if defined(__osf__) && !defined(__OSF__)
  54. #  define __OSF__ /* */
  55. #endif
  56. #if defined(M_SYSV) && !defined(SYSV)
  57. #  define SYSV /* */
  58. #endif
  59. #if defined(M_SYS3) && !defined(__SVR3)
  60. #  define __SVR3 /* */
  61. #endif
  62.  
  63. #if defined(__STDC__) || defined(__MSDOS__) || defined(__convex__) || defined(VMS) || defined(__OSF__) || defined(__WIN32__) || defined(__IBMC__)
  64. # if defined(M_UNIX) || defined(__GNUC__) || defined(__BORLANDC__) || defined(__IBMC__) || !defined(M_XENIX) /* SCO Xenix cc is broken */
  65. #  define __PROTOTYPES__ /* */
  66. # endif
  67. #endif
  68.  
  69. /* Define dummy values for __FILE__ and __LINE__ if the compiler */
  70. /* doesn't provide these.  Note that places that use __FILE__ */
  71. /* must check explicitly for a null pointer. */
  72. #ifndef __FILE__
  73. #  define __FILE__ NULL
  74. #endif
  75. #ifndef __LINE__
  76. #  define __LINE__ 0
  77. #endif
  78.  
  79. /* Disable 'const' and 'volatile' if the compiler can't handle them. */
  80. #ifndef __PROTOTYPES__
  81. #  undef const
  82. #  define const    /* */
  83. #  undef volatile
  84. #  define volatile /* */
  85. #endif
  86.  
  87. /*
  88.  * The SVR4.2 C compiler incorrectly considers the result of << and >>
  89.  * to be unsigned if the left operand is signed and the right operand is
  90.  * unsigned.  We believe this only causes trouble in Ghostscript code when
  91.  * the right operand is a sizeof(...), which is unsigned for this compiler.
  92.  * Therefore, we replace the relevant uses of sizeof with size_of:
  93.  */
  94. #define size_of(x) ((int)(sizeof(x)))
  95.  
  96. /* Disable MS-DOS specialized pointer types on non-MS-DOS systems. */
  97. /* Watcom C defines near, far, and huge as macros, so we must undef them. */
  98. /* far_data is used for static data that must get its own segment. */
  99. /* This is supported in Borland C++, but none of the others. */
  100. #undef far_data
  101. #if defined(__TURBOC__) && !defined(__WIN32__)
  102. #  ifdef __BORLANDC__
  103. #    define far_data far
  104. #  else
  105. #    define far_data /* */
  106. #  endif
  107. #else
  108. #  undef near
  109. #  define near /* */
  110. #  undef far
  111. #  define far /* */
  112. #  define far_data /* */
  113. #  undef huge
  114. #  define huge /* */
  115. #  define _cs /* */
  116. #  define _ds /* */
  117. /* _es is never safe to use */
  118. #  define _ss /* */
  119. #endif
  120.  
  121. /* Get the size of a statically declared array. */
  122. #define countof(a) (sizeof(a) / sizeof((a)[0]))
  123. #define count_of(a) (size_of(a) / size_of((a)[0]))
  124.  
  125. /* Get the offset of a structure member. */
  126. /* Amazingly enough, this appears to work on all compilers */
  127. /* (except for one broken MIPS compiler). */
  128. #define offset_of(type, memb) ((int) &((type *) 0)->memb)
  129.  
  130. /* Define a Boolean type.  Even though we would like it to be */
  131. /* unsigned char, it pretty well has to be int, because */
  132. /* that's what all the relational operators and && and || produce. */
  133. /* We can't make it an enumerated type, because ints don't coerce */
  134. /* freely to enums (although the opposite is true). */
  135. typedef int bool;
  136. #define false ((bool)0)
  137. #define true ((bool)1)
  138.  
  139. /* Define short names for the unsigned types. */
  140. typedef unsigned char byte;
  141. typedef unsigned char uchar;
  142. typedef unsigned short ushort;
  143. typedef unsigned int uint;
  144. typedef unsigned long ulong;
  145.  
  146. /* Since sys/types.h often defines one or more of these (depending on */
  147. /* the platform), we have to take steps to prevent name clashes. */
  148. /*** NOTE: This requires that you include std.h *before* any other ***/
  149. /*** header file that includes sys/types.h. ***/
  150. #define bool bool_        /* (maybe not needed) */
  151. #define uchar uchar_
  152. #define uint uint_
  153. #define ushort ushort_
  154. #define ulong ulong_
  155. #include <sys/types.h>
  156. #undef bool
  157. #undef uchar
  158. #undef uint
  159. #undef ushort
  160. #undef ulong
  161.  
  162. /*
  163.  * Define the type to be used for ordering pointers (<, >=, etc.).
  164.  * The Borland and Microsoft large models only compare the offset part
  165.  * of segmented pointers.  Semantically, the right type to use for the
  166.  * comparison is char huge *, but we have no idea how expensive comparing
  167.  * such pointers is, and any type that compares all the bits of the pointer,
  168.  * gives the right result for pointers in the same segment, and keeps
  169.  * different segments disjoint will do.
  170.  */
  171. #if defined(__TURBOC__) || defined(_MSC_VER)
  172. typedef unsigned long ptr_ord_t;
  173. #else
  174. typedef char *ptr_ord_t;
  175. #endif
  176. /* Define all the pointer comparison operations. */
  177. #define _ptr_cmp(p1, rel, p2)  ((ptr_ord_t)(p1) rel (ptr_ord_t)(p2))
  178. #define ptr_le(p1, p2) _ptr_cmp(p1, <=, p2)
  179. #define ptr_lt(p1, p2) _ptr_cmp(p1, <, p2)
  180. #define ptr_ge(p1, p2) _ptr_cmp(p1, >=, p2)
  181. #define ptr_gt(p1, p2) _ptr_cmp(p1, >, p2)
  182. #define ptr_between(ptr, lo, hi)\
  183.   (ptr_ge(ptr, lo) && ptr_lt(ptr, hi))
  184.  
  185. /* Define max and min, but make sure to use the identical definition */
  186. /* to the one that all the compilers seem to have.... */
  187. #ifndef min
  188. #  define min(a, b) (((a) < (b)) ? (a) : (b))
  189. #endif
  190. #ifndef max
  191. #  define max(a, b) (((a) > (b)) ? (a) : (b))
  192. #endif
  193.  
  194. /* Define a standard way to round values to a (constant) modulus. */
  195. #define round_down(value, modulus)\
  196.   ( (modulus) & ((modulus) - 1) ?    /* not a power of 2 */\
  197.     (value) - (value) % (modulus) :\
  198.     (value) & -(modulus) )
  199. #define round_up(value, modulus)\
  200.   ( (modulus) & ((modulus) - 1) ?    /* not a power of 2 */\
  201.     ((value) + ((modulus) - 1)) / (modulus) * (modulus) :\
  202.     ((value) + ((modulus) - 1)) & -(modulus) )
  203.  
  204. /*
  205.  * In pre-ANSI C, float parameters get converted to double.
  206.  * However, if we pass a float to a function that has been declared
  207.  * with a prototype, and the parameter has been declared as float,
  208.  * the ANSI standard specifies that the parameter is left as float.
  209.  * To avoid problems caused by missing prototypes,
  210.  * we declare almost all float parameters as double.
  211.  */
  212. typedef double floatp;
  213.  
  214. /*
  215.  * Define a handy macro for a statement that does nothing.
  216.  * We can't just use an empty body, since this upsets some compilers.
  217.  * We can't use the obvious
  218.  *    if (0)
  219.  * since that could "capture" a following statement if used incorrectly.
  220.  */
  221. #ifndef DO_NOTHING
  222. #  define DO_NOTHING do {} while (0)
  223. #endif
  224.  
  225. /*
  226.  * For accountability, debugging, and error messages,
  227.  * we pass a client identification string to alloc and free,
  228.  * and possibly other places as well.
  229.  * Define the type for these strings.  Note that because of the _ds,
  230.  * we must coerce them explicitly when passing them to printf et al.
  231.  */
  232. typedef const char _ds *client_name_t;
  233. #define client_name_string(cname) ((const char *)(cname))
  234.  
  235. /* If we are debugging, make all static variables and procedures public */
  236. /* so they get passed through the linker. */
  237. #define public /* */
  238. /* We separate out the definition of private this way so that */
  239. /* we can temporarily #undef it to handle the X Windows headers, */
  240. /* which define a member named private. */
  241. #ifdef NOPRIVATE
  242. # define private_ /* */
  243. #else
  244. # define private_ static
  245. #endif
  246. #define private private_
  247.  
  248. /*
  249.  * Macros for argument templates.  ANSI C has these, as does Turbo C,
  250.  * but older pcc-derived (K&R) Unix compilers don't.  The syntax is
  251.  *    resulttype func(Pn(arg1, ..., argn));
  252.  */
  253.  
  254. #ifdef __PROTOTYPES__
  255. # define P0() void
  256. # define P1(t1) t1
  257. # define P2(t1,t2) t1,t2
  258. # define P3(t1,t2,t3) t1,t2,t3
  259. # define P4(t1,t2,t3,t4) t1,t2,t3,t4
  260. # define P5(t1,t2,t3,t4,t5) t1,t2,t3,t4,t5
  261. # define P6(t1,t2,t3,t4,t5,t6) t1,t2,t3,t4,t5,t6
  262. # define P7(t1,t2,t3,t4,t5,t6,t7) t1,t2,t3,t4,t5,t6,t7
  263. # define P8(t1,t2,t3,t4,t5,t6,t7,t8) t1,t2,t3,t4,t5,t6,t7,t8
  264. # define P9(t1,t2,t3,t4,t5,t6,t7,t8,t9) t1,t2,t3,t4,t5,t6,t7,t8,t9
  265. # define P10(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10) t1,t2,t3,t4,t5,t6,t7,t8,t9,t10
  266. # define P11(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11) t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11
  267. # 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
  268. #else
  269. # define P0() /* */
  270. # define P1(t1)    /* */
  271. # define P2(t1,t2) /* */
  272. # define P3(t1,t2,t3) /* */
  273. # define P4(t1,t2,t3,t4) /* */
  274. # define P5(t1,t2,t3,t4,t5) /* */
  275. # define P6(t1,t2,t3,t4,t5,t6) /* */
  276. # define P7(t1,t2,t3,t4,t5,t6,t7) /* */
  277. # define P8(t1,t2,t3,t4,t5,t6,t7,t8) /* */
  278. # define P9(t1,t2,t3,t4,t5,t6,t7,t8,t9)    /* */
  279. # define P10(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10) /* */
  280. # define P11(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11) /* */
  281. # define P12(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12) /* */
  282. #endif
  283.  
  284. /* Define success and failure codes for 'exit'. */
  285. #ifdef VMS
  286. extern void exit(P1(int));
  287. #  define exit_OK 1
  288. #  define exit_FAILED 18
  289. #else
  290. #  define exit_OK 0
  291. #  define exit_FAILED 1
  292. #endif
  293.  
  294. #endif                    /* stdpre_INCLUDED */
  295.