MCPcopy Create free account
hub / github.com/dhewm/dhewm3 / LoadFile

Method LoadFile

neo/idlib/Lexer.cpp:1595–1643  ·  view source on GitHub ↗

================ idLexer::LoadFile ================ */

Source from the content-addressed store, hash-verified

1593================
1594*/
1595int idLexer::LoadFile( const char *filename, bool OSPath ) {
1596 idFile *fp;
1597 idStr pathname;
1598 int length;
1599 char *buf;
1600
1601 if ( idLexer::loaded ) {
1602 idLib::common->Error("idLexer::LoadFile: another script already loaded");
1603 return false;
1604 }
1605
1606 if ( !OSPath && ( baseFolder[0] != '\0' ) ) {
1607 pathname = va( "%s/%s", baseFolder, filename );
1608 } else {
1609 pathname = filename;
1610 }
1611 if ( OSPath ) {
1612 fp = idLib::fileSystem->OpenExplicitFileRead( pathname );
1613 } else {
1614 fp = idLib::fileSystem->OpenFileRead( pathname );
1615 }
1616 if ( !fp ) {
1617 return false;
1618 }
1619 length = fp->Length();
1620 buf = (char *) Mem_Alloc( length + 1 );
1621 buf[length] = '\0';
1622 fp->Read( buf, length );
1623 idLexer::fileTime = fp->Timestamp();
1624 idLexer::filename = fp->GetFullPath();
1625 idLib::fileSystem->CloseFile( fp );
1626
1627 idLexer::buffer = buf;
1628 idLexer::length = length;
1629 // pointer in script buffer
1630 idLexer::script_p = idLexer::buffer;
1631 // pointer in script buffer before reading token
1632 idLexer::lastScript_p = idLexer::buffer;
1633 // pointer to end of script buffer
1634 idLexer::end_p = &(idLexer::buffer[length]);
1635
1636 idLexer::tokenavailable = 0;
1637 idLexer::line = 1;
1638 idLexer::lastline = 1;
1639 idLexer::allocated = true;
1640 idLexer::loaded = true;
1641
1642 return true;
1643}
1644
1645/*
1646================

Callers 15

LoadAnimMethod · 0.45
ConvertMayaToMD5Method · 0.45
ExportDefFileMethod · 0.45
LoadAnimMethod · 0.45
CompareGameStateMethod · 0.45
Cmd_ShowViewNotes_fFunction · 0.45
SetSaveGameGuiVarsMethod · 0.45
InitFromFileMethod · 0.45
LoadModelMethod · 0.45
InitFromFileMethod · 0.45
CreateTypeInfoMethod · 0.45

Calls 10

vaFunction · 0.85
Mem_AllocFunction · 0.85
OpenExplicitFileReadMethod · 0.80
OpenFileReadMethod · 0.80
CloseFileMethod · 0.80
ErrorMethod · 0.45
LengthMethod · 0.45
ReadMethod · 0.45
TimestampMethod · 0.45
GetFullPathMethod · 0.45

Tested by

no test coverage detected