-
Notifications
You must be signed in to change notification settings - Fork 38
/
acc.c
318 lines (273 loc) · 7.52 KB
/
acc.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
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
312
313
314
315
316
317
318
//**************************************************************************
//**
//** acc.c
//**
//**************************************************************************
// HEADER FILES ------------------------------------------------------------
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "common.h"
#include "token.h"
#include "error.h"
#include "symbol.h"
#include "misc.h"
#include "pcode.h"
#include "parse.h"
#include "strlist.h"
// MACROS ------------------------------------------------------------------
#define VERSION_TEXT "1.60"
#define COPYRIGHT_YEARS_TEXT "1995-2023"
// TYPES -------------------------------------------------------------------
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
static void Init(void);
static void DisplayBanner(void);
static void DisplayUsage(void);
static void OpenDebugFile(char *name);
static void ProcessArgs(void);
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
// PUBLIC DATA DEFINITIONS -------------------------------------------------
boolean acs_BigEndianHost;
boolean acs_VerboseMode;
boolean acs_DebugMode;
FILE *acs_DebugFile;
char acs_SourceFileName[MAX_FILE_NAME_LENGTH];
// PRIVATE DATA DEFINITIONS ------------------------------------------------
static int ArgCount;
static char **ArgVector;
static char ObjectFileName[MAX_FILE_NAME_LENGTH];
// CODE --------------------------------------------------------------------
//==========================================================================
//
// main
//
//==========================================================================
int main(int argc, char **argv)
{
int i;
ArgCount = argc;
ArgVector = argv;
DisplayBanner();
Init();
TK_OpenSource(acs_SourceFileName);
PC_OpenObject(ObjectFileName, DEFAULT_OBJECT_SIZE, 0);
PA_Parse();
PC_CloseObject();
TK_CloseSource();
MS_Message(MSG_NORMAL, "\n\"%s\":\n %d line%s (%d included)\n",
acs_SourceFileName, tk_Line, tk_Line == 1 ? "" : "s",
tk_IncludedLines);
MS_Message(MSG_NORMAL, " %d function%s\n %d script%s\n",
pc_FunctionCount, pc_FunctionCount == 1 ? "" : "s",
pa_ScriptCount, pa_ScriptCount == 1 ? "" : "s");
for (i = 0; pa_TypedScriptCounts[i].TypeName; i++)
{
if (pa_TypedScriptCounts[i].TypeCount > 0)
{
MS_Message(MSG_NORMAL, "%5d %s\n",
pa_TypedScriptCounts[i].TypeCount,
pa_TypedScriptCounts[i].TypeName);
}
}
MS_Message(MSG_NORMAL, " %d global variable%s\n"
" %d world variable%s\n"
" %d map variable%s\n"
" %d global array%s\n"
" %d world array%s\n",
pa_GlobalVarCount, pa_GlobalVarCount == 1 ? "" : "s",
pa_WorldVarCount, pa_WorldVarCount == 1 ? "" : "s",
pa_MapVarCount, pa_MapVarCount == 1 ? "" : "s",
pa_GlobalArrayCount, pa_GlobalArrayCount == 1 ? "" : "s",
pa_WorldArrayCount, pa_WorldArrayCount == 1 ? "" : "s"
);
MS_Message(MSG_NORMAL, " object \"%s\": %d bytes\n",
ObjectFileName, pc_Address);
ERR_RemoveErrorFile();
return 0;
}
//==========================================================================
//
// DisplayBanner
//
//==========================================================================
static void DisplayBanner(void)
{
fprintf(stderr, "\nOriginal ACC Version 1.10 by Ben Gokey\n");
fprintf(stderr, "Copyright (c) "COPYRIGHT_YEARS_TEXT
" Raven Software, Corp.\n\n");
fprintf(stderr, "This is version "VERSION_TEXT" ("__DATE__")\n");
fprintf(stderr, "This software is not supported by Raven Software or Activision\n");
fprintf(stderr, "ZDoom changes and language extensions by Randy Heit\n");
fprintf(stderr, "Further changes by Brad Carney\n");
fprintf(stderr, "Even more changes by James Bentler\n");
fprintf(stderr, "Some additions by Michael \"Necromage\" Weber\n");
fprintf(stderr, "Error reporting improvements and limit expansion by Ty Halderman\n");
fprintf(stderr, "Include paths added by Pascal vd Heiden\n");
}
//==========================================================================
//
// Init
//
//==========================================================================
static void Init(void)
{
short endianTest = 1;
if (*(char *)&endianTest)
acs_BigEndianHost = NO;
else
acs_BigEndianHost = YES;
acs_VerboseMode = YES;
acs_DebugMode = NO;
acs_DebugFile = NULL;
TK_Init();
SY_Init();
STR_Init();
ProcessArgs();
MS_Message(MSG_NORMAL, "Host byte order: %s endian\n",
acs_BigEndianHost ? "BIG" : "LITTLE");
}
//==========================================================================
//
// ProcessArgs
//
// Pascal 12/11/08
// Allowing space after options (option parameter as the next argument)
//
//==========================================================================
static void ProcessArgs(void)
{
int i = 1;
int count = 0;
char *text;
char option;
while(i < ArgCount)
{
text = ArgVector[i];
if(*text == '-')
{
// Option
text++;
if(*text == 0)
{
DisplayUsage();
}
option = toupper(*text++);
switch(option)
{
case 'I':
if((i + 1) < ArgCount)
{
TK_AddIncludePath(ArgVector[++i]);
}
break;
case 'D':
acs_DebugMode = YES;
acs_VerboseMode = YES;
if(*text != 0)
{
OpenDebugFile(text);
}
break;
case 'H':
pc_NoShrink = TRUE;
pc_HexenCase = TRUE;
pc_EnforceHexen = toupper(*text) != 'H';
pc_WarnNotHexen = toupper(*text) == 'H';
break;
default:
DisplayUsage();
break;
}
}
else
{
// Input/output file
count++;
switch(count)
{
case 1:
strcpy(acs_SourceFileName, text);
MS_SuggestFileExt(acs_SourceFileName, ".acs");
break;
case 2:
strcpy(ObjectFileName, text);
MS_SuggestFileExt(ObjectFileName, ".o");
break;
default:
DisplayUsage();
break;
}
}
// Next arg
i++;
}
if(count == 0)
{
DisplayUsage();
}
TK_AddIncludePath(".");
#ifdef unix
TK_AddIncludePath("/usr/local/share/acc/");
#endif
TK_AddProgramIncludePath(ArgVector[0]);
if(count == 1)
{
strcpy(ObjectFileName, acs_SourceFileName);
MS_StripFileExt(ObjectFileName);
MS_SuggestFileExt(ObjectFileName, ".o");
}
}
//==========================================================================
//
// DisplayUsage
//
//==========================================================================
static void DisplayUsage(void)
{
puts("\nUsage: ACC [options] source[.acs] [object[.o]]\n");
puts("-i [path] Add include path to find include files");
puts("-d[file] Output debugging information");
puts("-h Create pcode compatible with Hexen and old ZDooms");
puts("-hh Like -h, but use of new features is only a warning");
exit(1);
}
//==========================================================================
//
// OpenDebugFile
//
//==========================================================================
static void OpenDebugFile(char *name)
{
if((acs_DebugFile = fopen(name, "w")) == NULL)
{
ERR_Exit(ERR_CANT_OPEN_DBGFILE, NO, "File: \"%s\".", name);
}
}
//==========================================================================
//
// OptionExists
//
//==========================================================================
/*
static boolean OptionExists(char *name)
{
int i;
char *arg;
for(i = 1; i < ArgCount; i++)
{
arg = ArgVector[i];
if(*arg == '-')
{
arg++;
if(MS_StrCmp(name, arg) == 0)
{
return YES;
}
}
}
return NO;
}
*/