================ idLexer::LoadFile ================ */
| 1593 | ================ |
| 1594 | */ |
| 1595 | int 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 | ================ |
no test coverage detected