-
Notifications
You must be signed in to change notification settings - Fork 0
/
comprout.c
252 lines (213 loc) · 4.18 KB
/
comprout.c
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
//compile routines
#include "qcc.h"
#undef progfuncs
char errorfile[128];
int errorline;
progfuncs_t *qccprogfuncs;
#include <setjmp.h>
extern int qcc_compileactive;
jmp_buf qcccompileerror;
char qcc_gamedir[128];
void QCC_PR_ResetErrorScope(void);
#ifdef MINIMAL
#else
int qccalloced;
int qcchunksize;
char *qcchunk;
void *qccHunkAlloc(size_t mem)
{
mem = (mem + 7)&~7;
qccalloced+=mem;
if (qccalloced > qcchunksize)
QCC_Error(ERR_INTERNAL, "Compile hunk was filled");
memset(qcchunk+qccalloced-mem, 0, mem);
return qcchunk+qccalloced-mem;
}
void qccClearHunk(void)
{
if (qcchunk)
{
free(qcchunk);
qcchunk=NULL;
}
}
int qccpersisthunk;
void PostCompile(void)
{
if (!qccpersisthunk)
qccClearHunk();
if (asmfile)
{
fclose(asmfile);
asmfile = NULL;
}
}
pbool PreCompile(void)
{
QCC_PR_ResetErrorScope();
qccClearHunk();
strcpy(qcc_gamedir, "");
qcchunk = malloc(qcchunksize=128*1024*1024);
while(!qcchunk && qcchunksize > 8*1024*1024)
{
qcchunksize /= 2;
qcchunk = malloc(qcchunksize);
}
qccalloced=0;
return !!qcchunk;
}
void QCC_main (int argc, char **argv);
void QCC_ContinueCompile(void);
void QCC_FinishCompile(void);
int comp_nump;char **comp_parms;
//void Editor(char *fname, int line, int numparms, char **compileparms);
pbool CompileParams(progfuncs_t *progfuncs, int doall, int nump, char **parms)
{
comp_nump = nump;
comp_parms = parms;
*errorfile = '\0';
qccprogfuncs = progfuncs;
if (setjmp(qcccompileerror))
{
PostCompile();
if (*errorfile)
{
if (!externs->useeditor)
printf("Error in %s on line %i\n", errorfile, errorline);
else
externs->useeditor(progfuncs, errorfile, errorline, nump, parms);
}
return false;
}
if (!PreCompile())
return false;
QCC_main(nump, parms);
while(qcc_compileactive)
QCC_ContinueCompile();
PostCompile();
return true;
}
int Comp_Begin(progfuncs_t *progfuncs, int nump, char **parms)
{
comp_nump = nump;
comp_parms = parms;
qccprogfuncs = progfuncs;
*errorfile = '\0';
if (setjmp(qcccompileerror))
{
PostCompile();
if (*errorfile)
externs->useeditor(progfuncs, errorfile, errorline, nump, parms);
return false;
}
if (!PreCompile())
return false;
QCC_main(nump, parms);
return true;
}
int Comp_Continue(progfuncs_t *progfuncs)
{
qccprogfuncs = progfuncs;
if (setjmp(qcccompileerror))
{
PostCompile();
if (*errorfile && externs->useeditor)
externs->useeditor(progfuncs, errorfile, errorline, comp_nump, comp_parms);
return false;
}
if (qcc_compileactive)
QCC_ContinueCompile();
else
{
PostCompile();
if (*errorfile && externs->useeditor)
externs->useeditor(progfuncs, errorfile, errorline, comp_nump, comp_parms);
return false;
}
return true;
}
#endif
pbool CompileFile(progfuncs_t *progfuncs, char *filename)
{
#ifdef MINIMAL
return false;
#else
char srcfile[32];
char newname[32];
static char *p[5];
int parms;
char *s, *s2;
p[0] = NULL;
parms = 1;
strcpy(newname, filename);
s = newname;
if (strchr(s+1, '/'))
{
while(1)
{
s2 = strchr(s+1, '/');
if (!s2)
{
*s = '\0';
break;
}
s = s2;
}
p[parms] = "-src";
p[parms+1] = newname;
parms+=2;
strcpy(srcfile, s+1);
srcfile[strlen(srcfile)-4] = '\0';
strcat(srcfile, ".src");
if (externs->FileSize(qcva("%s/%s", newname, srcfile))>0)
{
p[parms] = "-srcfile";
p[parms+1] = srcfile;
parms+=2;
}
}
else
{
p[parms] = "-srcfile";
p[parms+1] = newname;
newname[strlen(newname)-4] = '\0';
strcat(newname, ".src");
parms+=2;
}
// p[2][strlen(p[2])-4] = '\0';
// strcat(p[2], "/");
while (!CompileParams(progfuncs, true, parms, p))
{
return false;
}
return true;
#endif
}
int QC_strncasecmp(const char *s1, const char *s2, int n)
{
int c1, c2;
while (1)
{
c1 = *s1++;
c2 = *s2++;
if (!n--)
return 0; // strings are equal until end point
if (c1 != c2)
{
if (c1 >= 'a' && c1 <= 'z')
c1 -= ('a' - 'A');
if (c2 >= 'a' && c2 <= 'z')
c2 -= ('a' - 'A');
if (c1 != c2)
return -1; // strings not equal
}
if (!c1)
return 0; // strings are equal
}
return -1;
}
void editbadfile(char *fname, int line)
{
strcpy(errorfile, fname);
errorline = line;
}