Fixed 'save' command in debugger parser:

- all files are now appended with '.script' instead of '.stella'.
- files are saved in default save location, just like disassembly files
(this can be discussed/changed as necessary)
- 'exec' command has been changed to load from the same location
This commit is contained in:
Stephen Anthony 2017-10-08 14:24:10 -02:30
parent 5f2e383440
commit 741e148da5
3 changed files with 25 additions and 19 deletions

View File

@ -210,13 +210,13 @@ string Debugger::autoExec()
{ {
ostringstream buf; ostringstream buf;
// autoexec.stella is always run // autoexec.script is always run
FilesystemNode autoexec(myOSystem.baseDir() + "autoexec.stella"); FilesystemNode autoexec(myOSystem.baseDir() + "autoexec.script");
buf << "autoExec():" << endl buf << "autoExec():" << endl
<< myParser->exec(autoexec) << endl; << myParser->exec(autoexec) << endl;
// Also, "romname.stella" if present // Also, "romname.script" if present
FilesystemNode romname(myOSystem.romFile().getPathWithExt(".stella")); FilesystemNode romname(myOSystem.romFile().getPathWithExt(".script"));
buf << myParser->exec(romname) << endl; buf << myParser->exec(romname) << endl;
// Init builtins // Init builtins

View File

@ -129,7 +129,7 @@ string DebuggerParser::exec(const FilesystemNode& file)
{ {
ifstream in(file.getPath()); ifstream in(file.getPath());
if(!in.is_open()) if(!in.is_open())
return red("autoexec file \'" + file.getShortPath() + "\' not found"); return red("script file \'" + file.getShortPath() + "\' not found");
ostringstream buf; ostringstream buf;
int count = 0; int count = 0;
@ -142,13 +142,13 @@ string DebuggerParser::exec(const FilesystemNode& file)
run(command); run(command);
count++; count++;
} }
buf << "Executed " << count << " commands from \"" buf << "\nExecuted " << count << " commands from \""
<< file.getShortPath() << "\""; << file.getShortPath() << "\"";
return buf.str(); return buf.str();
} }
else else
return red("autoexec file \'" + file.getShortPath() + "\' not found"); return red("script file \'" + file.getShortPath() + "\' not found");
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -571,12 +571,16 @@ string DebuggerParser::trapStatus(uInt32 addr, bool& enabled)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool DebuggerParser::saveScriptFile(string file) string DebuggerParser::saveScriptFile(string file)
{ {
// Append 'script' extension when necessary
if(file.find_last_of('.') == string::npos) if(file.find_last_of('.') == string::npos)
file += ".stella"; file += ".script";
ofstream out(file); FilesystemNode node(debugger.myOSystem.defaultSaveDir() + file);
ofstream out(node.getPath());
if(!out.is_open())
return "Unable to save script to " + node.getShortPath();
FunctionDefMap funcs = debugger.getFunctionDefMap(); FunctionDefMap funcs = debugger.getFunctionDefMap();
for(const auto& f: funcs) for(const auto& f: funcs)
@ -606,7 +610,7 @@ bool DebuggerParser::saveScriptFile(string file)
for(const auto& cond: conds) for(const auto& cond: conds)
out << "breakif {" << cond << "}" << endl; out << "breakif {" << cond << "}" << endl;
return out.good(); return "saved " + node.getShortPath() + " OK";
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -938,8 +942,13 @@ void DebuggerParser::executeDump()
// "exec" // "exec"
void DebuggerParser::executeExec() void DebuggerParser::executeExec()
{ {
FilesystemNode file(argStrings[0]); // Append 'script' extension when necessary
commandResult << exec(file); string file = argStrings[0];
if(file.find_last_of('.') == string::npos)
file += ".script";
FilesystemNode node(debugger.myOSystem.defaultSaveDir() + file);
commandResult << exec(node);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -1382,10 +1391,7 @@ void DebuggerParser::executeS()
// "save" // "save"
void DebuggerParser::executeSave() void DebuggerParser::executeSave()
{ {
if(saveScriptFile(argStrings[0])) commandResult << saveScriptFile(argStrings[0]);
commandResult << "saved script to file " << argStrings[0];
else
commandResult << red("I/O error");
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -65,7 +65,7 @@ class DebuggerParser
bool getArgs(const string& command, string& verb); bool getArgs(const string& command, string& verb);
bool validateArgs(int cmd); bool validateArgs(int cmd);
string eval(); string eval();
bool saveScriptFile(string file); string saveScriptFile(string file);
private: private:
enum { kNumCommands = 72 }; enum { kNumCommands = 72 };