summaryrefslogtreecommitdiff
path: root/cmt/cext.h
blob: 665c13df65777088bcd5ae2338a260cf639d1120 (plain)
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
/******************************************************************
*               modified JCD 27 Apr-88 for AMIGA
*      cext.h -- extensions to c to make it more portable
* Copyright 1989 Carnegie Mellon University
*
*******************************************************************

cext must provide the following definitions:

true     -- a  constant
false     -- a boolean constant
private -- defined as static, used to declare local functions
public     -- defined as empty string, used to declare exported functions
boolean -- a new type
byte     -- unsigned 8-bit quantity
ushort     -- unsigned 16-bit quantity
ulong     -- unsigned 32-bit quantity
Pointer -- pointer to char, a generic pointer
ABS()     -- absolute value of any type of number
MAX()     -- maximum of two numbers
MIN()     -- minimum of two numbers
ROUND()	  -- round a double to long		     

NULL     -- pointer to nothing, a constant
EOS      -- end of string, a constant '\0'
MALLOC(x)     -- allocates x bytes
FREE(x)     -- frees something from MALLOC
AVAILMEM     -- tells how much memory is available.
                   (N.B.: no parens, no args.)
EXIT(n)  -- calls exit(n) after shutting down/deallocating resources

*****************************************************************************/

/* CHANGE LOG
 * --------------------------------------------------------------------
 * 28Apr03  dm  many changes for new conditional compilation switches
 * 28Apr03  rbd removed macro redefinitions: min, max
 */

#ifndef CEXT_H
#ifndef SWITCHES
#include "switches.h"
#endif

#include <stdio.h>
#include <string.h>
#include <math.h>

#if HAS_STDLIB_H
#include <stdlib.h>
#endif

#if HAS_SYS_TYPES_H
#include <sys/types.h>
#endif

#if HAS_MALLOC_H
#include <malloc.h>
#endif

#if NEED_ULONG
typedef unsigned long ulong;
#endif

#if NEED_USHORT
typedef unsigned long ushort;
#endif

#if NEED_BYTE
typedef unsigned char byte;
#endif

/* There's a name conflict between true/false as an enum type in
 * Apple #includes:Types.h on the Mac, and true/false as #defined below
 */
#ifndef TRUE
#define TRUE 1
#endif

#ifndef FALSE
#define FALSE 0
#endif

#define private static
#define public

#if NEED_DEFINE_MALLOC
public void *malloc();
#endif

typedef char *Pointer;

#ifdef UNIX_MACH
typedef int boolean;
#else
/* hopefully, unsigned short will save sign extension instructions */
typedef unsigned char boolean;
#endif

#ifndef ABS
#define ABS(a) (((a) > 0) ? (a) : -(a))
#endif
#ifndef MAX
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif

#define MAXULONG 0xffffffff

#ifndef NULL
#define NULL 0L
#endif

#ifndef EOS
#define EOS '\0'
#endif

#define SAFETYBUF    10    /* Safety buffer when allocating memory */
#define BIGGEST_BLOCK    32765    /* Should find a happy medium for this  */

#ifdef MACINTOSH /*DMH: gets AVAILMEM in record.c*/
#include <stddef.h>
#define MALLOC(x)       malloc((size_t)(x))  /*DMH: size_t is ulong, for MAC*/
#define FREE(x)    free((char *)(x))
#define AVAILMEM    MyMaxMem(NULL)/*???*/
#endif

#ifdef LATTICE322
#define MALLOC  malloc
#define FREE    free
#define AVAILMEM    MyMaxMem(NULL)

#else

#ifdef DOS /* was MICROSOFT */
#define MALLOC  malloc
#define FREE    free
#define AVAILMEM MyMaxMem(NULL)
#endif
#endif

#ifdef UNIX
#define MALLOC  malloc
#define FREE     free
#define AVAILMEM     10000000 /* since we have virtual memory, assume 10Mb */
#endif

#ifdef AMIGA
#define MALLOC  malloc
#define FREE    free
#define AVAILMEM     128000
#endif

public ulong MyMaxMem(ushort *);

#ifndef MEM
#include "mem.h"
#endif

#ifndef CLEANUP
#include "cleanup.h"
#endif

#ifdef CMTSTUFF
#define EXIT cmt_exit
public void EXIT(int);
/* don't allow anyone to call exit directly */
#define exit(n) PLEASE_CALL_EXIT_NOT_exit
#else
#define EXIT(n) exit(n)
#endif

#define _cext

#ifndef MALLOC
MALLOC is not defined!
#endif

#define ROUND(x) ((long) ((x) + 0.5))

/* for compatibility */
#ifdef NEED_ROUND
#define round ROUND
#endif

#ifndef min
#define min MIN
#define max MAX
#endif

#define CEXT_H
#endif