home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / g / gs252src.zip / GS252 / STD.H < prev    next >
C/C++ Source or Header  |  1992-09-19  |  13KB  |  325 lines

  1. /* Copyright (C) 1989, 1992 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* std.h */
  21. /* Standard definitions for Aladdin Enterprises code */
  22.  
  23. #ifndef std_INCLUDED
  24. #  define std_INCLUDED
  25.  
  26. /* Include the architecture definitions. */
  27. #include "arch.h"
  28. #define arch_ints_are_short (arch_sizeof_int == arch_sizeof_short)
  29.  
  30. /*
  31.  * Here we deal with the vagaries of various C compilers.  We assume that:
  32.  *    ANSI-standard Unix compilers define __STDC__.
  33.  *    Turbo C and Turbo C++ define __MSDOS__ and __TURBOC__.
  34.  *    Borland C++ defines __BORLANDC__, __MSDOS__, and __TURBOC__.
  35.  *    Microsoft C defines MSDOS.
  36.  *    Watcom C defines __WATCOMC__ and MSDOS.
  37.  * We arrange to define __MSDOS__ on all the MS-DOS platforms.
  38.  * Also, not used much here, but used in other header files, we assume:
  39.  *    Unix System V environments define USG or SYSV.
  40.  *      (GNU software uses the former, non-GNU tends to use the latter.)
  41.  *    VMS systems define VMS.
  42.  *      (The VMS C compiler handles prototypes and const, but does not
  43.  *      define __STDC__.)
  44.  *    bsd 4.2 or 4.3 systems define BSD4_2.
  45.  *    POSIX-compliant environments define _POSIX_SOURCE.
  46.  *    Motorola 88K BCS/OCS systems defined m88k.
  47.  *
  48.  * We make fairly heroic efforts to confine all uses of these flags to
  49.  * header files, and never to use them in code.
  50.  */
  51.  
  52. #if defined(__STDC__) || defined(__MSDOS__) || defined(__convex__) || defined(VMS)
  53. #  define __PROTOTYPES__ /* */
  54. #endif
  55.  
  56. /* Recognize USG and SYSV as synonyms.  GNU software uses the former, */
  57. /* non-GNU tends to use the latter.  We use the latter. */
  58. #ifdef USG
  59. #  define SYSV /* */
  60. #endif
  61.  
  62. /* Define dummy values for __FILE__ and __LINE__ if the compiler */
  63. /* doesn't provide these.  Note that places that use __FILE__ */
  64. /* must check explicitly for a null pointer. */
  65. #ifndef __FILE__
  66. #  define __FILE__ NULL
  67. #endif
  68. #ifndef __LINE__
  69. #  define __LINE__ 0
  70. #endif
  71.  
  72. /* Disable 'const' and 'volatile' if the compiler can't handle them. */
  73. #ifndef __PROTOTYPES__
  74. #  undef const
  75. #  define const /* */
  76. #  undef volatile
  77. #  define volatile /* */
  78. #endif
  79.  
  80. /* Disable MS-DOS specialized pointer types on non-MS-DOS systems. */
  81. /* Watcom C defines near, far, and huge as macros, so we must undef them. */
  82. #ifndef __TURBOC__
  83. #  undef near
  84. #  define near /* */
  85. #  undef far
  86. #  define far /* */
  87. #  undef huge
  88. #  define huge /* */
  89. #  define _cs /* */
  90. #  define _ds /* */
  91. /* _es is never safe to use */
  92. #  define _ss /* */
  93. #endif
  94.  
  95. /* Define a couple of useful language extensions. */
  96. /* Get the size of a statically declared array. */
  97. #define countof(a) (sizeof(a) / sizeof((a)[0]))
  98.  
  99. /* Define short names for the unsigned types. */
  100. typedef unsigned char byte;
  101. typedef unsigned char uchar;
  102. typedef unsigned short ushort;
  103. typedef unsigned int uint;
  104. typedef unsigned long ulong;
  105.  
  106. /* Since sys/types.h often defines one or more of these (depending on */
  107. /* the platform), we have to take steps to prevent name clashes. */
  108. /*** NOTE: This requires that you include std.h *before* any other ***/
  109. /*** header file that includes sys/types.h. ***/
  110. #define uchar uchar_
  111. #define uint uint_
  112. #define ushort ushort_
  113. #define ulong ulong_
  114. #include <sys/types.h>
  115. #undef uchar
  116. #undef uint
  117. #undef ushort
  118. #undef ulong
  119.  
  120. /* Maximum values for the unsigned types. */
  121. /* The "+0" is to get around apparent bugs in the UTek compiler. */
  122. #define max_uchar ((uchar)0xff + (uchar)0)
  123. #define max_ushort ((ushort)0xffff + (ushort)0)
  124. #define max_uint ((uint)0xffffffff + (uint)0)
  125. #define max_ulong ((ulong)0xffffffffL + (ulong)0)
  126.  
  127. /* Define a reliable arithmetic right shift. */
  128. /* Must use arith_rshift_1 for a shift by a literal 1. */
  129. #define arith_rshift_slow(x,n) ((x) < 0 ? ~(~(x) >> (n)) : (x) >> (n))
  130. #if arch_arith_rshift == 2
  131. #  define arith_rshift(x,n) ((x) >> (n))
  132. #  define arith_rshift_1(x) ((x) >> 1)
  133. #else
  134. #if arch_arith_rshift == 1        /* OK except for n=1 */
  135. #  define arith_rshift(x,n) ((x) >> (n))
  136. #  define arith_rshift_1(x) arith_rshift_slow(x,1)
  137. #else
  138. #  define arith_rshift(x,n) arith_rshift_slow(x,n)
  139. #  define arith_rshift_1(x) arith_rshift_slow(x,1)
  140. #endif
  141. #endif
  142.  
  143. /* The type to be used for comparing pointers for order (<, >=, etc.). */
  144. /* Turbo C large model doesn't compare pointers per se correctly. */
  145. #ifdef __MSDOS__
  146. typedef unsigned long ptr_ord_t;
  147. #else
  148. typedef char *ptr_ord_t;
  149. #endif
  150. /* Define all the pointer comparison operations. */
  151. #define _ptr_cmp(p1, rel, p2)  ((ptr_ord_t)(p1) rel (ptr_ord_t)(p2))
  152. #define ptr_le(p1, p2) _ptr_cmp(p1, <=, p2)
  153. #define ptr_lt(p1, p2) _ptr_cmp(p1, <, p2)
  154. #define ptr_ge(p1, p2) _ptr_cmp(p1, >=, p2)
  155. #define ptr_gt(p1, p2) _ptr_cmp(p1, >, p2)
  156. #define ptr_between(ptr, lo, hi)\
  157.   (ptr_ge(ptr, lo) && ptr_lt(ptr, hi))
  158.  
  159. /* In case stdio.h doesn't have these: */
  160. #ifndef min
  161. #  define min(a, b) ((a) < (b) ? (a) : (b))
  162. #endif
  163. #ifndef max
  164. #  define max(a, b) ((a) > (b) ? (a) : (b))
  165. #endif
  166.  
  167. /* VMS doesn't have the unlink system call.  Use delete instead. */
  168. #ifdef VMS
  169. #  define unlink(fname) delete(fname)
  170. #endif
  171.  
  172. /* K&R specifies that float parameters get converted to double. */
  173. /* However, if we pass a float to a function that has been declared */
  174. /* with a prototype, and the parameter has been declared as float, */
  175. /* the ANSI standard specifies that the parameter is left as float. */
  176. /* To avoid problems when mixing ANSI and non-ANSI compilation, */
  177. /* we declare all float parameters as double. */
  178. typedef double floatp;
  179.  
  180. /* If we are debugging, make all static variables and procedures public */
  181. /* so they get passed through the linker. */
  182. #ifdef NOPRIVATE
  183. # define private /* */
  184. #else
  185. # define private static
  186. #endif
  187.  
  188. /*
  189.  * Macros for argument templates.  ANSI C has these, as does Turbo C,
  190.  * but older pcc-derived (K&R) Unix compilers don't.  The syntax is
  191.  *    resulttype func(Pn(arg1, ..., argn));
  192.  */
  193.  
  194. #ifdef __PROTOTYPES__
  195. # define P0() void
  196. # define P1(t1) t1
  197. # define P2(t1,t2) t1,t2
  198. # define P3(t1,t2,t3) t1,t2,t3
  199. # define P4(t1,t2,t3,t4) t1,t2,t3,t4
  200. # define P5(t1,t2,t3,t4,t5) t1,t2,t3,t4,t5
  201. # define P6(t1,t2,t3,t4,t5,t6) t1,t2,t3,t4,t5,t6
  202. # define P7(t1,t2,t3,t4,t5,t6,t7) t1,t2,t3,t4,t5,t6,t7
  203. # define P8(t1,t2,t3,t4,t5,t6,t7,t8) t1,t2,t3,t4,t5,t6,t7,t8
  204. # define P9(t1,t2,t3,t4,t5,t6,t7,t8,t9) t1,t2,t3,t4,t5,t6,t7,t8,t9
  205. # define P10(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10) t1,t2,t3,t4,t5,t6,t7,t8,t9,t10
  206. # define P11(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11) t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11
  207. # 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
  208. #else
  209. # define P0() /* */
  210. # define P1(t1) /* */
  211. # define P2(t1,t2) /* */
  212. # define P3(t1,t2,t3) /* */
  213. # define P4(t1,t2,t3,t4) /* */
  214. # define P5(t1,t2,t3,t4,t5) /* */
  215. # define P6(t1,t2,t3,t4,t5,t6) /* */
  216. # define P7(t1,t2,t3,t4,t5,t6,t7) /* */
  217. # define P8(t1,t2,t3,t4,t5,t6,t7,t8) /* */
  218. # define P9(t1,t2,t3,t4,t5,t6,t7,t8,t9) /* */
  219. # define P10(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10) /* */
  220. # define P11(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11) /* */
  221. # define P12(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12) /* */
  222. #endif
  223.  
  224. /* Types for client-supplied allocate and free procedures. */
  225. /* For accountability, debugging, and error messages, */
  226. /* we pass an identifying string to alloc and free. */
  227. /* Note that the arguments are like calloc, not like malloc, */
  228. /* but an alloc procedure doesn't clear the block. */
  229. typedef char *(*proc_alloc_t)(P3(unsigned num_elements, unsigned element_size, const char *client_name));
  230. typedef void (*proc_free_t)(P4(char *data, unsigned num_elements, unsigned element_size, const char *client_name));
  231.  
  232. /* Standard error printing macros. */
  233. /* Use dprintf for messages that just go to dstderr, */
  234. /* eprintf for error messages to estderr that include the program name, */
  235. /* lprintf for debugging messages that should include line number info. */
  236.  
  237. /* dstderr and estderr may be redefined. */
  238. #define dstderr stderr
  239. #define estderr stderr
  240.  
  241. #define dputc(chr) fputc(chr, dstderr)
  242. #define dputs(str) fputs(str, dstderr)
  243. #define dprintf(str)\
  244.   fprintf(dstderr, str)
  245. #define dprintf1(str,arg1)\
  246.   fprintf(dstderr, str, arg1)
  247. #define dprintf2(str,arg1,arg2)\
  248.   fprintf(dstderr, str, arg1, arg2)
  249. #define dprintf3(str,arg1,arg2,arg3)\
  250.   fprintf(dstderr, str, arg1, arg2, arg3)
  251. #define dprintf4(str,arg1,arg2,arg3,arg4)\
  252.   fprintf(dstderr, str, arg1, arg2, arg3, arg4)
  253. #define dprintf5(str,arg1,arg2,arg3,arg4,arg5)\
  254.   fprintf(dstderr, str, arg1, arg2, arg3, arg4, arg5)
  255. #define dprintf6(str,arg1,arg2,arg3,arg4,arg5,arg6)\
  256.   fprintf(dstderr, str, arg1, arg2, arg3, arg4, arg5, arg6)
  257. #define dprintf7(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7)\
  258.   fprintf(dstderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
  259. #define dprintf8(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)\
  260.   fprintf(dstderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
  261. #define dprintf9(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)\
  262.   fprintf(dstderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
  263. #define dprintf10(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)\
  264.   fprintf(dstderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10)
  265.  
  266. #ifdef PROGRAM_NAME
  267. #  define _epn fprintf(estderr, "%s: ", PROGRAM_NAME),
  268. #else
  269. #  define _epn /* */
  270. #endif
  271.  
  272. #define eprintf(str)\
  273.   (_epn fprintf(estderr, str))
  274. #define eprintf1(str,arg1)\
  275.   (_epn fprintf(estderr, str, arg1))
  276. #define eprintf2(str,arg1,arg2)\
  277.   (_epn fprintf(estderr, str, arg1, arg2))
  278. #define eprintf3(str,arg1,arg2,arg3)\
  279.   (_epn fprintf(estderr, str, arg1, arg2, arg3))
  280. #define eprintf4(str,arg1,arg2,arg3,arg4)\
  281.   (_epn fprintf(estderr, str, arg1, arg2, arg3, arg4))
  282. #define eprintf5(str,arg1,arg2,arg3,arg4,arg5)\
  283.   (_epn fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5))
  284. #define eprintf6(str,arg1,arg2,arg3,arg4,arg5,arg6)\
  285.   (_epn fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6))
  286. #define eprintf7(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7)\
  287.   (_epn fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7))
  288. #define eprintf8(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)\
  289.   (_epn fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8))
  290. #define eprintf9(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)\
  291.   (_epn fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9))
  292. #define eprintf10(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)\
  293.   (_epn fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10))
  294.  
  295. #if __LINE__                /* compiler provides it */
  296. #  define _epl _epn fprintf(estderr, "%s(%d): ", __FILE__, __LINE__),
  297. #else
  298. #  define _epl _epn
  299. #endif
  300.  
  301. #define lprintf(str)\
  302.   (_epl fprintf(estderr, str))
  303. #define lprintf1(str,arg1)\
  304.   (_epl fprintf(estderr, str, arg1))
  305. #define lprintf2(str,arg1,arg2)\
  306.   (_epl fprintf(estderr, str, arg1, arg2))
  307. #define lprintf3(str,arg1,arg2,arg3)\
  308.   (_epl fprintf(estderr, str, arg1, arg2, arg3))
  309. #define lprintf4(str,arg1,arg2,arg3,arg4)\
  310.   (_epl fprintf(estderr, str, arg1, arg2, arg3, arg4))
  311. #define lprintf5(str,arg1,arg2,arg3,arg4,arg5)\
  312.   (_epl fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5))
  313. #define lprintf6(str,arg1,arg2,arg3,arg4,arg5,arg6)\
  314.   (_epl fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6))
  315. #define lprintf7(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7)\
  316.   (_epl fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7))
  317. #define lprintf8(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)\
  318.   (_epl fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8))
  319. #define lprintf9(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)\
  320.   (_epl fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9))
  321. #define lprintf10(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)\
  322.   (_epl fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10))
  323.  
  324. #endif                    /* std_INCLUDED */
  325.