diff options
| author | Petr Mrázek | 2012-03-14 01:52:58 +0100 |
|---|---|---|
| committer | Petr Mrázek | 2012-03-14 01:52:58 +0100 |
| commit | d75908b95c849b00fdd8b819e6dd3b9d671cac02 (patch) | |
| tree | 3926e8fe9735b2408f8c2155ce270226b9b0e527 /library/Core.cpp | |
| parent | fc7ba07476ed42b846cc34f23eb19a53cbce3daf (diff) | |
| parent | 4cb8995a0558d0ccf316584ca81f304ad976da37 (diff) | |
| download | dfhack-d75908b95c849b00fdd8b819e6dd3b9d671cac02.tar.gz dfhack-d75908b95c849b00fdd8b819e6dd3b9d671cac02.tar.bz2 dfhack-d75908b95c849b00fdd8b819e6dd3b9d671cac02.tar.xz | |
Merge https://github.com/ClaytonHughes/dfhack
Conflicts:
library/Core.cpp
plugins/workflow.cpp
Just had to fix a few minor things.
Diffstat (limited to 'library/Core.cpp')
| -rw-r--r-- | library/Core.cpp | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/library/Core.cpp b/library/Core.cpp index 9a005d33..1439d39b 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -67,6 +67,12 @@ using namespace tthread; using namespace df::enums; using df::global::init; +// FIXME: A lot of code in one file, all doing different things... there's something fishy about it. + +static void loadScriptFile(Core *core, PluginManager *plug_mgr, string fname); +static void runInteractiveCommand(Core *core, PluginManager *plug_mgr, int &clueless_counter, const string &command); +static bool parseKeySpec(std::string keyspec, int *psym, int *pmod); + struct Core::Cond { Cond() @@ -371,6 +377,7 @@ static void runInteractiveCommand(Core *core, PluginManager *plug_mgr, int &clue " fpause - Force DF to pause.\n" " die - Force DF to close immediately\n" " keybinding - Modify bindings of commands to keys\n" + " script FILENAME - Run the commands specified in a file.\n" " plug [PLUGIN|v] - List plugin state and detailed description.\n" " load PLUGIN|all - Load a plugin by name or load all possible plugins.\n" " unload PLUGIN|all - Unload a plugin or all loaded plugins.\n" @@ -466,6 +473,18 @@ static void runInteractiveCommand(Core *core, PluginManager *plug_mgr, int &clue { _exit(666); } + else if(first == "script") + { + if(parts.size() == 1) + { + loadScriptFile(core, plug_mgr, parts[0]); + } + else + { + con << "Usage:" << endl + << " script <filename>" << endl; + } + } else { command_result res = plug_mgr->InvokeCommand(con, first, parts); @@ -478,19 +497,26 @@ static void runInteractiveCommand(Core *core, PluginManager *plug_mgr, int &clue } } -static void loadInitFile(Core *core, PluginManager *plug_mgr, string fname) +static void loadScriptFile(Core *core, PluginManager *plug_mgr, string fname) { - ifstream init(fname); - if (init.bad()) - return; - - int tmp = 0; - string command; - while (getline(init, command)) + core->getConsole() << "Loading script at " << fname << std::endl; + ifstream script(fname); + if (script.good()) { - if (!command.empty()) - runInteractiveCommand(core, plug_mgr, tmp, command); + int tmp = 0; + string command; + while (getline(script, command)) + { + if (!command.empty()) + runInteractiveCommand(core, plug_mgr, tmp, command); + } } + else + { + core->getConsole().printerr("Error loading script\n"); + } + + script.close(); } // A thread function... for the interactive console. @@ -510,7 +536,7 @@ void fIOthread(void * iodata) return; } - loadInitFile(core, plug_mgr, "dfhack.init"); + loadScriptFile(core, plug_mgr, "dfhack.init"); con.print("DFHack is ready. Have a nice day!\n" "Type in '?' or 'help' for general help, 'ls' to see all commands.\n"); |
