============================================================================ Parameter: - Returns: - Changes Globals: - ============================================================================
| 1331 | // Changes Globals: - |
| 1332 | //============================================================================ |
| 1333 | script_t *LoadScriptFile(const char *filename) |
| 1334 | { |
| 1335 | #ifdef BOTLIB |
| 1336 | fileHandle_t fp; |
| 1337 | char pathname[MAX_QPATH]; |
| 1338 | #else |
| 1339 | FILE *fp; |
| 1340 | #endif |
| 1341 | int length; |
| 1342 | void *buffer; |
| 1343 | script_t *script; |
| 1344 | |
| 1345 | #ifdef BOTLIB |
| 1346 | if (strlen(basefolder)) |
| 1347 | Com_sprintf(pathname, sizeof(pathname), "%s/%s", basefolder, filename); |
| 1348 | else |
| 1349 | Com_sprintf(pathname, sizeof(pathname), "%s", filename); |
| 1350 | length = botimport.FS_FOpenFile( pathname, &fp, FS_READ ); |
| 1351 | if (!fp) return NULL; |
| 1352 | #else |
| 1353 | fp = fopen(filename, "rb"); |
| 1354 | if (!fp) return NULL; |
| 1355 | |
| 1356 | length = FileLength(fp); |
| 1357 | #endif |
| 1358 | |
| 1359 | buffer = GetClearedMemory(sizeof(script_t) + length + 1); |
| 1360 | script = (script_t *) buffer; |
| 1361 | Com_Memset(script, 0, sizeof(script_t)); |
| 1362 | Q_strncpyz(script->filename, filename, sizeof(script->filename)); |
| 1363 | script->buffer = (char *) buffer + sizeof(script_t); |
| 1364 | script->buffer[length] = 0; |
| 1365 | script->length = length; |
| 1366 | //pointer in script buffer |
| 1367 | script->script_p = script->buffer; |
| 1368 | //pointer in script buffer before reading token |
| 1369 | script->lastscript_p = script->buffer; |
| 1370 | //pointer to end of script buffer |
| 1371 | script->end_p = &script->buffer[length]; |
| 1372 | //set if there's a token available in script->token |
| 1373 | script->tokenavailable = 0; |
| 1374 | // |
| 1375 | script->line = 1; |
| 1376 | script->lastline = 1; |
| 1377 | // |
| 1378 | SetScriptPunctuations(script, NULL); |
| 1379 | // |
| 1380 | #ifdef BOTLIB |
| 1381 | botimport.FS_Read(script->buffer, length, fp); |
| 1382 | botimport.FS_FCloseFile(fp); |
| 1383 | #else |
| 1384 | if (fread(script->buffer, length, 1, fp) != 1) |
| 1385 | { |
| 1386 | FreeMemory(buffer); |
| 1387 | script = NULL; |
| 1388 | } //end if |
| 1389 | fclose(fp); |
| 1390 | #endif |
no test coverage detected