xref: /plan9/sys/src/cmd/gs/src/jconfig0.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 2002 Aladdin Enterprises.  All rights reserved.
2 
3   This software is provided AS-IS with no warranty, either express or
4   implied.
5 
6   This software is distributed under license and may not be copied,
7   modified or distributed except as expressly authorized under the terms
8   of the license contained in the file LICENSE in this distribution.
9 
10   For more information about licensing, please refer to
11   http://www.ghostscript.com/licensing/. For information on
12   commercial licensing, go to http://www.artifex.com/licensing/ or
13   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15 */
16 
17 /* $Id: stdpn.h,v 1.2 2002/06/16 08:59:16 lpd Exp $ */
18 /* Pn macros for pre-ANSI compiler compatibility */
19 
20 #ifndef stdpn_INCLUDED
21 #  define stdpn_INCLUDED
22 
23 /*
24  * We formerly supported "traditional" (pre-ANSI) C compilers, by using
25  * these macros for formal parameter lists and defining them as empty
26  * for pre-ANSI compilers, with the syntax
27  *      resulttype func(Pn(arg1, ..., argn));
28  * However, we no longer support pre-ANSI compilers; these macros are
29  * deprecated (should not be used in new code), and eventually will be
30  * removed.
31  */
32 
33 #define P0() void
34 #define P1(t1) t1
35 #define P2(t1,t2) t1,t2
36 #define P3(t1,t2,t3) t1,t2,t3
37 #define P4(t1,t2,t3,t4) t1,t2,t3,t4
38 #define P5(t1,t2,t3,t4,t5) t1,t2,t3,t4,t5
39 #define P6(t1,t2,t3,t4,t5,t6) t1,t2,t3,t4,t5,t6
40 #define P7(t1,t2,t3,t4,t5,t6,t7) t1,t2,t3,t4,t5,t6,t7
41 #define P8(t1,t2,t3,t4,t5,t6,t7,t8) t1,t2,t3,t4,t5,t6,t7,t8
42 #define P9(t1,t2,t3,t4,t5,t6,t7,t8,t9) t1,t2,t3,t4,t5,t6,t7,t8,t9
43 #define P10(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10) t1,t2,t3,t4,t5,t6,t7,t8,t9,t10
44 #define P11(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11) t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11
45 #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
46 #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
47 #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
48 #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
49 #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
50 
51 #endif /* stdpn_INCLUDED */
52 /* Copyright (C) 1993-2003 artofcode LLC.  All rights reserved.
53 
54   This software is provided AS-IS with no warranty, either express or
55   implied.
56 
57   This software is distributed under license and may not be copied,
58   modified or distributed except as expressly authorized under the terms
59   of the license contained in the file LICENSE in this distribution.
60 
61   For more information about licensing, please refer to
62   http://www.ghostscript.com/licensing/. For information on
63   commercial licensing, go to http://www.artifex.com/licensing/ or
64   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
65   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
66 */
67 
68 /* $Id: stdpre.h,v 1.22 2003/12/09 21:17:59 giles Exp $ */
69 /* Standard definitions for Ghostscript code not needing arch.h */
70 
71 #ifndef stdpre_INCLUDED
72 #  define stdpre_INCLUDED
73 
74 /*
75  * Here we deal with the vagaries of various C compilers.  We assume that:
76  *      ANSI-standard Unix compilers define __STDC__.
77  *      gcc defines __GNUC__.
78  *      Borland Turbo C and Turbo C++ define __MSDOS__ and __TURBOC__.
79  *      Borland C++ defines __BORLANDC__, __MSDOS__, and __TURBOC__.
80  *      Microsoft C/C++ defines _MSC_VER and _MSDOS.
81  *      Watcom C defines __WATCOMC__ and MSDOS.
82  *      MetroWerks C defines __MWERKS__.
83  *
84  * We arrange to define __MSDOS__ on all the MS-DOS platforms.
85  */
86 #if (defined(MSDOS) || defined(_MSDOS)) && !defined(__MSDOS__)
87 #  define __MSDOS__
88 #endif
89 /*
90  * Also, not used much here, but used in other header files, we assume:
91  *      Unix System V environments define SYSV.
92  *      The SCO ODT compiler defines M_SYSV and M_SYS3.
93  *      VMS systems define VMS.
94  *      OSF/1 compilers define __osf__ or __OSF__.
95  *        (The VMS and OSF/1 C compilers handle prototypes and const,
96  *        but do not define __STDC__.)
97  *      bsd 4.2 or 4.3 systems define BSD4_2.
98  *      POSIX-compliant environments define _POSIX_SOURCE.
99  *      Motorola 88K BCS/OCS systems defined m88k.
100  *
101  * We make fairly heroic efforts to confine all uses of these flags to
102  * header files, and never to use them in code.
103  */
104 #if defined(__osf__) && !defined(__OSF__)
105 #  define __OSF__		/* */
106 #endif
107 #if defined(M_SYSV) && !defined(SYSV)
108 #  define SYSV			/* */
109 #endif
110 #if defined(M_SYS3) && !defined(__SVR3)
111 #  define __SVR3		/* */
112 #endif
113 
114 #if defined(__STDC__) || defined(__MSDOS__) || defined(__convex__) || defined(VMS) || defined(__OSF__) || defined(__WIN32__) || defined(__IBMC__) || defined(M_UNIX) || defined(__GNUC__) || defined(__BORLANDC__)
115 # if !(defined(M_XENIX) && !defined(__GNUC__))	/* SCO Xenix cc is broken */
116 #  define __PROTOTYPES__	/* */
117 # endif
118 #endif
119 
120 /* Define dummy values for __FILE__ and __LINE__ if the compiler */
121 /* doesn't provide these.  Note that places that use __FILE__ */
122 /* must check explicitly for a null pointer. */
123 #ifndef __FILE__
124 #  define __FILE__ NULL
125 #endif
126 #ifndef __LINE__
127 #  define __LINE__ 0
128 #endif
129 
130 /* Disable 'const' and 'volatile' if the compiler can't handle them. */
131 #ifndef __PROTOTYPES__
132 #  undef const
133 #  define const			/* */
134 #  undef volatile
135 #  define volatile		/* */
136 #endif
137 
138 /* Disable 'inline' if the compiler can't handle it. */
139 #ifdef __DECC
140 #  undef inline
141 #  define inline __inline
142 #else
143 #  ifdef __GNUC__
144 /* Define inline as __inline__ so -pedantic won't produce a warning. */
145 #    undef inline
146 #    define inline __inline__
147 #  else
148 #    if !(defined(__MWERKS__) || defined(inline))
149 #      define inline		/* */
150 #    endif
151 #  endif
152 #endif
153 
154 /*
155  * Provide a way to include inline procedures in header files, regardless of
156  * whether the compiler (A) doesn't support inline at all, (B) supports it
157  * but also always compiles a closed copy, (C) supports it but somehow only
158  * includes a single closed copy in the executable, or (D) supports it and
159  * also supports a different syntax if no closed copy is desired.
160  *
161  * The code that appears just after this comment indicates which compilers
162  * are of which kind.  (Eventually this might be determined automatically.)
163  *	(A) and (B) require nothing here.
164  *	(C) requires
165  *		#define extern_inline inline
166  *	(D) requires
167  *		#define extern_inline extern inline  // or whatever
168  * Note that for case (B), the procedure will only be declared inline in
169  * the .c file where its closed copy is compiled.
170  */
171 #ifdef __GNUC__
172 #  define extern_inline extern inline
173 #endif
174 
175 /*
176  * To include an inline procedure xyz in a header file abc.h, use the
177  * following template in the header file:
178 
179 extern_inline int xyz(<<parameters>>)
180 #if HAVE_EXTERN_INLINE || defined(INLINE_INCLUDE_xyz)
181 {
182     <<body>>
183 }
184 #else
185 ;
186 #endif
187 
188  * And use the following in whichever .c file takes responsibility for
189  * including the closed copy of xyz:
190 
191 #define EXTERN_INCLUDE_xyz	// must precede all #includes
192 #include "abc.h"
193 
194  * The definitions of the EXTERN_INCLUDE_ macros must precede *all* includes
195  * because there is no way to know whether some other .h file #includes abc.h
196  * indirectly, and because of the protection against double #includes, the
197  * EXTERN_INCLUDE_s must be defined before the first inclusion of abc.h.
198  */
199 
200 /*
201  * The following is generic code that does not need per-compiler
202  * customization.
203  */
204 #ifdef extern_inline
205 #  define HAVE_EXTERN_INLINE 1
206 #else
207 #  define extern_inline /* */
208 #  define HAVE_EXTERN_INLINE 0
209 #endif
210 
211 /*
212  * Some compilers give a warning if a function call that returns a value
213  * is used as a statement; a few compilers give an error for the construct
214  * (void)0, which is contrary to the ANSI standard.  Since we don't know of
215  * any compilers that do both, we define a macro here for discarding
216  * the value of an expression statement, which can be defined as either
217  * including or not including the cast.  (We don't conditionalize this here,
218  * because no commercial compiler gives the error on (void)0, although
219  * some give warnings.)  */
220 #define DISCARD(expr) ((void)(expr))
221 /* Backward compatibility */
222 #define discard(expr) DISCARD(expr)
223 
224 /*
225  * Some versions of the Watcom compiler give a "Comparison result always
226  * 0/1" message that we want to suppress because it gets in the way of
227  * meaningful warnings.
228  */
229 #ifdef __WATCOMC__
230 #  pragma disable_message(124);
231 #endif
232 
233 /*
234  * Some versions of gcc have a bug such that after
235 	byte *p;
236 	...
237 	x = *(long *)p;
238  * the compiler then thinks that p always points to long-aligned data.
239  * Detect this here so it can be handled appropriately in the few places
240  * that (we think) matter.
241  */
242 #ifdef __GNUC__
243 # if __GNUC__ == 2 & (7 < __GNUC_MINOR__ <= 95)
244 #  define ALIGNMENT_ALIASING_BUG
245 # endif
246 #endif
247 
248 /*
249  * The SVR4.2 C compiler incorrectly considers the result of << and >>
250  * to be unsigned if the left operand is signed and the right operand is
251  * unsigned.  We believe this only causes trouble in Ghostscript code when
252  * the right operand is a sizeof(...), which is unsigned for this compiler.
253  * Therefore, we replace the relevant uses of sizeof with size_of:
254  */
255 #define size_of(x) ((int)(sizeof(x)))
256 
257 /*
258  * far_data was formerly used for static data that had to be assigned its
259  * own segment on PCs with 64K segments.  This was supported in Borland C++,
260  * but none of the other compilers.  Since we no longer support
261  * small-segment systems, far_data is vacuous.
262  */
263 #undef far_data
264 #define far_data /* */
265 
266 /*
267  * Get the number of elements of a statically dimensioned array.
268  * Note that this also works on array members of structures.
269  */
270 #define countof(a) (sizeof(a) / sizeof((a)[0]))
271 #define count_of(a) (size_of(a) / size_of((a)[0]))
272 
273 /*
274  * Get the offset of a structure member.  Amazingly enough, the simpler
275  * definition works on all compilers except for one broken MIPS compiler
276  * and the IBM RS/6000.  Unfortunately, because of these two compilers,
277  * we have to use the more complex definition.  Even more unfortunately,
278  * the more complex definition doesn't work on the MetroWerks
279  * CodeWarrior compiler (Macintosh and BeOS).
280  */
281 #ifdef __MWERKS__
282 #define offset_of(type, memb)\
283  ((int) &((type *) 0)->memb)
284 #else
285 #define offset_of(type, memb)\
286  ((int) ( (char *)&((type *)0)->memb - (char *)((type *)0) ))
287 #endif
288 
289 /*
290  * Get the alignment of a pointer modulo a given power of 2.
291  * There is no portable way to do this, but the following definition
292  * works on all reasonable systems.
293  */
294 #define ALIGNMENT_MOD(ptr, modu)\
295   ((uint)( ((const char *)(ptr) - (const char *)0) & ((modu) - 1) ))
296 
297 /* Define short names for the unsigned types. */
298 typedef unsigned char byte;
299 typedef unsigned char uchar;
300 typedef unsigned short ushort;
301 typedef unsigned int uint;
302 typedef unsigned long ulong;
303 
304 /* Since sys/types.h may define one or more of these (depending on
305  * the platform), we have to take steps to prevent name clashes.
306  * Unfortunately this can clobber valid definitions for the size-
307  * specific types, but there's no simple solution.
308  *
309  * NOTE: This requires that you include std.h *before* any other
310  * header file that includes sys/types.h.
311  *
312  */
313 #define bool bool_		/* (maybe not needed) */
314 #define uchar uchar_
315 #define uint uint_
316 #define ushort ushort_
317 #define ulong ulong_
318 #include <sys/types.h>
319 #undef bool
320 #undef uchar
321 #undef uint
322 #undef ushort
323 #undef ulong
324 
325 /*
326  * Define a Boolean type.  Even though we would like it to be
327  * unsigned char, it pretty well has to be int, because
328  * that's what all the relational operators and && and || produce.
329  * We can't make it an enumerated type, because ints don't coerce
330  * freely to enums (although the opposite is true).
331  * Unfortunately, at least some C++ compilers have a built-in bool type,
332  * and the MetroWerks C++ compiler insists that bool be equivalent to
333  * unsigned char.
334  */
335 #ifndef __cplusplus
336 #ifdef __BEOS__
337 typedef unsigned char bool;
338 #else
339 typedef int bool;
340 #endif
341 #endif
342 /*
343  * Older versions of MetroWerks CodeWarrior defined true and false, but they're now
344  * an enum in the (MacOS) Universal Interfaces. The only way around this is to escape
345  * our own definitions wherever MacTypes.h is included.
346  */
347 #ifndef __MACOS__
348 #undef false
349 #define false ((bool)0)
350 #undef true
351 #define true ((bool)1)
352 #endif /* __MACOS__ */
353 
354 /*
355  * Compilers disagree as to whether macros used in macro arguments
356  * should be expanded at the time of the call, or at the time of
357  * final expansion.  Even authoritative documents disagree: the ANSI
358  * standard says the former, but Harbison and Steele's book says the latter.
359  * In order to work around this discrepancy, we have to do some very
360  * ugly things in a couple of places.  We mention it here because
361  * it might well trip up future developers.
362  */
363 
364 /*
365  * Define the type to be used for ordering pointers (<, >=, etc.).
366  * The Borland and Microsoft large models only compare the offset part
367  * of segmented pointers.  Semantically, the right type to use for the
368  * comparison is char huge *, but we have no idea how expensive comparing
369  * such pointers is, and any type that compares all the bits of the pointer,
370  * gives the right result for pointers in the same segment, and keeps
371  * different segments disjoint will do.
372  */
373 #if defined(__TURBOC__) || defined(_MSC_VER)
374 typedef unsigned long ptr_ord_t;
375 #else
376 typedef const char *ptr_ord_t;
377 #endif
378 /* Define all the pointer comparison operations. */
379 #define _PTR_CMP(p1, rel, p2)  ((ptr_ord_t)(p1) rel (ptr_ord_t)(p2))
380 #define PTR_LE(p1, p2) _PTR_CMP(p1, <=, p2)
381 #define PTR_LT(p1, p2) _PTR_CMP(p1, <, p2)
382 #define PTR_GE(p1, p2) _PTR_CMP(p1, >=, p2)
383 #define PTR_GT(p1, p2) _PTR_CMP(p1, >, p2)
384 #define PTR_BETWEEN(ptr, lo, hi)\
385   (PTR_GE(ptr, lo) && PTR_LT(ptr, hi))
386 
387 /* Define  min and max, but make sure to use the identical definition */
388 /* to the one that all the compilers seem to have.... */
389 #ifndef min
390 #  define min(a, b) (((a) < (b)) ? (a) : (b))
391 #endif
392 #ifndef max
393 #  define max(a, b) (((a) > (b)) ? (a) : (b))
394 #endif
395 
396 /* Define a standard way to round values to a (constant) modulus. */
397 #define ROUND_DOWN(value, modulus)\
398   ( (modulus) & ((modulus) - 1) ?	/* not a power of 2 */\
399     (value) - (value) % (modulus) :\
400     (value) & -(modulus) )
401 #define ROUND_UP(value, modulus)\
402   ( (modulus) & ((modulus) - 1) ?	/* not a power of 2 */\
403     ((value) + ((modulus) - 1)) / (modulus) * (modulus) :\
404     ((value) + ((modulus) - 1)) & -(modulus) )
405 /* Backward compatibility */
406 #define round_up(v, m) ROUND_UP(v, m)
407 #define round_down(v, m) ROUND_DOWN(v, m)
408 
409 /*
410  * In pre-ANSI C, float parameters get converted to double.
411  * However, if we pass a float to a function that has been declared
412  * with a prototype, and the parameter has been declared as float,
413  * the ANSI standard specifies that the parameter is left as float.
414  * To avoid problems caused by missing prototypes,
415  * we declare almost all float parameters as double.
416  */
417 typedef double floatp;
418 
419 /*
420  * Because of C's strange insistence that ; is a terminator and not a
421  * separator, compound statements {...} are not syntactically equivalent to
422  * single statements.  Therefore, we define here a compound-statement
423  * construct that *is* syntactically equivalent to a single statement.
424  * Usage is
425  *      BEGIN
426  *        ...statements...
427  *      END
428  */
429 #define BEGIN	do {
430 #define END	} while (0)
431 
432 /*
433  * Define a handy macro for a statement that does nothing.
434  * We can't just use an empty statement, since this upsets some compilers.
435  */
436 #ifndef DO_NOTHING
437 #  define DO_NOTHING BEGIN END
438 #endif
439 
440 /*
441  * For accountability, debugging, and error messages, we pass a client
442  * identification string to alloc and free, and possibly other places as
443  * well.  Define the type for these strings.
444  */
445 typedef const char *client_name_t;
446 /****** WHAT TO DO ABOUT client_name_string ? ******/
447 #define client_name_string(cname) (cname)
448 
449 /*
450  * If we are debugging, make all static variables and procedures public
451  * so they get passed through the linker.
452  */
453 #define public			/* */
454 /*
455  * We separate out the definition of private this way so that
456  * we can temporarily #undef it to handle the X Windows headers,
457  * which define a member named private.
458  */
459 #ifdef NOPRIVATE
460 # define private_		/* */
461 #else
462 # define private_ static
463 #endif
464 #define private private_
465 
466 /*
467  * Define the now-deprecated Pn macros for pre-ANSI compiler compatibility.
468  * The double-inclusion check is replicated here because of the way that
469  * jconfig.h is constructed.
470  */
471 #ifndef stdpn_INCLUDED
472 #  define stdpn_INCLUDED
473 #include "stdpn.h"
474 #endif /* stdpn_INCLUDED */
475 
476 /*
477  * Define success and failure codes for 'exit'.  The only system on which
478  * they are different is VMS with older DEC C versions.  We aren't sure
479  * in what version DEC C started being compatible with the rest of the
480  * world, and we don't know what the story is with VAX C.  If you have
481  * problems, uncomment the following line or add -DOLD_VMS_C to the C
482  * command line.
483  */
484 /*#define OLD_VMS_C*/
485 #if defined(VMS)
486 #  define exit_FAILED 18
487 #  if (defined(OLD_VMS_C) || !defined(__DECC))
488 #    define exit_OK 1
489 #  else
490 #    define exit_OK 0
491 #  endif
492 #else
493 #  define exit_OK 0
494 #  define exit_FAILED 1
495 #endif
496 
497 #endif /* stdpre_INCLUDED */
498 /* Copyright (C) 1994, 1998 Aladdin Enterprises.  All rights reserved.
499 
500   This software is provided AS-IS with no warranty, either express or
501   implied.
502 
503   This software is distributed under license and may not be copied,
504   modified or distributed except as expressly authorized under the terms
505   of the license contained in the file LICENSE in this distribution.
506 
507   For more information about licensing, please refer to
508   http://www.ghostscript.com/licensing/. For information on
509   commercial licensing, go to http://www.artifex.com/licensing/ or
510   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
511   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
512 */
513 
514 /* $Id: gsjconf.h,v 1.4 2002/02/21 22:24:52 giles Exp $ */
515 /* jconfig.h file for Independent JPEG Group code */
516 
517 #ifndef gsjconf_INCLUDED
518 #  define gsjconf_INCLUDED
519 
520 /*
521  * We should have the following here:
522 
523 #include "stdpre.h"
524 
525  * But because of the directory structure used to build the IJG library, we
526  * actually concatenate stdpre.h on the front of this file instead to
527  * construct the jconfig.h file used for the compilation.
528  */
529 
530 #include "arch.h"
531 
532 /* See IJG's jconfig.doc for the contents of this file. */
533 
534 #ifdef __PROTOTYPES__
535 #  define HAVE_PROTOTYPES
536 #endif
537 
538 #define HAVE_UNSIGNED_CHAR
539 #define HAVE_UNSIGNED_SHORT
540 #undef CHAR_IS_UNSIGNED
541 
542 #ifdef __STDC__			/* is this right? */
543 #  define HAVE_STDDEF_H
544 #  define HAVE_STDLIB_H
545 #endif
546 
547 #undef NEED_BSD_STRINGS		/* WRONG */
548 #undef NEED_SYS_TYPES_H		/* WRONG */
549 #undef NEED_FAR_POINTERS
550 #undef NEED_SHORT_EXTERNAL_NAMES
551 
552 #undef INCOMPLETE_TYPES_BROKEN
553 
554 /* The following is documented in jmemsys.h, not jconfig.doc. */
555 #if ARCH_SIZEOF_INT <= 2
556 #  undef MAX_ALLOC_CHUNK
557 #  define MAX_ALLOC_CHUNK 0xfff0
558 #endif
559 
560 #ifdef JPEG_INTERNALS
561 
562 #if ARCH_ARITH_RSHIFT == 0
563 #  define RIGHT_SHIFT_IS_UNSIGNED
564 #else
565 #  undef RIGHT_SHIFT_IS_UNSIGNED
566 #endif
567 
568 #endif /* JPEG_INTERNALS */
569 
570 #endif /* gsjconf_INCLUDED */
571 
572