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