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