-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathglobal.h
312 lines (272 loc) · 8.04 KB
/
global.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#ifndef _GLOBAL_H
#define _GLOBAL_H
#include <stdlib.h>
#include <string.h>
/* Global definitions used by every source file.
* Some may be compiler dependent.
*
* This file depends only on internal macros or those defined on the
* command line, so it may be safely included first.
*/
#if !defined(AMIGA) && (defined(MAC) || defined(MSDOS))
/* These compilers require special open modes when reading binary files.
*
* "The single most brilliant design decision in all of UNIX was the
* choice of a SINGLE character as the end-of-line indicator" -- M. O'Dell
*
* "Whoever picked the end-of-line conventions for MS-DOS and the Macintosh
* should be shot!" -- P. Karn's corollary to O'Dell's declaration
*/
#define READ_BINARY "rb"
#define WRITE_BINARY "wb"
#define APPEND_BINARY "ab+"
#define READ_TEXT "rt"
#define WRITE_TEXT "wt"
#define APPEND_TEXT "at+"
#else
#define READ_BINARY "r"
#define WRITE_BINARY "w"
#define APPEND_BINARY "a+"
#define READ_TEXT "r"
#define WRITE_TEXT "w"
#define APPEND_TEXT "a+"
#endif
#include <sys/types.h>
#ifndef HAVE_STDINT
/* These two lines assume that your compiler's longs are 32 bits and
* shorts are 16 bits. It is already assumed that chars are 8 bits,
* but it doesn't matter if they're signed or unsigned.
*/
typedef long int32; /* 32-bit signed integer */
typedef unsigned int uint; /* 16 or 32-bit unsigned integer */
typedef unsigned long uint32; /* 32-bit unsigned integer */
typedef unsigned short uint16; /* 16-bit unsigned integer */
typedef unsigned char byte_t; /* 8-bit unsigned integer */
typedef unsigned char uint8; /* 8-bit unsigned integer */
typedef unsigned long long uint64; /* 64-bit unsigned integer */
#define MAXINT16 0xffff /* Largest 16-bit integer */
#define MAXINT32 0xffffffff /* Largest 32-bit integer */
#define NBBY 8 /* 8 bits/byte */
#define __SZPTR 9 /* Number of characters in a '%p' output */
#define __PRPTR "%-9p"
#define __FWPTR "%-9s"
#define PRIu32 "ul"
#else
#include <stdint.h>
#include <limits.h>
#include <inttypes.h>
typedef int32_t int32; /* 32-bit signed integer */
typedef unsigned int uint; /* 16 or 32-bit unsigned integer */
typedef uint32_t uint32; /* 32-bit unsigned integer */
typedef uint16_t uint16; /* 16-bit unsigned integer */
typedef uint8_t byte_t; /* 8-bit unsigned integer */
typedef uint8_t uint8; /* 8-bit unsigned integer */
typedef uint64_t uint64; /* 64-bit unsigned integer */
#define MAXINT16 UINT16_MAX /* Largest 16-bit integer */
#define MAXINT32 UINT32_MAX /* Largest 32-bit integer */
#ifndef NBBY
#define NBBY CHAR_BIT /* Number of bits per byte */
#endif
#ifdef __LP64__
#define __SZPTR 18 /* Number of characters in a '%p' output */
#define __PRPTR "%-18p"
#define __FWPTR "%-18s"
#else
#define __SZPTR 10 /* Number of characters in a '%p' output */
#define __PRPTR "%-10p"
#define __FWPTR "%-10s"
#endif
#endif
#define HASHMOD 7 /* Modulus used by hash_ip() function */
/* The "interrupt" keyword is non-standard, so make it configurable */
#if defined(__TURBOC__) && defined(MSDOS)
#define INTERRUPT void interrupt
#else
#define INTERRUPT void
#endif
/* Note that these definitions are on by default if none of the Turbo-C style
* memory model definitions are on; this avoids having to change them when
* porting to 68K environments.
*/
#if !defined(__TINY__) && !defined(__SMALL__) && !defined(__MEDIUM__) && !defined(__GNUC__)
#define LARGEDATA 1
#endif
#if !defined(__TINY__) && !defined(__SMALL__) && !defined(__COMPACT__) && !defined(__GNUC__)
#define LARGECODE 1
#endif
/* Since not all compilers support structure assignment, the ASSIGN()
* macro is used. This controls how it's actually implemented.
*/
#ifdef NOSTRUCTASSIGN /* Version for old compilers that don't support it */
#define ASSIGN(a,b) memcpy((char *)&(a),(char *)&(b),sizeof(b);
#else /* Version for compilers that do */
#define ASSIGN(a,b) ((a) = (b))
#endif
/* Define null object pointer in case stdio.h isn't included */
#ifndef NULL
/* General purpose NULL pointer */
#define NULL 0
#endif
/* standard boolean constants */
#define FALSE 0
#define TRUE 1
#define NO 0
#define YES 1
#define CTLA 0x1
#define CTLB 0x2
#define CTLC 0x3
#define CTLD 0x4
#define CTLE 0x5
#define CTLF 0x6
#define CTLG 0x7
#define CTLH 0x8
#define CTLI 0x9
#define CTLJ 0xa
#define CTLK 0xb
#define CTLL 0xc
#define CTLM 0xd
#define CTLN 0xe
#define CTLO 0xf
#define CTLP 0x10
#define CTLQ 0x11
#define CTLR 0x12
#define CTLS 0x13
#define CTLT 0x14
#define CTLU 0x15
#define CTLV 0x16
#define CTLW 0x17
#define CTLX 0x18
#define CTLY 0x19
#define CTLZ 0x1a
#define BELL CTLG
#define BS CTLH
#define TAB CTLI
#define LF CTLJ
#define FF CTLL
#define CR CTLM
#define XON CTLQ
#define XOFF CTLS
#define ESC 0x1b
#define DEL 0x7f
/* string comparison portability */
#ifdef MODERN_UNIX
#define STRNICMP(a,b,c) strncasecmp((a),(b),(c))
#define STRICMP(a,b) strcasecmp((a),(b))
#else
#define STRNICMP(a,b,c) strnicmp((a),(b),(c))
#define STRICMP(a,b) stricmp((a),(b))
#endif
/* string equality shorthand */
#define STREQ(x,y) (strcmp(x,y) == 0)
/* Extract a short from a long */
#define hiword(x) ((uint16)((x) >> 16))
#define loword(x) ((uint16)(x))
/* Extract a byte from a short */
#define hibyte(x) ((unsigned char)((x) >> 8))
#define lobyte(x) ((unsigned char)(x))
/* Extract nibbles from a byte */
#define hinibble(x) (((x) >> 4) & 0xf)
#define lonibble(x) ((x) & 0xf)
/* Various low-level and miscellaneous functions */
int availmem(void);
#ifndef USE_SYSTEM_MALLOC
void *callocw(unsigned nelem,unsigned size);
#else
#define callocw(nelem,size) calloc((nelem),(size))
#endif
int dirps(void);
#ifndef USE_SYSTEM_MALLOC
void free(void *);
#endif
#define FREE(p) {free(p); p = NULL;}
int kgetopt(int argc,char *argv[],char *opts);
void getrand(unsigned char *buf,int len);
int htob(char c);
int htoi(char *);
int readhex(uint8 *,char *,int);
long htol(char *);
char *inbuf(uint port,char *buf,uint cnt);
uint hash_ip(int32 addr);
int istate(void);
#ifdef UNIX
int enable(void);
int disable(void);
void giveup(void);
#endif
void logmsg(int s,char *fmt, ...);
int ilog2(uint x);
void *htop(const char *);
#ifndef USE_SYSTEM_MALLOC
void *malloc(size_t nb);
void *mallocw(size_t nb);
#else
#define mallocw(nb) malloc((nb))
#endif
int memcnt(const uint8 *buf,uint8 c,int size);
void memxor(uint8 *,uint8 *,unsigned int);
char *outbuf(uint port,char *buf,uint cnt);
int32 rdclock(void);
void restore(int);
void rip(char *);
char *smsg(char *msgs[],unsigned nmsgs,unsigned n);
void stktrace(void);
#if !defined __TURBOC__ && !defined(HAVE_STRDUP)
char *strdup(const char *);
#endif
int urandom(unsigned int n);
int wildmat(char *s,char *p,char **argv);
#ifdef AZTEC
#define krewind(fp) kfseek(fp,0L,0);
#endif
#if defined(__TURBOC__) && defined(MSDOS)
#define movblock(so,ss,do,ds,c) movedata(ss,so,ds,do,c)
#else
/* General purpose function macros already defined in turbo C */
#ifndef min
#define min(x,y) ((x)<(y)?(x):(y)) /* Lesser of two args */
#endif
#ifndef max
#define max(x,y) ((x)>(y)?(x):(y)) /* Greater of two args */
#endif
#ifdef MSDOS
#define MK_FP(seg,ofs) ((void far *) \
(((unsigned long)(seg) << 16) | (unsigned)(ofs)))
#endif
#endif /* __TURBOC __ */
#ifdef AMIGA
/* super kludge de WA3YMH */
#ifndef fileno
#include <stdio.h>
#endif
#define kfclose(fp) amiga_fclose(fp)
extern int amiga_fclose(kFILE *);
extern kFILE *ktmpfile(void);
extern char *ksys_errlist[];
extern int kerrno;
#endif
/* Externals used by getopt */
extern int koptind;
extern char *koptarg;
/* Threshold setting on available memory */
extern int32 Memthresh;
#ifndef HAVE_UNIX_TIMEOFDAY
/* System clock - count of ticks since startup */
extern int32 Clock;
#endif
/* Various useful strings */
extern char Badhost[];
extern char Nospace[];
extern char Notval[];
extern char *Hostname;
extern char Version[];
extern char Whitespace[];
/* Your system's end-of-line convention */
extern char Eol[];
/* Your system OS - set in files.c */
extern char System[];
/* Your system's temp directory */
extern char *Tmpdir;
extern unsigned Nfiles; /* Maximum number of open files */
extern unsigned Nsock; /* Maximum number of open sockets */
extern void (*Gcollect[])();
#endif /* _GLOBAL_H */