std.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /* Copyright (C) 1989-2003 artofcode LLC. All rights reserved.
  2. This software is provided AS-IS with no warranty, either express or
  3. implied.
  4. This software is distributed under license and may not be copied,
  5. modified or distributed except as expressly authorized under the terms
  6. of the license contained in the file LICENSE in this distribution.
  7. For more information about licensing, please refer to
  8. http://www.ghostscript.com/licensing/. For information on
  9. commercial licensing, go to http://www.artifex.com/licensing/ or
  10. contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  12. */
  13. /* $Id: std.h,v 1.12 2004/08/04 19:36:13 stefan Exp $ */
  14. /* Standard definitions for Ghostscript code */
  15. #ifndef std_INCLUDED
  16. # define std_INCLUDED
  17. #include "stdpre.h"
  18. /* Include the architecture definitions. */
  19. #include "arch.h"
  20. /*
  21. * Define lower-case versions of the architecture parameters for backward
  22. * compatibility.
  23. */
  24. #define arch_align_short_mod ARCH_ALIGN_SHORT_MOD
  25. #define arch_align_int_mod ARCH_ALIGN_INT_MOD
  26. #define arch_align_long_mod ARCH_ALIGN_LONG_MOD
  27. #define arch_align_ptr_mod ARCH_ALIGN_PTR_MOD
  28. #define arch_align_float_mod ARCH_ALIGN_FLOAT_MOD
  29. #define arch_align_double_mod ARCH_ALIGN_DOUBLE_MOD
  30. #define arch_align_struct_mod ARCH_ALIGN_STRUCT_MOD
  31. #define arch_log2_sizeof_short ARCH_LOG2_SIZEOF_SHORT
  32. #define arch_log2_sizeof_int ARCH_LOG2_SIZEOF_INT
  33. #define arch_log2_sizeof_long ARCH_LOG2_SIZEOF_LONG
  34. #define arch_sizeof_ptr ARCH_SIZEOF_PTR
  35. #define arch_sizeof_float ARCH_SIZEOF_FLOAT
  36. #define arch_sizeof_double ARCH_SIZEOF_DOUBLE
  37. #define arch_float_mantissa_bits ARCH_FLOAT_MANTISSA_BITS
  38. #define arch_double_mantissa_bits ARCH_DOUBLE_MANTISSA_BITS
  39. #define arch_max_uchar ARCH_MAX_UCHAR
  40. #define arch_max_ushort ARCH_MAX_USHORT
  41. #define arch_max_uint ARCH_MAX_UINT
  42. #define arch_max_ulong ARCH_MAX_ULONG
  43. #define arch_cache1_size ARCH_CACHE1_SIZE
  44. #define arch_cache2_size ARCH_CACHE2_SIZE
  45. #define arch_is_big_endian ARCH_IS_BIG_ENDIAN
  46. #define arch_ptrs_are_signed ARCH_PTRS_ARE_SIGNED
  47. #define arch_floats_are_IEEE ARCH_FLOATS_ARE_IEEE
  48. #define arch_arith_rshift ARCH_ARITH_RSHIFT
  49. #define arch_can_shift_full_long ARCH_CAN_SHIFT_FULL_LONG
  50. /*
  51. * Define the alignment that the memory manager must preserve.
  52. * We assume all alignment moduli are powers of 2.
  53. * NOTE: we require that malloc align blocks at least this strictly.
  54. */
  55. #define ARCH_ALIGN_MEMORY_MOD\
  56. (((ARCH_ALIGN_LONG_MOD - 1) | (ARCH_ALIGN_PTR_MOD - 1) |\
  57. (ARCH_ALIGN_DOUBLE_MOD - 1) | (ARCH_ALIGN_STRUCT_MOD - 1)) + 1)
  58. #define arch_align_memory_mod ARCH_ALIGN_MEMORY_MOD
  59. /* Define integer data type sizes in terms of log2s. */
  60. #define ARCH_SIZEOF_CHAR (1 << ARCH_LOG2_SIZEOF_CHAR)
  61. #define ARCH_SIZEOF_SHORT (1 << ARCH_LOG2_SIZEOF_SHORT)
  62. #define ARCH_SIZEOF_INT (1 << ARCH_LOG2_SIZEOF_INT)
  63. #define ARCH_SIZEOF_LONG (1 << ARCH_LOG2_SIZEOF_LONG)
  64. #define ARCH_SIZEOF_LONG_LONG (1 << ARCH_LOG2_SIZEOF_LONG_LONG)
  65. #define ARCH_INTS_ARE_SHORT (ARCH_SIZEOF_INT == ARCH_SIZEOF_SHORT)
  66. /* Backward compatibility */
  67. #define arch_sizeof_short ARCH_SIZEOF_SHORT
  68. #define arch_sizeof_int ARCH_SIZEOF_INT
  69. #define arch_sizeof_long ARCH_SIZEOF_LONG
  70. #define arch_ints_are_short ARCH_INTS_ARE_SHORT
  71. /* Define whether we are on a large- or small-memory machine. */
  72. /* Currently, we assume small memory and 16-bit ints are synonymous. */
  73. #define ARCH_SMALL_MEMORY (ARCH_SIZEOF_INT <= 2)
  74. /* Backward compatibility */
  75. #define arch_small_memory ARCH_SMALL_MEMORY
  76. /* Define unsigned 16- and 32-bit types. These are needed in */
  77. /* a surprising number of places that do bit manipulation. */
  78. #if arch_sizeof_short == 2 /* no plausible alternative! */
  79. typedef ushort bits16;
  80. #endif
  81. #if arch_sizeof_int == 4
  82. typedef uint bits32;
  83. #else
  84. # if arch_sizeof_long == 4
  85. typedef ulong bits32;
  86. # endif
  87. #endif
  88. /* Minimum and maximum values for the signed types. */
  89. /* Avoid casts, to make them acceptable to strict ANSI compilers. */
  90. #define min_short (-1 << (arch_sizeof_short * 8 - 1))
  91. #define max_short (~min_short)
  92. #define min_int (-1 << (arch_sizeof_int * 8 - 1))
  93. #define max_int (~min_int)
  94. #define min_long (-1L << (arch_sizeof_long * 8 - 1))
  95. #define max_long (~min_long)
  96. /*
  97. * The maximum values for the unsigned types are defined in arch.h,
  98. * because so many compilers handle unsigned constants wrong.
  99. * In particular, most of the DEC VMS compilers incorrectly sign-extend
  100. * short unsigned constants (but not short unsigned variables) when
  101. * widening them to longs. We program around this on a case-by-case basis.
  102. * Some compilers don't truncate constants when they are cast down.
  103. * The UTek compiler does special weird things of its own.
  104. * All the rest (including gcc on all platforms) do the right thing.
  105. */
  106. #define max_uchar arch_max_uchar
  107. #define max_ushort arch_max_ushort
  108. #define max_uint arch_max_uint
  109. #define max_ulong arch_max_ulong
  110. /* Minimum and maximum values for pointers. */
  111. #if arch_ptrs_are_signed
  112. # define min_ptr min_long
  113. # define max_ptr max_long
  114. #else
  115. # define min_ptr ((ulong)0)
  116. # define max_ptr max_ulong
  117. #endif
  118. /* Define a reliable arithmetic right shift. */
  119. /* Must use arith_rshift_1 for a shift by a literal 1. */
  120. #define arith_rshift_slow(x,n) ((x) < 0 ? ~(~(x) >> (n)) : (x) >> (n))
  121. #if arch_arith_rshift == 2
  122. # define arith_rshift(x,n) ((x) >> (n))
  123. # define arith_rshift_1(x) ((x) >> 1)
  124. #else
  125. #if arch_arith_rshift == 1 /* OK except for n=1 */
  126. # define arith_rshift(x,n) ((x) >> (n))
  127. # define arith_rshift_1(x) arith_rshift_slow(x,1)
  128. #else
  129. # define arith_rshift(x,n) arith_rshift_slow(x,n)
  130. # define arith_rshift_1(x) arith_rshift_slow(x,1)
  131. #endif
  132. #endif
  133. /*
  134. * Standard error printing macros.
  135. * Use dprintf for messages that just go to dpf;
  136. * dlprintf for messages to dpf with optional with file name (and,
  137. * if available, line number);
  138. * eprintf for error messages to epf that include the program name;
  139. * lprintf for debugging messages that should include line number info.
  140. * Since we all stdout/stderr output must go via outprintf/errprintf,
  141. * we have to define dputc and dputs in terms of errprintf also.
  142. */
  143. /*
  144. * We would prefer not to include stdio.h here, but we need it for
  145. * the FILE * argument of the printing procedures.
  146. */
  147. #include <stdio.h>
  148. /*
  149. * Not a very good place to define this, but we can't find a better one.
  150. */
  151. #ifndef gs_memory_DEFINED
  152. # define gs_memory_DEFINED
  153. typedef struct gs_memory_s gs_memory_t;
  154. #endif
  155. #define init_proc(proc)\
  156. int proc(gs_memory_t *)
  157. /* dpf and epf may be redefined */
  158. #define dpf errprintf
  159. #define epf errprintf
  160. /* To allow stdout and stderr to be redirected, all stdout goes
  161. * though outwrite and all stderr goes through errwrite.
  162. */
  163. int outwrite(const gs_memory_t *mem, const char *str, int len);
  164. int errwrite(const char *str, int len);
  165. void outflush(const gs_memory_t *mem);
  166. void errflush(void);
  167. /* Formatted output to outwrite and errwrite.
  168. * The maximum string length is 1023 characters.
  169. */
  170. #ifdef __PROTOTYPES__
  171. int outprintf(const gs_memory_t *mem, const char *fmt, ...);
  172. int errprintf(const char *fmt, ...);
  173. #else
  174. int outprintf();
  175. int errprintf();
  176. #endif
  177. /* Print the program line # for debugging. */
  178. #if __LINE__ /* compiler provides it */
  179. void dprintf_file_and_line(const char *, int);
  180. # define _dpl dprintf_file_and_line(__FILE__, __LINE__),
  181. #else
  182. void dprintf_file_only(const char *);
  183. # define _dpl dprintf_file_only(__FILE__),
  184. #endif
  185. void dflush(void); /* flush stderr */
  186. #define dputc(chr) dprintf1("%c", chr)
  187. #define dlputc(chr) dlprintf1("%c", chr)
  188. #define dputs(str) dprintf1("%s", str)
  189. #define dlputs(str) dlprintf1("%s", str)
  190. #define dprintf(str)\
  191. dpf(str)
  192. #define dlprintf(str)\
  193. (_dpl dpf(str))
  194. #define dprintf1(str,arg1)\
  195. dpf(str, arg1)
  196. #define dlprintf1(str,arg1)\
  197. (_dpl dprintf1(str, arg1))
  198. #define dprintf2(str,arg1,arg2)\
  199. dpf(str, arg1, arg2)
  200. #define dlprintf2(str,arg1,arg2)\
  201. (_dpl dprintf2(str, arg1, arg2))
  202. #define dprintf3(str,arg1,arg2,arg3)\
  203. dpf(str, arg1, arg2, arg3)
  204. #define dlprintf3(str,arg1,arg2,arg3)\
  205. (_dpl dprintf3(str, arg1, arg2, arg3))
  206. #define dprintf4(str,arg1,arg2,arg3,arg4)\
  207. dpf(str, arg1, arg2, arg3, arg4)
  208. #define dlprintf4(str,arg1,arg2,arg3,arg4)\
  209. (_dpl dprintf4(str, arg1, arg2, arg3, arg4))
  210. #define dprintf5(str,arg1,arg2,arg3,arg4,arg5)\
  211. dpf(str, arg1, arg2, arg3, arg4, arg5)
  212. #define dlprintf5(str,arg1,arg2,arg3,arg4,arg5)\
  213. (_dpl dprintf5(str, arg1, arg2, arg3, arg4, arg5))
  214. #define dprintf6(str,arg1,arg2,arg3,arg4,arg5,arg6)\
  215. dpf(str, arg1, arg2, arg3, arg4, arg5, arg6)
  216. #define dlprintf6(str,arg1,arg2,arg3,arg4,arg5,arg6)\
  217. (_dpl dprintf6(str, arg1, arg2, arg3, arg4, arg5, arg6))
  218. #define dprintf7(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7)\
  219. dpf(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
  220. #define dlprintf7(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7)\
  221. (_dpl dprintf7(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7))
  222. #define dprintf8(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)\
  223. dpf(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
  224. #define dlprintf8(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)\
  225. (_dpl dprintf8(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8))
  226. #define dprintf9(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)\
  227. dpf(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
  228. #define dlprintf9(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)\
  229. (_dpl dprintf9(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9))
  230. #define dprintf10(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)\
  231. dpf(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10)
  232. #define dlprintf10(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)\
  233. (_dpl dprintf10(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10))
  234. #define dprintf11(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11)\
  235. dpf(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11)
  236. #define dlprintf11(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11)\
  237. (_dpl dprintf11(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11))
  238. #define dprintf12(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12)\
  239. dpf(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12)
  240. #define dlprintf12(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12)\
  241. (_dpl dprintf12(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12))
  242. void printf_program_ident(const gs_memory_t *mem, const char *program_name, long revision_number);
  243. void eprintf_program_ident(const char *program_name, long revision_number);
  244. const char *gs_program_name(void);
  245. long gs_revision_number(void);
  246. #define _epi eprintf_program_ident(gs_program_name(), gs_revision_number()),
  247. #define eprintf(str)\
  248. (_epi epf(str))
  249. #define eprintf1(str,arg1)\
  250. (_epi epf(str, arg1))
  251. #define eprintf2(str,arg1,arg2)\
  252. (_epi epf(str, arg1, arg2))
  253. #define eprintf3(str,arg1,arg2,arg3)\
  254. (_epi epf(str, arg1, arg2, arg3))
  255. #define eprintf4(str,arg1,arg2,arg3,arg4)\
  256. (_epi epf(str, arg1, arg2, arg3, arg4))
  257. #define eprintf5(str,arg1,arg2,arg3,arg4,arg5)\
  258. (_epi epf(str, arg1, arg2, arg3, arg4, arg5))
  259. #define eprintf6(str,arg1,arg2,arg3,arg4,arg5,arg6)\
  260. (_epi epf(str, arg1, arg2, arg3, arg4, arg5, arg6))
  261. #define eprintf7(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7)\
  262. (_epi epf(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7))
  263. #define eprintf8(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)\
  264. (_epi epf(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8))
  265. #define eprintf9(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)\
  266. (_epi epf(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9))
  267. #define eprintf10(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)\
  268. (_epi epf(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10))
  269. #if __LINE__ /* compiler provides it */
  270. void lprintf_file_and_line(const char *, int);
  271. # define _epl _epi lprintf_file_and_line(__FILE__, __LINE__),
  272. #else
  273. void lprintf_file_only(const char *);
  274. # define _epl _epi lprintf_file_only(__FILE__)
  275. #endif
  276. #define lprintf(str)\
  277. (_epl epf(str))
  278. #define lprintf1(str,arg1)\
  279. (_epl epf(str, arg1))
  280. #define lprintf2(str,arg1,arg2)\
  281. (_epl epf(str, arg1, arg2))
  282. #define lprintf3(str,arg1,arg2,arg3)\
  283. (_epl epf(str, arg1, arg2, arg3))
  284. #define lprintf4(str,arg1,arg2,arg3,arg4)\
  285. (_epl epf(str, arg1, arg2, arg3, arg4))
  286. #define lprintf5(str,arg1,arg2,arg3,arg4,arg5)\
  287. (_epl epf(str, arg1, arg2, arg3, arg4, arg5))
  288. #define lprintf6(str,arg1,arg2,arg3,arg4,arg5,arg6)\
  289. (_epl epf(str, arg1, arg2, arg3, arg4, arg5, arg6))
  290. #define lprintf7(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7)\
  291. (_epl epf(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7))
  292. #define lprintf8(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)\
  293. (_epl epf(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8))
  294. #define lprintf9(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)\
  295. (_epl epf(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9))
  296. #define lprintf10(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)\
  297. (_epl epf(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10))
  298. /*
  299. * Define the prototype for module initialization procedures. This is not
  300. * a very good place to define this, but we can't find a better one.
  301. */
  302. #ifndef gs_memory_DEFINED
  303. # define gs_memory_DEFINED
  304. typedef struct gs_memory_s gs_memory_t;
  305. #endif
  306. #define init_proc(proc)\
  307. int proc(gs_memory_t *)
  308. #endif /* std_INCLUDED */