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
|
/* xos.h
**/
#ifndef os_h
#define os_h
#if HAVE_CONFIG_H
#include <conf.h>
#endif
#include "longlong.h"
#ifndef NULL
#define NULL 0
#endif
#ifdef __STDC__
#include <stdarg.h>
#define PROTOTYPE(X) X
#else
#include <varargs.h>
#define PROTOTYPE(X) ( )
#endif
#if HAVE_STRING_H
#include <string.h>
#else
char *strchr();
char *strrchr();
char *strcpy();
char *strncpy();
int strlen();
void *memset();
#endif
#ifndef HAVE_STRCHR
#define strchr index
#define strrchr rindex
#endif
#ifndef HAVE_MEMCPY
#ifndef memcpy
#define memcpy(d, s, n) bcopy ((s), (d), (n))
#endif
#ifndef memmove
#define memmove(d, s, n) bcopy ((s), (d), (n))
#endif
#else
#ifndef bcopy
#define bcopy(s, d, n) memcpy( (d), (s), (n))
#endif
#endif
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#else
void *malloc();
void *calloc();
void *realloc();
void free();
#endif
#define Min(x, y) (((x) < (y)) ? (x) : (y))
#define Max(x, y) (((x) > (y)) ? (x) : (y))
#define Clip(min, max, val) (((val) < (min) ) ? (min) : \
((val) > (max) ) ? (max) : (val) )
#define Abs(xx) (((xx) > 0) ? (xx) : -(xx) )
#ifdef MSDOS
#define sleep SAOSleep
#endif
#ifdef __GNU_C__
#define INLINE inline
#else
#define INLINE
#endif
#define New(space, thing) Calloc(space, sizeof(thing))
#ifndef NewString
#define NewString(space, str) (( str == NULL ) \
? NULL \
: strcpy(Malloc(space, strlen(str) + 1) \
, str))
#endif
#ifdef _EXCEPT_H
extern exception ex_malloc;
#define MEMEX(exc, space) , ((space) ? (space) : \
( except(exc, "cannot allocate %s line %d", __FILE__, __LINE__) \
, space))
#else
#define MEMEX(exc, space)
#endif
#ifdef DEBUG
#define Malloc(space, size) ( ((space) = (void *) malloc(size)) \
, printf("malloc : 0x%09lx %10d bytes - " #space "\n" \
, space, size) \
, space)
#define Calloc(space, size) ( ((space) = (void *) malloc(size)) \
, printf("calloc : 0x%09lx %10d bytes - " #space "\n"\
, space, size) \
, memset(space, 0, size) \
, space)
#define Free(space) ( space != NULL ? \
printf("free : 0x%09lx - " #space "\n", space) \
, free((char *) space), (int) (space = NULL) \
: printf("free : (null)\n"), (void *) NULL )
#define ReAlloc(space, size) ( space != NULL ? \
printf("relloc : 0x%09lx %10d bytes - " #space "\n" \
, ((space) = (void *) realloc((void*)space, size)) \
, size), (void *) space \
: (void *) Malloc(space, size) )
#define D(args) printf args
#else
#define Malloc(space, size) ( (space) = (void *) calloc(size, 1) MEMEX(ex_malloc, space) )
#define ReAlloc(space, size) ( space ? \
(void *)(((space) = (void *) realloc((void*)space, size)) \
MEMEX(ex_malloc, space)) \
: (void *) Malloc(space, size) )
#define Calloc(space, size) ( Malloc(space, size), memset(space, 0, size), space )
#define Free(space) ( space ? ( free((char *) space), (void *)(space = NULL)) \
: (void *) NULL )
#define D(args)
#endif
#ifdef TYPES
typedef double real;
typedef int bool;
typedef struct _complex {
double r;
double i;
} complex;
typedef bool (*bfunct) ();
typedef short (*sfunct) ();
typedef int (*ifunct) ();
typedef longlong (*lfunct) ();
typedef real (*rfunct) ();
typedef double (*dfunct) ();
typedef complex (*xfunct) ();
#endif
#define MIN_normal 0.99e-306
#define MAX_normal 0.99e306
/* Types.h
**
** Data type constants
**/
#ifndef INDEFS
#define INDEFS (-32767)
#endif
#ifndef INDEFL
#define INDEFL ((unsigned long) 0x80000001)
#endif
#ifndef INDEFI
#define INDEFI INDEFL
#endif
#ifndef INDEFR
#define INDEFR 1.6e38
#endif
#ifndef INDEFD
#define INDEFD 1.6e308
#endif
#ifndef INDEF
#define INDEF INDEFR
#endif
#define TY_CHAR 0
#define TY_SHORT 1
#define TY_INT 2
#define TY_LONG 3
#define TY_REAL 4
#define TY_DOUBLE 5
#define TY_UCHAR 6
#define TY_USHORT 7
#define TY_UINT 8
#define TY_ULONG 9
#define SZ_CHAR 1
#define SZ_SHORT 2
#define SZ_INT 4
#define SZ_LONG 8
#define SZ_REAL 4
#define SZ_DOUBLE 8
#define X__PI 3.14159265358979323846
#define X_2PI ( 2 * X__PI )
#define X_R2D (X_2PI / 360.0)
#define X_R2H (X_2PI / 24.0)
#define X_H2D (360.0 / 24.0)
#define r2h(r) ( (r) / X_R2H )
#define h2r(d) ( (d) * X_R2H )
#define r2d(r) ( (r) / X_R2D )
#define d2r(d) ( (d) * X_R2D )
#define h2d(r) ( (r) * X_H2D )
#define d2h(d) ( (d) / X_H2D )
#endif
#define DPrint(X) EPrint X
#define XPrint(X)
/* end os_h */
|