Added support for multiline commands inside dfhack.init and the script command.

develop
expwnent 2015-01-26 17:18:30 -05:00
parent 08110312ff
commit 1993c5fb1b
4 changed files with 53 additions and 12 deletions

@ -1,4 +1,12 @@
DFHack Future
Internals
Fixes
New Plugins
New Scripts
New Tweaks
Removed
Misc Improvements
Multiline commands are now possible inside dfhack.init scripts. See dfhack.init-example for example usage.
DFHack 0.40.24-r1
Internals

@ -242,6 +242,9 @@ To include a double quote character, use ``\"`` inside double quotes.
If the first non-whitespace character of a line is ``#``, the line is treated
as a comment, i.e. a silent no-op command.
When reading commands from dfhack.init or with the ``script`` command, if the final character on a line is a backslash then the next uncommented line is considered a continuation of that line, with the backslash converted to a space character.
Commented lines are skipped, so it is possible to comment out parts of a command with the ``#`` character.
If the first non-whitespace character is ``:``, the command is parsed in a special
alternative mode: first, non-whitespace characters immediately following the ``:``
are used as the command name; the remaining part of the line, starting with the first

@ -195,7 +195,23 @@ enable search
enable automaterial
# Other interface improvement tools
enable dwarfmonitor mousequery automelt autotrade buildingplan resume trackstop zone stocks autochop stockpiles
# enable dwarfmonitor mousequery automelt autotrade buildingplan resume trackstop zone stocks autochop stockpiles
enable \
dwarfmonitor \
mousequery \
automelt \
autotrade \
buildingplan \
resume \
trackstop \
zone \
stocks \
autochop \
stockpiles
#end a line with a backslash to make it continue to the next line. The \ is converted to a space for the final command.
# Multiline commands are ONLY supported for scripts like dfhack.init. You cannot do multiline command manually on the DFHack console.
# You cannot extend a commented line.
# You can comment out the extension of a line.
# allow the fortress bookkeeper to queue jobs through the manager
stockflow enable

@ -824,22 +824,36 @@ bool Core::loadScriptFile(color_ostream &out, string fname, bool silent)
if(!silent)
out << "Loading script at " << fname << std::endl;
ifstream script(fname.c_str());
if (script.good())
{
string command;
while (getline(script, command))
{
if (!command.empty())
runCommand(out, command);
}
return true;
}
else
if ( !script.good() )
{
if(!silent)
out.printerr("Error loading script\n");
return false;
}
string command;
while(script.good()) {
string temp;
getline(script,temp);
bool doMore = false;
if ( temp.length() > 0 ) {
if ( temp[0] == '#' )
continue;
if ( temp[temp.length()-1] == '\r' )
temp = temp.substr(0,temp.length()-1);
if ( temp.length() > 0 ) {
if ( temp[temp.length()-1] == '\\' ) {
temp[temp.length()-1] = ' ';
doMore = true;
}
}
}
command = command + temp;
if ( (!doMore || !script.good()) && !command.empty() ) {
runCommand(out, command);
command = "";
}
}
return true;
}
static void run_dfhack_init(color_ostream &out, Core *core)