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
|
#include "cmdline.h"
Boolean Overlays_Initialize(Overlays *this) {
OvlGroup *grp;
Overlay *ovl;
OvlAddr addr;
SInt32 idx;
#line 24
OPTION_ASSERT(this);
this->groups = NULL;
this->lastgrp = NULL;
this->grpcnt = 0;
addr.hi = 0;
addr.lo = 0;
grp = OvlGroup_New("main_application", addr);
if (!grp)
return 0;
ovl = Overlay_New("MAIN");
if (!ovl)
return 0;
OvlGroup_AddOverlay(grp, ovl, &idx);
#line 42
OPTION_ASSERT(idx==0);
Overlays_AddOvlGroup(this, grp, &idx);
#line 45
OPTION_ASSERT(idx==0);
return 1;
}
Boolean Overlays_Terminate(Overlays *this) {
OvlGroup *grp;
OvlGroup *nxtgrp;
#line 54
OPTION_ASSERT(this);
for (grp = this->groups; grp; grp = nxtgrp) {
nxtgrp = grp->next;
OvlGroup_Delete(grp);
xfree(grp);
}
this->groups = NULL;
return 1;
}
Boolean Overlays_AddOvlGroup(Overlays *this, OvlGroup *grp, SInt32 *grpnum) {
#line 70
OPTION_ASSERT(this);
OPTION_ASSERT(grp);
if (this->groups == NULL)
this->groups = grp;
else
this->lastgrp->next = grp;
this->lastgrp = grp;
if (grpnum)
*grpnum = this->grpcnt;
this->grpcnt++;
return 1;
}
OvlGroup *Overlays_GetOvlGroup(Overlays *this, SInt32 grpnum) {
OvlGroup *grp;
SInt32 cnt = 0;
#line 93
OPTION_ASSERT(this);
grp = this->groups;
while (grp && cnt < grpnum) {
grp = grp->next;
cnt++;
}
if (cnt == grpnum)
return grp;
else
return NULL;
}
SInt32 Overlays_CountGroups(Overlays *this) {
OvlGroup *scan;
int num = 0;
#line 112
OPTION_ASSERT(this);
scan = this->groups;
while (scan) {
scan = scan->next;
num++;
}
return num;
}
Boolean Overlays_AddFileToOverlay(Overlays *this, SInt32 grpnum, SInt32 ovlnum, SInt32 filenum) {
Overlay *oly;
#line 130
OPTION_ASSERT(this);
oly = Overlays_GetOverlayInGroup(this, grpnum, ovlnum);
if (oly)
return Overlay_AddFile(oly, filenum, NULL);
else
return 0;
}
Overlay *Overlays_GetOverlayInGroup(Overlays *this, SInt32 grpnum, SInt32 ovlnum) {
OvlGroup *grp;
#line 144
OPTION_ASSERT(this);
grp = Overlays_GetOvlGroup(this, grpnum);
if (grp)
return OvlGroup_GetOverlay(grp, ovlnum);
else
return NULL;
}
SInt32 Overlays_GetFileInOverlay(Overlays *this, SInt32 grpnum, SInt32 ovlnum, SInt32 filnum) {
Overlay *oly;
#line 160
OPTION_ASSERT(this);
oly = Overlays_GetOverlayInGroup(this, grpnum, ovlnum);
if (oly)
return Overlay_GetFile(oly, filnum);
else
return -1;
}
OvlGroup *OvlGroup_New(const char *name, OvlAddr addr) {
OvlGroup *grp;
#line 175
OPTION_ASSERT(name);
grp = xmalloc(NULL, sizeof(OvlGroup));
if (grp) {
strncpy(grp->name, name, sizeof(grp->name));
grp->name[sizeof(grp->name) - 1] = 0;
grp->addr = addr;
grp->lastoly = NULL;
grp->olys = NULL;
grp->olycnt = 0;
grp->next = NULL;
} else {
#line 188
DO_INTERNAL_ERROR("Could not allocate %s", "overlay group");
}
return grp;
}
void OvlGroup_Delete(OvlGroup *grp) {
Overlay *scan;
Overlay *next;
#line 197
OPTION_ASSERT(grp);
for (scan = grp->olys; scan; scan = next) {
next = scan->next;
Overlay_Delete(scan);
xfree(scan);
}
grp->olys = NULL;
}
Boolean OvlGroup_AddOverlay(OvlGroup *this, Overlay *oly, SInt32 *olynum) {
#line 211
OPTION_ASSERT(this);
OPTION_ASSERT(oly);
if (!this->lastoly)
this->olys = oly;
else
this->lastoly->next = oly;
this->lastoly = oly;
if (olynum)
*olynum = this->olycnt;
this->olycnt++;
return 1;
}
Overlay *OvlGroup_GetOverlay(OvlGroup *this, SInt32 olynum) {
Overlay *oly;
SInt32 cnt = 0;
#line 234
OPTION_ASSERT(this);
oly = this->olys;
while (oly && cnt < olynum) {
oly = oly->next;
cnt++;
}
if (cnt == olynum)
return oly;
else
return NULL;
}
SInt32 OvlGroup_CountOverlays(OvlGroup *this) {
Overlay *scan;
int num = 0;
#line 254
OPTION_ASSERT(this);
scan = this->olys;
while (scan) {
scan = scan->next;
num++;
}
return num;
}
Overlay *Overlay_New(const char *name) {
Overlay *oly;
oly = xmalloc(NULL, sizeof(Overlay));
if (oly) {
strncpy(oly->name, name, sizeof(oly->name));
oly->name[sizeof(oly->name) - 1] = 0;
oly->list = NULL;
oly->max = 0;
oly->cnt = 0;
oly->next = NULL;
} else {
#line 281
DO_INTERNAL_ERROR("Could not allocate %s", "overlay");
}
return oly;
}
void Overlay_Delete(Overlay *oly) {
#line 288
OPTION_ASSERT(oly);
if (oly->list)
xfree(oly->list);
oly->list = NULL;
}
Boolean Overlay_AddFile(Overlay *oly, SInt32 filenum, SInt32 *filnum) {
#line 296
OPTION_ASSERT(oly);
if (oly->cnt >= oly->max) {
oly->max += 16;
oly->list = xrealloc("overlay file list", oly->list, sizeof(SInt32) * oly->max);
}
oly->list[oly->cnt] = filenum;
if (filnum)
*filnum = oly->cnt;
oly->cnt++;
return 1;
}
SInt32 Overlay_GetFile(Overlay *oly, SInt32 filnum) {
#line 314
OPTION_ASSERT(oly);
if (filnum < oly->cnt)
return oly->list[filnum];
else
return -1;
}
SInt32 Overlay_CountFiles(Overlay *oly) {
#line 323
OPTION_ASSERT(oly);
return oly->cnt;
}
|