forked from JACoders/OpenJK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathibize.cpp
209 lines (173 loc) · 4.17 KB
/
ibize.cpp
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
// ICARUS: IBIze Interpreter
//
// -- jweier
#ifdef _WIN32
#include <conio.h> //For getch()
#include <io.h> //For _findXXX
#else
#include "ibize_platform.h"
#endif
#include "Tokenizer.h"
#include "BlockStream.h"
#include "Interpreter.h"
#define IBIZE_VERSION 1.6f
#define SCRIPT_EXTENSION ".ICR"
CInterpreter Interpreter;
CTokenizer Tokenizer;
CBlockStream BlockStream;
/*
-------------------------
NULL_Error
-------------------------
*/
void NULL_Error( LPCSTR *error_msg )
{
}
/*
-------------------------
InterpretFile
-------------------------
*/
// note different return type now, rather than true/false bool it returns CBlock# +1 of the bad command (if any),
// else 0 for all ok. Also returns -ve block numbers to indicate last block that was ok if an error occured between
// blocks (eg unexpected float at command identifier position)
//
int InterpretFile( char *filename )
{
printf("Parsing '%s'...\n\n", filename);
//Create a block stream
if ( BlockStream.Create( filename ) == false )
{
printf("ERROR: Unable to create file \"%s\"!\n", filename );
return 1;
}
//Create the Interpreted Block Instruction file
//
// (if error, return)
//
int iErrorBlock = Interpreter.Interpret( &Tokenizer, &BlockStream, filename );
if (iErrorBlock!=0)
{
return iErrorBlock;
}
BlockStream.Free();
return iErrorBlock; //true;
}
/*
-------------------------
main
-------------------------
*/
int main(int argc, char* argv[])
{
#ifdef _WIN32
struct _finddata_t fileinfo;
bool error_pause = false;
#endif
char *filename, error_msg[MAX_STRING_LENGTH], newfilename[MAX_FILENAME_LENGTH];
int handle;
//Init the tokenizer and pass the symbols we require
Tokenizer.Create( 0 );
Tokenizer.SetSymbols( (keywordArray_t *) Interpreter.GetSymbols() );
Tokenizer.SetErrorProc( (void (__cdecl *)(const char *)) NULL_Error );
//Init the block streaming class
BlockStream.Init();
//No script arguments, print the banner
if (argc < 2)
{
printf("\n\nIBIze v%1.2f -- jweier\n", IBIZE_VERSION );
printf("ICARUS v%1.2f\n", ICARUS_VERSION );
printf("Copyright (c) 1999, Raven Software\n");
printf("------------------------------\n");
printf("\nIBIze [script1.txt] [script2.txt] [script3.txt] ...\n\n");
return 0;
}
int iErrorBlock = 0;
//Interpret all files passed on the command line
for (int i=1; i<argc; i++)
{
filename = (char *) argv[i];
//FIXME: There could be better ways to do this...
if ( filename[0] == '-' )
{
#ifdef _WIN32
if ( tolower(filename[1]) == 'e' )
error_pause = true;
//Can just use a wildcard in the commandline on non-windows
if ( tolower(filename[1]) == 'a' )
{
handle = _findfirst ( "*.txt", &fileinfo);
while ( handle != -1 )
{
if (Tokenizer.AddParseFile( (char*) &fileinfo.name ))
{
//Interpret the file
if ( (iErrorBlock=InterpretFile( (char *) &fileinfo.name )) !=0 )
{
// failed
//
BlockStream.Free();
if (error_pause)
getch();
}
}
if ( _findnext( handle, &fileinfo ) == -1 )
break;
}
_findclose (handle);
}
#endif
continue;
}
//Tokenize the file
if (Tokenizer.AddParseFile( filename ))
{
//Interpret the file
if ( (iErrorBlock=InterpretFile( filename )) !=0 )
{
// failed
//
BlockStream.Free();
#ifdef _WIN32
if (error_pause)
getch();
#endif
return iErrorBlock;
}
}
else
{
//Try adding on the SCR extension if it was left off
strcpy((char *) &newfilename, filename);
strcat((char *) &newfilename, SCRIPT_EXTENSION);
if (Tokenizer.AddParseFile( (char*) &newfilename ))
{
//Interpret the file
if ( (iErrorBlock=InterpretFile( (char *) &newfilename )) !=0 )
{
// failed
//
BlockStream.Free();
#ifdef _WIN32
if (error_pause)
getch();
#endif
return iErrorBlock;
}
}
else
{
//File wasn't found
sprintf(error_msg, "ERROR: File '%s' not found!\n", filename);
printf(error_msg);
#ifdef _WIN32
if (error_pause)
getch();
#endif
return 1; // this will technically mean that there was a problem with cblock 1, but wtf?
}
}
}
printf("Done\n\n");
return 0;
}