1 /* 2 ************************************************************************ 3 File chelp.h 4 5 6 Tab size: 4 (all tabs converted to spaces) 7 Max line length: 72 8 Programmer: Volker Kuhlmann 9 10 11 DESCRIPTION: 12 13 General useful definitions for the C language, like TRUE, BITAND, etc., 14 or mnemonic names for basic C operators. 15 16 17 CONDITIONALS: 18 ANSIEXT Required for ANSI extensions (currently only 19 types XINT64, llword) 20 21 NO_USHORTINTLONG Inhibits typedefs for ushort, uint, ulong 22 WANT_USHORTINTLONG Forces " 23 (default is to guess) 24 25 LINUX_GCC Required when compiling with Linux gcc 26 (SOLARIS_GCC " with Solaris gcc) 27 (SOLARIS_CC " with Solaris cc) 28 MSDOS_BC " with MSDOS Borland C (3.1 as of now) 29 30 various Predefined by various compilers with various 31 cmd line options 32 33 34 HISTORY: 35 36 3.48 18 Jan 06 Fixed [SU]INT32 (long is 8 bytes on AMD64) 37 3.47 21 Feb 99 Added __alpha checks from Bart Warmerdam <bartw@xs4all.nl>. 38 3.46 26 May 98 HAS_DISENABLED. 39 3.45 02 May 98 Split up a long #define - Borland C is a little limited. 40 3.44 17 Feb 98 Commented. 41 3.43 04 Dec 97 Added EITHEROR. 42 3.42 30 Nov 97 Made WAIT_FOREVER require (). Scattered a few more #ifdefs. 43 Commented assert() with fixed sizes. 44 3.4 26 Nov 97 Added typedefs UINT.., SINT.. 45 3.31 28 Jul 97 Comments. 46 3.3 11 Jul 97 Renamed SET/CLRBITS to ASET/ACLRBITS, new SET/CLRBITS. 47 3.21 04 Jul 97 Commented more; more #defines. 48 3.2 02 Jul 97 Renamed SPACE to CHR_SPACE. Added more HAS_xxx. Took out 49 types lint, ulint which were a bit silly. 50 3.12 01 Jul 97 Added HAS_BOOL 51 3.1 03 Feb 97 Added conditionals SOLARIS_GCC, SOLARIS_CC, MSDOS_BC, 52 then ignoring them and using builtin stuff instead; 53 NO_UNSIGNED 54 3.04 29 Jan 97 Added conditional ANSIEXT; REPEAT, UNTIL. 55 3.03 28 Jan 97 Changed comments. 56 3.02 26 Jan 97 Added lint, ulint. Slightly reorganised. 57 3.0 21 Jan 97 Changed name to chelp.h, because cdefs.h is used by gcc. 58 Commented more. 59 2.12 28 Mar 96 Added conditional GCC. 60 2.1 09 Mar 96 Added SETBITS, CLRBITS. 61 2.01 01 Mar 96 Added comments to mnemonical data types. 62 2.0 15 Feb 96 Commented, mnemonical data types are now typedef's. 63 1.92 25 Feb 95 Added SPACE. 64 1.9 09 Feb 95 Changed AAND to ABITAND, AOR to ABITOR, AXOR to ABITXOR. 65 1.8 24 Aug 94 Added ENABLED / DISABLED. 66 1.7 11 Aug 94 Added BITINV. 67 1.6 09 Aug 94 Added WAITFOR. 68 1.4 28 Jul 94 Changed almost everything. 69 1.1 08 Jul 94 Modified. 70 1.0 06 Jul 94 Created out of a few other files. Added a few things. 71 72 ************************************************************************ 73 */ 74 75 76 #ifndef CHELP_H 77 #define CHELP_H 78 79 80 /* Mnemonics for logical and bit-wise operators 81 */ 82 #define NOT ! 83 #define AND && 84 #define OR || 85 #define LOGNOT ! 86 #define LOGAND && 87 #define LOGOR || 88 #define BITINV ~ 89 #define BITNOT ~ 90 #define BITAND & 91 #define BITOR | 92 #define BITXOR ^ 93 #define ABITAND &= 94 #define ABITOR |= 95 #define ABITXOR ^= 96 97 #define EITHEROR(cond1,cond2) (((cond1) != 0) BITXOR ((cond2) != 0)) 98 /* evaluates arguments only once */ 99 100 101 /* 102 Shortcuts for unsigned short, int, long 103 These are a hassle - it's best not to use them. There is no way 104 to find out whether they are defined already, so we guess. If the 105 guess fails, overide with NO_USHORTINTLONG or WANT_USHORTINTLONG. 106 107 Linux gcc: 108 always typedefs these (and defines _LINUX_TYPES_H) 109 Solaris gcc 2.7.2: 110 defines __GNUC__ (without -traditional), 111 __STRICT_ANSI__ (with -ansi); 112 unistd.h typedefs these (and defines _UNISTD_H). 113 Solaris cc SC4.0 18 Oct 1995 C 4.0: 114 defines __STDC__ = 1 for strict conformance; 115 unistd.h typedefs these (and defines _UNISTD_H) 116 Borland C: 117 defines __TURBOC__, __BORLANDC__ 118 typedefs these? 119 TI TMS320C3x: 120 ? 121 */ 122 #define GUESS1__ \ 123 NOT (defined(LINUX_GCC) OR defined(_LINUX_TYPES_H)) \ 124 AND defined(__GNUC__) \ 125 AND defined(__STRICT_ANSI__) \ 126 AND NOT defined(_UNISTD_H) 127 #define GUESS2__ \ 128 (__STDC__-0 == 1) \ 129 AND NOT defined(__GNUC__) \ 130 AND NOT defined(_UNISTD_H) 131 #define USHORTINTLONG_GUESS__ ( \ 132 GUESS1__ \ 133 OR \ 134 GUESS2__ \ 135 OR \ 136 (defined(MSDOS_BC) OR defined(__TURBOC__)) \ 137 ) 138 #if defined (WANT_USHORTINTLONG) \ 139 OR (NOT defined(NO_USHORTINTLONG) AND USHORTINTLONG_GUESS__) 140 #define HAS_USHORTINTLONG 141 typedef unsigned short ushort; 142 typedef unsigned int uint; 143 typedef unsigned long ulong; 144 #endif 145 146 147 /* 148 Shortcut for unsigned char 149 Does not seem to clash with any compiler / system 150 */ 151 #ifndef HAS_UCHAR 152 #define HAS_UCHAR 153 typedef unsigned char uchar; 154 #endif 155 156 157 /* Shortcuts for common data types (size is compiler dependent) 158 */ 159 #ifndef HAS_STRING 160 #define HAS_STRING 161 typedef char string; 162 #endif 163 164 165 /* Data types with fixed sizes (independent of compiler) 166 */ 167 #ifndef HAS_FIXEDSIZES 168 #define HAS_FIXEDSIZES 169 typedef unsigned char UINT8, byte; /* 8 bits */ 170 typedef unsigned short UINT16, dbyte, word; /* 16 bits */ 171 #if defined(__alpha) OR defined(__x86_64__) 172 typedef unsigned int UINT32, 173 qbyte, dword, lword; /* 32 bits */ 174 #else 175 typedef unsigned long UINT32, 176 qbyte, dword, lword; /* 32 bits */ 177 #endif 178 179 typedef signed char SINT8; /* 8 bits signed */ 180 typedef signed short SINT16; /* 16 bits signed */ 181 #if defined(__alpha) OR defined(__x86_64__) 182 typedef signed int SINT32; /* 32 bits signed */ 183 #else 184 typedef signed long SINT32; /* 32 bits signed */ 185 #endif 186 187 #ifdef ANSIEXT 188 #ifdef __alpha 189 typedef unsigned long UINT64, llword; /* 64 bits */ 190 typedef signed long SINT64; /* 64 bits signed */ 191 #else 192 typedef unsigned long long UINT64, llword; /* 64 bits */ 193 typedef signed long long SINT64; /* 64 bits signed */ 194 #endif 195 #endif 196 /* check the sizes here? then we would depend on limits.h 197 better to require the user to use assert(): 198 assert (sizeof(UINT8) == 1); 199 assert (sizeof(UINT16) == 2); 200 assert (sizeof(UINT32) == 4); 201 assert (sizeof(SINT8) == 1); 202 assert (sizeof(SINT16) == 2); 203 assert (sizeof(SINT32) == 4); 204 assert (sizeof(UINT64) == 8); 205 assert (sizeof(SINT64) == 8); 206 */ 207 #endif 208 209 210 /* Mnemonical data types 211 It should be possible to choose (int) for these, in case sizeof(enum) < 212 sizeof(int). Essential for GNU getopt(). 213 */ 214 #ifndef HAS_BOOL 215 #define HAS_BOOL 216 typedef enum {FALSE = 0, TRUE = !0} BOOL; 217 /* Note: all values != FALSE count as TRUE. 218 Always compare with FALSE! */ 219 #endif 220 221 #ifndef HAS_OFFON 222 #define HAS_OFFON 223 typedef enum {OFF, ON = NOT OFF} OFFON; 224 /* Note: all values != OFF count as ON. 225 Always compare with OFF, never ever ever with ON! */ 226 #endif 227 228 #ifndef HAS_PASSFAIL 229 #define HAS_PASSFAIL 230 typedef enum {PASS, FAIL = NOT PASS} PASSFAIL; 231 /* Note: only the values PASS and FAIL are legal in this type!!! 232 Must compare with either PASS or FAIL. 233 Do not assume either PASS or FAIL are 0 or 1 or -1 or anything!! 234 I.e. do not compare with 0!! */ 235 #endif 236 237 #ifndef HAS_DISENABLED 238 #ifndef DISABLED 239 #define DISABLED 0 240 #endif 241 #ifndef ENABLED 242 #define ENABLED (NOT DISABLED) 243 #endif 244 #endif 245 246 247 /* Mnemonics for control flow 248 */ 249 #define WAIT_FOREVER() for (;;){} 250 #define FOREVER while (TRUE) 251 #define WAITFOR(cond) while (NOT((cond))) 252 #define REPEAT do { 253 #define UNTIL(cond) } while (NOT((cond))) 254 255 256 /* Handling bits in hardware registers 257 Bits set in the bit field will be set/cleared in the register. 258 */ 259 /* use: xxxBITS (register, bit field); */ 260 #define SETBITS(reg,bits) ((reg)) ABITOR ((bits)) 261 #define CLRBITS(reg,bits) ((reg)) ABITAND (BITINV ((bits))) 262 263 /* use: hw_register = AxxxBITS (bit field); */ 264 #define ASETBITS(bits) ABITOR (bits) 265 #define ACLRBITS(bits) ABITAND (BITINV (bits)) 266 267 268 /* ASCII Character names 269 */ 270 /* these (all 34; 0-32, 127) should prob go into a separate file */ 271 #if 0 272 #ifndef HAS_CHARNAMES 273 #define HAS_CHARNAMES 274 #define CHR_NUL '\x00' 275 #define CHR_BEL '\x07' 276 #define CHR_BS '\x08' 277 #define CHR_HT '\x09' 278 #define CHR_NL '\x0a' 279 #define CHR_LF '\x0a' 280 #define CHR_VT '\x0b' 281 #define CHR_NP '\x0c' 282 #define CHR_CR '\x0d' 283 #define CHR_ESC '\x1b' 284 #define CHR_SPC '\x20' 285 #define CHR_DEL '\x7f' 286 #define Ctrl(letter) ((char) (letter) >= 'a' ? \ 287 (letter) - '`' : (letter) - '@') 288 #endif 289 #endif 290 291 292 #endif /* #ifndef CHELP_H */ 293 294 /* EOF chelp.h */ 295 /**********************************************************************/ 296