More fixes

Include unistd.h in linux process file
Fix assert in autolabor
Don't print 'script missing' error on DF start
develop
Petr Mrázek 2012-03-29 02:49:44 +02:00
parent 757ad3334c
commit d82120a3db
3 changed files with 17 additions and 17 deletions

@ -70,7 +70,7 @@ using df::global::init;
// FIXME: A lot of code in one file, all doing different things... there's something fishy about it. // 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 loadScriptFile(Core *core, PluginManager *plug_mgr, string fname, bool silent);
static void runInteractiveCommand(Core *core, PluginManager *plug_mgr, int &clueless_counter, const string &command); static void runInteractiveCommand(Core *core, PluginManager *plug_mgr, int &clueless_counter, const string &command);
static bool parseKeySpec(std::string keyspec, int *psym, int *pmod); static bool parseKeySpec(std::string keyspec, int *psym, int *pmod);
@ -492,7 +492,7 @@ static void runInteractiveCommand(Core *core, PluginManager *plug_mgr, int &clue
{ {
if(parts.size() == 1) if(parts.size() == 1)
{ {
loadScriptFile(core, plug_mgr, parts[0]); loadScriptFile(core, plug_mgr, parts[0], false);
} }
else else
{ {
@ -512,8 +512,9 @@ static void runInteractiveCommand(Core *core, PluginManager *plug_mgr, int &clue
} }
} }
static void loadScriptFile(Core *core, PluginManager *plug_mgr, string fname) static void loadScriptFile(Core *core, PluginManager *plug_mgr, string fname, bool silent)
{ {
if(!silent)
core->getConsole() << "Loading script at " << fname << std::endl; core->getConsole() << "Loading script at " << fname << std::endl;
ifstream script(fname); ifstream script(fname);
if (script.good()) if (script.good())
@ -528,6 +529,7 @@ static void loadScriptFile(Core *core, PluginManager *plug_mgr, string fname)
} }
else else
{ {
if(!silent)
core->getConsole().printerr("Error loading script\n"); core->getConsole().printerr("Error loading script\n");
} }
@ -551,7 +553,7 @@ void fIOthread(void * iodata)
return; return;
} }
loadScriptFile(core, plug_mgr, "dfhack.init"); loadScriptFile(core, plug_mgr, "dfhack.init", true);
con.print("DFHack is ready. Have a nice day!\n" con.print("DFHack is ready. Have a nice day!\n"
"Type in '?' or 'help' for general help, 'ls' to see all commands.\n"); "Type in '?' or 'help' for general help, 'ls' to see all commands.\n");

@ -25,6 +25,7 @@ distribution.
#include "Internal.h" #include "Internal.h"
#include <dirent.h> #include <dirent.h>
#include <errno.h> #include <errno.h>
#include <unistd.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <string> #include <string>

@ -398,16 +398,13 @@ struct dwarf_info
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{ {
// initialize labor infos table from default table // initialize labor infos table from default table
if(ARRAY_COUNT(default_labor_infos) != ENUM_LAST_ITEM(unit_labor) + 1)
return CR_FAILURE;
labor_infos = new struct labor_info[ARRAY_COUNT(default_labor_infos)]; labor_infos = new struct labor_info[ARRAY_COUNT(default_labor_infos)];
for (int i = 0; i < ARRAY_COUNT(default_labor_infos); i++) { for (int i = 0; i < ARRAY_COUNT(default_labor_infos); i++) {
labor_infos[i] = default_labor_infos[i]; labor_infos[i] = default_labor_infos[i];
} }
assert(ARRAY_COUNT(labor_infos) > ENUM_LAST_ITEM(unit_labor));
// Fill the command list with your commands. // Fill the command list with your commands.
commands.clear();
commands.push_back(PluginCommand( commands.push_back(PluginCommand(
"autolabor", "Automatically manage dwarf labors.", "autolabor", "Automatically manage dwarf labors.",
autolabor, false, /* true means that the command can't be used from non-interactive user interface */ autolabor, false, /* true means that the command can't be used from non-interactive user interface */