1 /* $XConsortium: util.h,v 1.3 92/03/26 16:42:29 eswu Exp $ */ 2 /* Copyright International Business Machines,Corp. 1991 3 * All Rights Reserved 4 * 5 * License to use, copy, modify, and distribute this software 6 * and its documentation for any purpose and without fee is 7 * hereby granted, provided that the above copyright notice 8 * appear in all copies and that both that copyright notice and 9 * this permission notice appear in supporting documentation, 10 * and that the name of IBM not be used in advertising or 11 * publicity pertaining to distribution of the software without 12 * specific, written prior permission. 13 * 14 * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES 15 * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT 16 * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF 18 * THIRD PARTY RIGHTS. THE ENTIRE RISK AS TO THE QUALITY AND 19 * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT 20 * OR MAINTAIN, BELONGS TO THE LICENSEE. SHOULD ANY PORTION OF 21 * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES 22 * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION. IN 23 * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR 24 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING 25 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF 26 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 27 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 28 * SOFTWARE. 29 */ 30 #ifndef UTIL_H 31 #define UTIL_H 32 #include "types.h" 33 34 #ifndef boolean 35 typedef int boolean; 36 #endif 37 38 #ifndef TRUE 39 #define TRUE (1) 40 #endif 41 42 #ifndef FALSE 43 #define FALSE (0) 44 #endif 45 46 /***================================================================***/ 47 /* Portable definitions for 2's complement machines. 48 * NOTE: These really should be based on PostScript types, 49 * for example, sizeof(ps_integer), or sizeof(ps_unsigned) 50 */ 51 #define MAX_ULONG (~(ULONG)(0)) 52 /* This code is portable, assuming K&R C and 2's complement arithmetic */ 53 #define MAX_INTEGER \ 54 ((LONG)((((ULONG) 1)<<(sizeof(ULONG)*8-1))-1)) 55 #define MIN_INTEGER ((-MAX_INTEGER)-1) 56 57 #define MAX_ARRAY_CNT (65535) 58 #define MAX_DICT_CNT (65535) 59 #define MAX_STRING_LEN (65535) 60 #define MAX_NAME_LEN (128) 61 62 /* this is the size of memory allocated for reading fonts */ 63 64 #define VM_SIZE (50*1024) 65 /***================================================================***/ 66 67 #ifndef TYPE1_MIN 68 #define TYPE1_MIN(a,b) (((a)<(b)) ? a : b ) 69 #endif 70 71 /***================================================================***/ 72 /* Routines for managing virtual memory */ 73 /***================================================================***/ 74 extern boolean vm_init(); 75 extern LONG vm_free; 76 extern LONG vm_size; 77 extern char *vm_next; 78 extern char *vm_alloc(); 79 /***================================================================***/ 80 /* Macros for managing virtual memory */ 81 /***================================================================***/ 82 #define vm_next_byte() (vm_next) 83 #define vm_free_bytes() (vm_free) 84 #define vm_avail(B) (B <= vm_free) 85 86 87 88 /***================================================================***/ 89 /* Types of PostScript objects */ 90 /***================================================================***/ 91 #define OBJ_INTEGER (0) 92 #define OBJ_REAL (1) 93 #define OBJ_BOOLEAN (2) 94 #define OBJ_ARRAY (3) 95 #define OBJ_STRING (4) 96 #define OBJ_NAME (5) 97 #define OBJ_FILE (6) 98 #define OBJ_ENCODING (7) 99 100 /***================================================================***/ 101 /* Value of PostScript objects */ 102 /***================================================================***/ 103 typedef union ps_value { 104 char *valueP; /* value pointer for unspecified type */ 105 int value; /* value for unspecified type */ 106 int integer; /* when type is OBJ_INTEGER */ 107 float real; /* when type is OBJ_REAL */ 108 int boolean; /* when type is OBJ_BOOLEAN */ 109 struct ps_obj *arrayP; /* when type is OBJ_ARRAY */ 110 unsigned char *stringP; /* when type is OBJ_STRING */ 111 char *nameP; /* when type is OBJ_NAME */ 112 FILE *fileP; /* when type is OBJ_FILE */ 113 } psvalue; 114 115 /***================================================================***/ 116 /* Definition of a PostScript object */ 117 /***================================================================***/ 118 typedef struct ps_obj { 119 char type; 120 char unused; 121 unsigned short len; 122 union ps_value data; 123 } psobj; 124 125 /***================================================================***/ 126 /* Definition of a PostScript Dictionary Entry */ 127 /***================================================================***/ 128 typedef struct ps_dict { 129 psobj key; 130 psobj value; 131 } psdict; 132 133 /***================================================================***/ 134 /* Macros for testing type of PostScript objects */ 135 /***================================================================***/ 136 #define objIsInteger(o) ((o).type == OBJ_INTEGER) 137 #define objIsReal(o) ((o).type == OBJ_REAL) 138 #define objIsBoolean(o) ((o).type == OBJ_BOOLEAN) 139 #define objIsArray(o) ((o).type == OBJ_ARRAY) 140 #define objIsString(o) ((o).type == OBJ_STRING) 141 #define objIsName(o) ((o).type == OBJ_NAME) 142 #define objIsFile(o) ((o).type == OBJ_FILE) 143 144 /***================================================================***/ 145 /* Macros for setting type of PostScript objects */ 146 /***================================================================***/ 147 #define objSetInteger(o) ((o).type = OBJ_INTEGER) 148 #define objSetReal(o) ((o).type = OBJ_REAL) 149 #define objSetBoolean(o) ((o).type = OBJ_BOOLEAN) 150 #define objSetArray(o) ((o).type = OBJ_ARRAY) 151 #define objSetString(o) ((o).type = OBJ_STRING) 152 #define objSetName(o) ((o).type = OBJ_NAME) 153 #define objSetFile(o) ((o).type = OBJ_FILE) 154 155 /***================================================================***/ 156 /* Macros for testing type of PostScript objects (pointer access) */ 157 /***================================================================***/ 158 #define objPIsInteger(o) ((o)->type == OBJ_INTEGER) 159 #define objPIsReal(o) ((o)->type == OBJ_REAL) 160 #define objPIsBoolean(o) ((o)->type == OBJ_BOOLEAN) 161 #define objPIsArray(o) ((o)->type == OBJ_ARRAY) 162 #define objPIsString(o) ((o)->type == OBJ_STRING) 163 #define objPIsName(o) ((o)->type == OBJ_NAME) 164 #define objPIsFile(o) ((o)->type == OBJ_FILE) 165 166 /***================================================================***/ 167 /* Macros for setting type of PostScript objects (pointer access) */ 168 /***================================================================***/ 169 #define objPSetInteger(o) ((o)->type = OBJ_INTEGER) 170 #define objPSetReal(o) ((o)->type = OBJ_REAL) 171 #define objPSetBoolean(o) ((o)->type = OBJ_BOOLEAN) 172 #define objPSetArray(o) ((o)->type = OBJ_ARRAY) 173 #define objPSetString(o) ((o)->type = OBJ_STRING) 174 #define objPSetName(o) ((o)->type = OBJ_NAME) 175 #define objPSetFile(o) ((o)->type = OBJ_FILE) 176 177 /***================================================================***/ 178 /* Entry point for Type1Char to get entry from CharStrings */ 179 /***================================================================***/ 180 extern psobj *GetType1CharString(); 181 182 #endif 183