summaryrefslogtreecommitdiff
path: root/includes/common.h
blob: 9ea51fb8cc769d8cec12cf0612985d8333ec9a53 (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
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
#ifndef ROOT_COMMON_H
#define ROOT_COMMON_H

/*
 * Common imports and Mac OS types
 */
#include <ctype.h>
#include <float.h>
#include <setjmp.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#ifdef __MWERKS__
#define macintosh
#define CW_PASCAL pascal
#undef toupper
#undef tolower

// What the fuck is this haha
// typedef char * va_list;
#define va_start(a,b) (a = ((va_list) __builtin_next_arg(b)))
#define va_arg(a,b) (*(b *) (void *) ((a = (char *) (((((unsigned long)(a)) + ((__alignof__ (b) == 16) ? 15 : 3)) & ~((__alignof__ (b) == 16) ? 15 : 3)) + ((sizeof (b) + 3) & ~3))) - ((sizeof (b) + 3) & ~3)))
#define va_end(a) ((void)0)

#define alloca(x) __alloca(x)

#define CW_INLINE inline

#else
#include <stdarg.h>
// expand this to nothing
#define CW_PASCAL

#define CW_INLINE static inline
#endif

// ----------
// MacTypes.h
#ifdef __MWERKS__
typedef unsigned char UInt8;
typedef char SInt8;
typedef unsigned short UInt16;
typedef short SInt16;
typedef unsigned long UInt32;
typedef long SInt32;
typedef unsigned long long UInt64;
typedef long long SInt64;

typedef long Size;
#else
typedef uint8_t UInt8;
typedef int8_t SInt8;
typedef uint16_t UInt16;
typedef int16_t SInt16;
typedef uint32_t UInt32;
typedef int32_t SInt32;
typedef uint64_t UInt64;
typedef int64_t SInt64;

typedef int32_t Size;
#endif

typedef char *Ptr;
typedef Ptr *Handle;

typedef SInt16 OSErr;
typedef SInt32 OSStatus;
typedef SInt16 ScriptCode;
typedef UInt32 FourCharCode;
typedef FourCharCode OSType;
typedef FourCharCode ResType;
typedef OSType *OSTypePtr;
typedef ResType *ResTypePtr;

typedef uint8_t Boolean;

enum {
    noErr = 0,
    abortErr = -27,
    nsvErr = -35,
    ioErr = -36,
    bdNamErr = -37,
    eofErr = -39,
    tmfoErr = -42,
    fnfErr = -43, // file not found
    dupFNErr = -48, // duplicate filename
    paramErr = -50,
    rfNumErr = -51,
    permErr = -54,
    memFullErr = -108, // not enough memory
    nilHandleErr = -109, // pointer was nil
    memLockedErr = -117,
    dirNFErr = -120,
    userCanceledErr = -128,
    inputOutOfBounds = -190,
    resNotFound = -192, // resource not found
    resFNotFound = -193, // resource file not found
    addResFailed = -194, // AddResource failed
    rmvResFailed = -196, // RmveResource failed
    resAttrErr = -198, // inconsistent attribute
    mapReadErr = -199, // map inconsistent with operation
    notAFileErr = -1302,
    fsDataTooBigErr = -1310
};
enum { kNilOptions = 0 };
enum { kUnknownType = 0x3F3F3F3F };

// Pascal strings
typedef unsigned char Str255[256];
typedef unsigned char Str63[64];
typedef unsigned char *StringPtr;
typedef const unsigned char *ConstStringPtr;
typedef const unsigned char *ConstStr63Param;
typedef const unsigned char *ConstStr255Param;
// XXX: MacTypes.h defines StrLength() which is an inline for C++ and a macro for C
// This might be useful?

#ifdef __MWERKS__
#pragma options align=mac68k
#endif
typedef struct Point {
    SInt16 v, h;
} Point;

typedef struct Rect {
    SInt16 top, left, bottom, right;
} Rect;

// -------
// Files.h
enum {
    fsCurPerm = 0x00,
    fsRdPerm = 0x01,
    fsWrPerm = 0x02,
    fsRdWrPerm = 0x03,
    fsRdWrShPerm = 0x04,
    fsRdDenyPerm = 0x10,
    fsWrDenyPerm = 0x20
};
enum {
    fsAtMark = 0,
    fsFromStart = 1,
    fsFromLEOF = 2,
    fsFromMark = 3
};
enum {
    fsRtParID = 1,
    fsRtDirID = 2
};
enum {
    ioDirMask = 0x10
};
enum {
    kIsAlias = 0x8000
};

typedef struct FSSpec {
    SInt16 vRefNum;
    SInt32 parID;
    Str255 name;
} FSSpec;

typedef struct FInfo {
    OSType fdType;
    OSType fdCreator;
    UInt16 fdFlags;
    Point fdLocation;
    SInt16 fdFldr;
} FInfo;

typedef struct FXInfo {
    SInt16 fdIconID;
    SInt16 fdUnused[3];
    SInt8 fdScript;
    SInt8 fdXFlags;
    SInt16 fdComment;
    SInt32 fdPutAway;
} FXInfo;

typedef struct DInfo {
    Rect frRect;
    SInt16 frFlags;
    Point frLocation;
    SInt16 frView;
} DInfo;

typedef struct DXInfo {
    Point frScroll;
    SInt32 frOpenChain;
    SInt16 frUnused;
    SInt16 frComment;
    SInt32 frPutAway;
} DXInfo;

typedef struct IOParam {
    OSErr ioResult;
    SInt16 ioRefNum;
    char *ioBuffer;
    SInt32 ioReqCount;
    SInt32 ioActCount;
    SInt16 ioPosMode;
    SInt32 ioPosOffset;
} IOParam;

typedef union ParamBlockRec {
    IOParam ioParam;
} ParamBlockRec;
typedef ParamBlockRec *ParmBlkPtr;

typedef struct HFileParam {
    void *qLink;
    SInt16 qType;
    SInt16 ioTrap;
    Ptr ioCmdAddr;
    void *ioCompletion;
    SInt16 ioResult;
    StringPtr ioNamePtr;
    SInt16 ioVRefNum;
    SInt16 ioFRefNum;
    SInt8 ioFVersNum;
    SInt8 filler1;
    SInt16 ioFDirIndex;
    SInt8 ioFlAttrib;
    SInt8 ioFlVersNum;
    FInfo ioFlFndrInfo;
    SInt32 ioDirID;
    UInt16 ioFlStBlk;
    SInt32 ioFlLgLen;
    SInt32 ioFlPyLen;
    UInt16 ioFlRStBlk;
    SInt32 ioFlRLgLen;
    SInt32 ioFlRPyLen;
    UInt32 ioFlCrDat;
    UInt32 ioFlMdDat;
} HFileParam;

typedef union HParamBlockRec {
    HFileParam fileParam;
} HParamBlockRec;
typedef HParamBlockRec *HParmBlkPtr;

typedef struct HFileInfo {
    void *qLink;
    SInt16 qType;
    SInt16 ioTrap;
    Ptr ioCmdAddr;
    void *ioCompletion;
    SInt16 ioResult;
    StringPtr ioNamePtr;
    SInt16 ioVRefNum;
    SInt16 ioFRefNum;
    SInt8 ioFVersNum;
    SInt8 filler1;
    SInt16 ioFDirIndex;
    SInt8 ioFlAttrib;
    SInt8 ioACUser;
    FInfo ioFlFndrInfo;
    SInt32 ioDirID;
    UInt16 ioFlStBlk;
    SInt32 ioFlLgLen;
    SInt32 ioFlPyLen;
    UInt16 ioFlRStBlk;
    SInt32 ioFlRLgLen;
    SInt32 ioFlRPyLen;
    UInt32 ioFlCrDat;
    UInt32 ioFlMdDat;
    UInt32 ioFlBkDat;
    FXInfo ioFlXFndrInfo;
    SInt32 ioFlParID;
    SInt32 ioFlClpSiz;
} HFileInfo;
typedef struct DirInfo {
    void *qLink;
    SInt16 qType;
    SInt16 ioTrap;
    Ptr ioCmdAddr;
    void *ioCompletion;
    SInt16 ioResult;
    StringPtr ioNamePtr;
    SInt16 ioVRefNum;
    SInt16 ioFRefNum;
    SInt8 ioFVersNum;
    SInt8 filler1;
    SInt16 ioFDirIndex;
    SInt8 ioFlAttrib;
    SInt8 ioACUser;
    DInfo ioDrUsrWds;
    SInt32 ioDrDirID;
    UInt16 ioDrNmFls;
    SInt16 filler3[9];
    UInt32 ioDrCrDat;
    UInt32 ioDrMdDat;
    UInt32 ioDrBkDat;
    DXInfo ioDrFndrInfo;
    SInt32 ioDrParID;
} DirInfo;

typedef union CInfoPBRec {
    HFileInfo hFileInfo;
    DirInfo hDirInfo;
} CInfoPBRec;
typedef CInfoPBRec *CInfoPBPtr;

#ifdef __MWERKS__
#pragma options align=reset
#endif

#endif