2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
26 ===========================================================================
29 #include "../../idlib/precompiled.h"
32 #include "DebuggerApp.h"
33 #include "DebuggerScript.h"
34 #include "../../game/script/Script_Program.h"
35 #include "../../ui/Window.h"
36 #include "../../ui/UserInterfaceLocal.h"
40 rvDebuggerScript::rvDebuggerScript
43 rvDebuggerScript::rvDebuggerScript ( void )
52 rvDebuggerScript::~rvDebuggerScript
55 rvDebuggerScript::~rvDebuggerScript ( void )
62 rvDebuggerScript::Unload
64 Unload the script from memory
67 void rvDebuggerScript::Unload ( void )
87 rvDebuggerScript::Load
89 Loads the debugger script and attempts to compile it using the method
90 appropriate for the file being loaded. If the script cant be compiled
91 the loading of the script fails
94 bool rvDebuggerScript::Load ( const char* filename )
99 // Unload the script before reloading it
102 // Cache the filename used to load the script
103 mFilename = filename;
106 size = fileSystem->ReadFile ( filename, &buffer, &mModifiedTime );
107 if ( buffer == NULL )
112 // Copy the buffer over
113 mContents = new char [ size + 1 ];
114 memcpy ( mContents, buffer, size );
118 fileSystem->FreeFile ( buffer );
120 // Now compile the script so we can tell what a valid line is, etc.. If its
121 // a gui file then we need to parse it using the userinterface system rather
122 // than the normal script compiler.
125 // Parse the script using the script compiler
126 mProgram = new idProgram;
127 mProgram->BeginCompilation ( );
128 mProgram->CompileFile ( SCRIPT_DEFAULT );
130 //BSM Nerve: Loads a game specific main script file
131 idStr gamedir = cvarSystem->GetCVarString( "fs_game" );
132 if(gamedir.Length() > 0) {
134 idStr scriptFile = va("script/%s_main.script", gamedir.c_str());
135 if(fileSystem->ReadFile(scriptFile.c_str(), NULL) > 0) {
136 mProgram.CompileFile(scriptFile.c_str());
141 // Make sure the file isnt already compiled before trying to compile it again
142 for ( int f = mProgram->NumFilenames() - 1; f >= 0; f -- )
145 qpath = fileSystem->OSPathToRelativePath ( mProgram->GetFilename ( f ) );
146 qpath.BackSlashesToSlashes ( );
147 if ( !qpath.Cmp ( filename ) )
155 mProgram->CompileText ( filename, mContents, false );
158 mProgram->FinishCompilation ( );
160 catch ( idException& )
162 // Failed to parse the script so fail to load the file
168 // TODO: Should cache the error for the dialog box
178 rvDebuggerScript::Reload
180 Reload the contents of the script
183 bool rvDebuggerScript::Reload ( void )
185 return Load ( mFilename );
190 rvDebuggerScript::IsValidLine
192 Determines whether or not the given line number within the script is a valid line of code
195 bool rvDebuggerScript::IsLineCode ( int linenumber )
201 // Run through all the statements in the program and see if any match the
202 // linenumber that we are checking.
203 for ( i = 0; i < mProgram->NumStatements ( ); i ++ )
205 if ( mProgram->GetStatement ( i ).linenumber == linenumber )
216 rvDebuggerScript::IsFileModified
218 Determines whether or not the file loaded for this script has been modified since
222 bool rvDebuggerScript::IsFileModified ( bool updateTime )
227 // Grab the filetime and shut the file down
228 fileSystem->ReadFile ( mFilename, NULL, &t );
230 // Has the file been modified?
231 if ( t > mModifiedTime )
236 // If updateTime is true then we will update the modified time
237 // stored in the script with the files current modified time