|     43 #include "string.h" | 
    43 #include "string.h" | 
|     44 #include "str.h" | 
    44 #include "str.h" | 
|     45 #include "common.h" | 
    45 #include "common.h" | 
|     46 #include "scriptreader.h" | 
    46 #include "scriptreader.h" | 
|     47  | 
    47  | 
|         | 
    48 #define STORE_POSITION \ | 
|         | 
    49 	bool _atnewline = atnewline; \ | 
|         | 
    50 	unsigned int _curline = curline[fc]; \ | 
|         | 
    51 	unsigned int _curchar = curchar[fc]; | 
|         | 
    52  | 
|         | 
    53 #define RESTORE_POSITION \ | 
|         | 
    54 	atnewline = _atnewline; \ | 
|         | 
    55 	curline[fc] = _curline; \ | 
|         | 
    56 	curchar[fc] = _curchar; | 
|         | 
    57  | 
|     48 // ============================================================================ | 
    58 // ============================================================================ | 
|     49 ScriptReader::ScriptReader (str path) { | 
    59 ScriptReader::ScriptReader (str path) { | 
|     50 	token = ""; | 
    60 	token = ""; | 
|     51 	prevtoken = ""; | 
    61 	prevtoken = ""; | 
|     52 	prevpos = 0; | 
    62 	prevpos = 0; | 
|    150 // ============================================================================ | 
   160 // ============================================================================ | 
|    151 // Peeks the next character | 
   161 // Peeks the next character | 
|    152 char ScriptReader::PeekChar (int offset) { | 
   162 char ScriptReader::PeekChar (int offset) { | 
|    153 	// Store current position | 
   163 	// Store current position | 
|    154 	long curpos = ftell (fp[fc]); | 
   164 	long curpos = ftell (fp[fc]); | 
|         | 
   165 	STORE_POSITION | 
|    155 	 | 
   166 	 | 
|    156 	// Forward by offset | 
   167 	// Forward by offset | 
|    157 	fseek (fp[fc], offset, SEEK_CUR); | 
   168 	fseek (fp[fc], offset, SEEK_CUR); | 
|    158 	 | 
   169 	 | 
|    159 	// Read the character | 
   170 	// Read the character | 
|    265 // Returns the next token without advancing the cursor. | 
   277 // Returns the next token without advancing the cursor. | 
|    266 str ScriptReader::PeekNext (int offset) { | 
   278 str ScriptReader::PeekNext (int offset) { | 
|    267 	// Store current information | 
   279 	// Store current information | 
|    268 	str storedtoken = token; | 
   280 	str storedtoken = token; | 
|    269 	int cpos = ftell (fp[fc]); | 
   281 	int cpos = ftell (fp[fc]); | 
|         | 
   282 	STORE_POSITION | 
|    270 	 | 
   283 	 | 
|    271 	// Advance on the token. | 
   284 	// Advance on the token. | 
|    272 	while (offset >= 0) { | 
   285 	while (offset >= 0) { | 
|    273 		if (!Next (true)) | 
   286 		if (!Next (true)) | 
|    274 			return ""; | 
   287 			return ""; | 
|    335 } | 
   349 } | 
|    336  | 
   350  | 
|    337 // ============================================================================ | 
   351 // ============================================================================ | 
|    338 void ScriptReader::ParserMessage (const char* header, char* message) { | 
   352 void ScriptReader::ParserMessage (const char* header, char* message) { | 
|    339 	if (fc >= 0 && fc < MAX_FILESTACK) | 
   353 	if (fc >= 0 && fc < MAX_FILESTACK) | 
|    340 		fprintf (stderr, "%sIn file %s, at line %u, col %u: %s\n", | 
   354 		fprintf (stderr, "%s%s:%u:%u: %s\n", | 
|    341 			header, filepath[fc], curline[fc], curchar[fc], message); | 
   355 			header, filepath[fc], curline[fc], curchar[fc], message); | 
|    342 	else | 
   356 	else | 
|    343 		fprintf (stderr, "%s%s\n", header, message); | 
   357 		fprintf (stderr, "%s%s\n", header, message); | 
|    344 } | 
   358 } | 
|    345  | 
   359  |