home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / TEKST / GSPMSRC / SRC / STD.H < prev    next >
C/C++ Source or Header  |  1993-10-25  |  16KB  |  401 lines

  1. /* Copyright (C) 1989, 1992, 1993 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* Modified by J. Yang, 1993 */
  20.  
  21. /* std.h */
  22. /* Standard definitions for Aladdin Enterprises code */
  23.  
  24. #ifndef std_INCLUDED
  25. #  define std_INCLUDED
  26.  
  27. /* Include the architecture definitions. */
  28. #include "arch.h"
  29. #define arch_ints_are_short (arch_sizeof_int == arch_sizeof_short)
  30.  
  31. /*
  32.  * Here we deal with the vagaries of various C compilers.  We assume that:
  33.  *    ANSI-standard Unix compilers define __STDC__.
  34.  *    Borland Turbo C and Turbo C++ define __MSDOS__ and __TURBOC__.
  35.  *    Borland C++ defines __BORLANDC__, __MSDOS__, and __TURBOC__.
  36.  *    Microsoft C/C++ defines _MSC_VER and _MSDOS.
  37.  *    Watcom C defines __WATCOMC__ and MSDOS.
  38.  *
  39.  * We arrange to define __MSDOS__ on all the MS-DOS platforms.
  40.  */
  41. #if (defined(MSDOS) || defined(_MSDOS)) && !defined(__MSDOS__)
  42. #  define __MSDOS__
  43. #endif
  44. /*
  45.  * Also, not used much here, but used in other header files, we assume:
  46.  *    Unix System V environments define USG or SYSV.
  47.  *      (GNU software uses the former, non-GNU tends to use the latter.)
  48.  *    The SCO ODT compiler defines M_SYSV and M_SYS3.
  49.  *    VMS systems define VMS.
  50.  *      (The VMS C compiler handles prototypes and const, but does not
  51.  *      define __STDC__.)
  52.  *    bsd 4.2 or 4.3 systems define BSD4_2.
  53.  *    POSIX-compliant environments define _POSIX_SOURCE.
  54.  *    Motorola 88K BCS/OCS systems defined m88k.
  55.  *    OSF/1 compilers define __osf__ or __OSF__.
  56.  *
  57.  * We make fairly heroic efforts to confine all uses of these flags to
  58.  * header files, and never to use them in code.
  59.  */
  60. #if defined(__osf__) && !defined(__OSF__)
  61. #  define __OSF__ /* */
  62. #endif
  63. #if defined(M_SYSV) && !defined(SYSV)
  64. #  define SYSV /* */
  65. #endif
  66. #if defined(M_SYS3) && !defined(__SVR3)
  67. #  define __SVR3 /* */
  68. #endif
  69.  
  70. #if defined(__OS2__) || defined(__STDC__) || defined(__MSDOS__) || defined(__convex__) || defined(VMS)
  71. # if defined(M_UNIX) || defined(__GNUC__) || !defined(M_XENIX) /* SCO Xenix cc is broken */
  72. #  define __PROTOTYPES__ /* */
  73. # endif
  74. #endif
  75.  
  76. /* Recognize USG and SYSV as synonyms.  GNU software uses the former, */
  77. /* non-GNU tends to use the latter.  We use the latter. */
  78. #ifdef USG
  79. # ifndef SYSV
  80. #  define SYSV /* */
  81. # endif
  82. #endif
  83.  
  84. /* Define dummy values for __FILE__ and __LINE__ if the compiler */
  85. /* doesn't provide these.  Note that places that use __FILE__ */
  86. /* must check explicitly for a null pointer. */
  87. #ifndef __FILE__
  88. #  define __FILE__ NULL
  89. #endif
  90. #ifndef __LINE__
  91. #  define __LINE__ 0
  92. #endif
  93.  
  94. /* Disable 'const' and 'volatile' if the compiler can't handle them. */
  95. #ifndef __PROTOTYPES__
  96. #  undef const
  97. #  define const /* */
  98. #  undef volatile
  99. #  define volatile /* */
  100. #endif
  101.  
  102. /*
  103.  * The SVR4.2 C compiler incorrectly considers the result of << and >>
  104.  * to be unsigned if the left operand is signed and the right operand is
  105.  * unsigned.  We believe this only causes trouble in Ghostscript code when
  106.  * the right operand is a sizeof(...), which is unsigned for this compiler.
  107.  * Therefore, we replace the relevant uses of sizeof with size_of:
  108.  */
  109. #define size_of(x) ((int)(sizeof(x)))
  110.  
  111. /* Disable MS-DOS specialized pointer types on non-MS-DOS systems. */
  112. /* Watcom C defines near, far, and huge as macros, so we must undef them. */
  113. /* far_data is used for static data that must get its own segment. */
  114. /* This is supported in Borland C++, but none of the others. */
  115. #undef far_data
  116. #if defined(__TURBOC__) && !defined(__OS2__) 
  117. #  ifdef __BORLANDC__
  118. #    define far_data far
  119. #  else
  120. #    define far_data /* */
  121. #  endif
  122. #else
  123. #  undef near
  124. #  define near /* */
  125. #  undef far
  126. #  define far /* */
  127. #  define far_data /* */
  128. #  undef huge
  129. #  define huge /* */
  130. #  define _cs /* */
  131. #  define _ds /* */
  132. /* _es is never safe to use */
  133. #  define _ss /* */
  134. #endif
  135.  
  136. /* Define a couple of useful language extensions. */
  137. /* Get the size of a statically declared array. */
  138. #define countof(a) (sizeof(a) / sizeof((a)[0]))
  139. #define count_of(a) (size_of(a) / size_of((a)[0]))
  140. /* Get the offset of a structure member. */
  141. /* Amazingly enough, this appears to work on all compilers */
  142. /* (except for one broken MIPS compiler). */
  143. #define offset_of(type, memb) ((int) &((type *) 0)->memb)
  144.  
  145. /* Define short names for the unsigned types. */
  146. typedef unsigned char byte;
  147. typedef unsigned char uchar;
  148. typedef unsigned short ushort;
  149. typedef unsigned int uint;
  150. typedef unsigned long ulong;
  151.  
  152. /* Since sys/types.h often defines one or more of these (depending on */
  153. /* the platform), we have to take steps to prevent name clashes. */
  154. /*** NOTE: This requires that you include std.h *before* any other ***/
  155. /*** header file that includes sys/types.h. ***/
  156. #define uchar uchar_
  157. #define uint uint_
  158. #define ushort ushort_
  159. #define ulong ulong_
  160. #include <sys/types.h>
  161. #undef uchar
  162. #undef uint
  163. #undef ushort
  164. #undef ulong
  165.  
  166. /* Minimum and maximum values for the signed types. */
  167. #define min_signed(type) (-(type)1 << (size_of(type) * 8 - 1))
  168. #define min_short min_signed(short)
  169. #define max_short (~min_short)
  170. #define min_int min_signed(int)
  171. #define max_int (~min_int)
  172. #define min_long min_signed(long)
  173. #define max_long (~min_long)
  174.  
  175. /*
  176.  * The maximum values for the unsigned types are defined in arch.h,
  177.  * because so many compilers handle unsigned constants wrong.
  178.  * In particular, most of the DEC VMS compilers incorrectly sign-extend
  179.  * short unsigned constants (but not short unsigned variables) when
  180.  * widening them to longs.  We program around this on a case-by-case basis.
  181.  * Some compilers don't truncate constants when they are cast down.
  182.  * The UTek compiler does special weird things of its own.
  183.  * All the rest (including gcc on all platforms) do the right thing.
  184.  */
  185. #define max_uchar arch_max_uchar
  186. #define max_ushort arch_max_ushort
  187. #define max_uint arch_max_uint
  188. #define max_ulong arch_max_ulong
  189.  
  190. /* Define a reliable arithmetic right shift. */
  191. /* Must use arith_rshift_1 for a shift by a literal 1. */
  192. #define arith_rshift_slow(x,n) ((x) < 0 ? ~(~(x) >> (n)) : (x) >> (n))
  193. #if arch_arith_rshift == 2
  194. #  define arith_rshift(x,n) ((x) >> (n))
  195. #  define arith_rshift_1(x) ((x) >> 1)
  196. #else
  197. #if arch_arith_rshift == 1        /* OK except for n=1 */
  198. #  define arith_rshift(x,n) ((x) >> (n))
  199. #  define arith_rshift_1(x) arith_rshift_slow(x,1)
  200. #else
  201. #  define arith_rshift(x,n) arith_rshift_slow(x,n)
  202. #  define arith_rshift_1(x) arith_rshift_slow(x,1)
  203. #endif
  204. #endif
  205.  
  206. /* The type to be used for comparing pointers for order (<, >=, etc.). */
  207. /* Turbo C large model doesn't compare pointers correctly */
  208. /* if they have different segment parts. */
  209. #if defined(__TURBOC__) && !defined(__OS2__) 
  210. typedef unsigned long ptr_ord_t;
  211. #else
  212. typedef char *ptr_ord_t;
  213. #endif
  214. /* Define all the pointer comparison operations. */
  215. #define _ptr_cmp(p1, rel, p2)  ((ptr_ord_t)(p1) rel (ptr_ord_t)(p2))
  216. #define ptr_le(p1, p2) _ptr_cmp(p1, <=, p2)
  217. #define ptr_lt(p1, p2) _ptr_cmp(p1, <, p2)
  218. #define ptr_ge(p1, p2) _ptr_cmp(p1, >=, p2)
  219. #define ptr_gt(p1, p2) _ptr_cmp(p1, >, p2)
  220. #define ptr_between(ptr, lo, hi)\
  221.   (ptr_ge(ptr, lo) && ptr_lt(ptr, hi))
  222.  
  223. /* Define max and min, but make sure to use the identical definition */
  224. /* to the one that all the compilers seem to have.... */
  225. #ifndef min
  226. #  define min(a, b) (((a) < (b)) ? (a) : (b))
  227. #endif
  228. #ifndef max
  229. #  define max(a, b) (((a) > (b)) ? (a) : (b))
  230. #endif
  231.  
  232. /* Define a standard way to round values to a (constant) modulus. */
  233. #define round_down(value, modulus)\
  234.   ( (modulus) & ((modulus) - 1) ?    /* not a power of 2 */\
  235.     (value) - (value) % (modulus) :\
  236.     (value) & -(modulus) )
  237. #define round_up(value, modulus)\
  238.   ( (modulus) & ((modulus) - 1) ?    /* not a power of 2 */\
  239.     ((value) + ((modulus) - 1)) / (modulus) * (modulus) :\
  240.     ((value) + ((modulus) - 1)) & -(modulus) )
  241.  
  242. /* VMS doesn't have the unlink system call.  Use delete instead. */
  243. #ifdef VMS
  244. #  define unlink(fname) delete(fname)
  245. #endif
  246.  
  247. /*
  248.  * In pre-ANSI C, float parameters get converted to double.
  249.  * However, if we pass a float to a function that has been declared
  250.  * with a prototype, and the parameter has been declared as float,
  251.  * the ANSI standard specifies that the parameter is left as float.
  252.  * To avoid problems caused by missing prototypes,
  253.  * we declare almost all float parameters as double.
  254.  */
  255. typedef double floatp;
  256.  
  257. /* If we are debugging, make all static variables and procedures public */
  258. /* so they get passed through the linker. */
  259. #ifdef NOPRIVATE
  260. # define private /* */
  261. #else
  262. # define private static
  263. #endif
  264.  
  265. /*
  266.  * Macros for argument templates.  ANSI C has these, as does Turbo C,
  267.  * but older pcc-derived (K&R) Unix compilers don't.  The syntax is
  268.  *    resulttype func(Pn(arg1, ..., argn));
  269.  */
  270.  
  271. #ifdef __PROTOTYPES__
  272. # define P0() void
  273. # define P1(t1) t1
  274. # define P2(t1,t2) t1,t2
  275. # define P3(t1,t2,t3) t1,t2,t3
  276. # define P4(t1,t2,t3,t4) t1,t2,t3,t4
  277. # define P5(t1,t2,t3,t4,t5) t1,t2,t3,t4,t5
  278. # define P6(t1,t2,t3,t4,t5,t6) t1,t2,t3,t4,t5,t6
  279. # define P7(t1,t2,t3,t4,t5,t6,t7) t1,t2,t3,t4,t5,t6,t7
  280. # define P8(t1,t2,t3,t4,t5,t6,t7,t8) t1,t2,t3,t4,t5,t6,t7,t8
  281. # define P9(t1,t2,t3,t4,t5,t6,t7,t8,t9) t1,t2,t3,t4,t5,t6,t7,t8,t9
  282. # define P10(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10) t1,t2,t3,t4,t5,t6,t7,t8,t9,t10
  283. # define P11(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11) t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11
  284. # 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
  285. #else
  286. # define P0() /* */
  287. # define P1(t1) /* */
  288. # define P2(t1,t2) /* */
  289. # define P3(t1,t2,t3) /* */
  290. # define P4(t1,t2,t3,t4) /* */
  291. # define P5(t1,t2,t3,t4,t5) /* */
  292. # define P6(t1,t2,t3,t4,t5,t6) /* */
  293. # define P7(t1,t2,t3,t4,t5,t6,t7) /* */
  294. # define P8(t1,t2,t3,t4,t5,t6,t7,t8) /* */
  295. # define P9(t1,t2,t3,t4,t5,t6,t7,t8,t9) /* */
  296. # define P10(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10) /* */
  297. # define P11(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11) /* */
  298. # define P12(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12) /* */
  299. #endif
  300.  
  301. /* Standard error printing macros. */
  302. /* Use dprintf for messages that just go to dstderr, */
  303. /* eprintf for error messages to estderr that include the program name, */
  304. /* lprintf for debugging messages that should include line number info. */
  305. /* Since we intercept fprintf to redirect output under MS Windows, */
  306. /* we have to define dputc and dputs in terms of fprintf also. */
  307.  
  308. /* dstderr and estderr may be redefined. */
  309. #define dstderr stderr
  310. #define estderr stderr
  311.  
  312. #define dputc(chr) dprintf1("%c", chr)
  313. #define dputs(str) dprintf1("%s", str)
  314. #define dprintf(str)\
  315.   fprintf(dstderr, str)
  316. #define dprintf1(str,arg1)\
  317.   fprintf(dstderr, str, arg1)
  318. #define dprintf2(str,arg1,arg2)\
  319.   fprintf(dstderr, str, arg1, arg2)
  320. #define dprintf3(str,arg1,arg2,arg3)\
  321.   fprintf(dstderr, str, arg1, arg2, arg3)
  322. #define dprintf4(str,arg1,arg2,arg3,arg4)\
  323.   fprintf(dstderr, str, arg1, arg2, arg3, arg4)
  324. #define dprintf5(str,arg1,arg2,arg3,arg4,arg5)\
  325.   fprintf(dstderr, str, arg1, arg2, arg3, arg4, arg5)
  326. #define dprintf6(str,arg1,arg2,arg3,arg4,arg5,arg6)\
  327.   fprintf(dstderr, str, arg1, arg2, arg3, arg4, arg5, arg6)
  328. #define dprintf7(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7)\
  329.   fprintf(dstderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
  330. #define dprintf8(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)\
  331.   fprintf(dstderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
  332. #define dprintf9(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)\
  333.   fprintf(dstderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
  334. #define dprintf10(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)\
  335.   fprintf(dstderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10)
  336. #define dprintf11(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11)\
  337.   fprintf(dstderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11)
  338. #define dprintf12(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12)\
  339.   fprintf(dstderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12)
  340.  
  341. #ifdef PROGRAM_NAME
  342. extern const char *PROGRAM_NAME;
  343. #  define _epn fprintf(estderr, "%s: ", PROGRAM_NAME),
  344. #else
  345. #  define _epn /* */
  346. #endif
  347.  
  348. #define eprintf(str)\
  349.   (_epn fprintf(estderr, str))
  350. #define eprintf1(str,arg1)\
  351.   (_epn fprintf(estderr, str, arg1))
  352. #define eprintf2(str,arg1,arg2)\
  353.   (_epn fprintf(estderr, str, arg1, arg2))
  354. #define eprintf3(str,arg1,arg2,arg3)\
  355.   (_epn fprintf(estderr, str, arg1, arg2, arg3))
  356. #define eprintf4(str,arg1,arg2,arg3,arg4)\
  357.   (_epn fprintf(estderr, str, arg1, arg2, arg3, arg4))
  358. #define eprintf5(str,arg1,arg2,arg3,arg4,arg5)\
  359.   (_epn fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5))
  360. #define eprintf6(str,arg1,arg2,arg3,arg4,arg5,arg6)\
  361.   (_epn fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6))
  362. #define eprintf7(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7)\
  363.   (_epn fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7))
  364. #define eprintf8(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)\
  365.   (_epn fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8))
  366. #define eprintf9(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)\
  367.   (_epn fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9))
  368. #define eprintf10(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)\
  369.   (_epn fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10))
  370.  
  371. #if __LINE__                /* compiler provides it */
  372. #  define _epl _epn fprintf(estderr, "%s(%d): ", __FILE__, __LINE__),
  373. #else
  374. #  define _epl _epn
  375. #endif
  376.  
  377. #define lprintf(str)\
  378.   (_epl fprintf(estderr, str))
  379. #define lprintf1(str,arg1)\
  380.   (_epl fprintf(estderr, str, arg1))
  381. #define lprintf2(str,arg1,arg2)\
  382.   (_epl fprintf(estderr, str, arg1, arg2))
  383. #define lprintf3(str,arg1,arg2,arg3)\
  384.   (_epl fprintf(estderr, str, arg1, arg2, arg3))
  385. #define lprintf4(str,arg1,arg2,arg3,arg4)\
  386.   (_epl fprintf(estderr, str, arg1, arg2, arg3, arg4))
  387. #define lprintf5(str,arg1,arg2,arg3,arg4,arg5)\
  388.   (_epl fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5))
  389. #define lprintf6(str,arg1,arg2,arg3,arg4,arg5,arg6)\
  390.   (_epl fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6))
  391. #define lprintf7(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7)\
  392.   (_epl fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7))
  393. #define lprintf8(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)\
  394.   (_epl fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8))
  395. #define lprintf9(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)\
  396.   (_epl fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9))
  397. #define lprintf10(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)\
  398.   (_epl fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10))
  399.  
  400. #endif                    /* std_INCLUDED */
  401.