This commit is contained in:
thrust26 2017-10-08 19:04:48 +02:00
commit 64e4153bca
3 changed files with 25 additions and 19 deletions

View File

@ -211,13 +211,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");
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -572,12 +572,16 @@ string DebuggerParser::trapStatus(const Trap& trap)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool DebuggerParser::saveScriptFile(string file) string DebuggerParser::saveScriptFile(string file)
{ {
if( file.find_last_of('.') == string::npos ) // Append 'script' extension when necessary
file += ".stella"; if(file.find_last_of('.') == string::npos)
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)
@ -608,7 +612,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";
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -959,8 +963,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);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -1429,10 +1438,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 = 76 }; enum { kNumCommands = 76 };