Portability: Updated to make main re-entrant()

- New INSTALL instructions to emscripten, and AUTHORS for contribution.
This commit is contained in:
Mark Scannell
2018-01-31 19:45:07 -05:00
committed by Paul Beckingham
parent cae3f06b7d
commit 7af6db4c17
112 changed files with 960 additions and 1147 deletions

View File

@@ -35,8 +35,6 @@
#include <shared.h>
#include <format.h>
extern Context context;
// Overridden by rc.abbreviation.minimum.
int CLI2::minimumMatchLength = 3;
@@ -235,7 +233,7 @@ void CLI2::getOverride (int argc, const char** argv, std::string& home, File& rc
if (last_slash != std::string::npos)
home = rc.parent ();
context.header (format ("Using alternate .taskrc file {1}", rc._data));
Context::getContext ().header (format ("Using alternate .taskrc file {1}", rc._data));
// Keep looping, because if there are multiple rc:file arguments, the last
// one should dominate.
@@ -248,7 +246,7 @@ void CLI2::getOverride (int argc, const char** argv, std::string& home, File& rc
// Static method.
void CLI2::getDataLocation (int argc, const char** argv, Path& data)
{
std::string location = context.config.get ("data.location");
std::string location = Context::getContext ().config.get ("data.location");
if (location != "")
data = location;
@@ -262,7 +260,7 @@ void CLI2::getDataLocation (int argc, const char** argv, Path& data)
raw.substr (0, 16) == "rc.data.location")
{
data = Directory (raw.substr (17));
context.header (format ("Using alternate data.location {1}", (std::string) data));
Context::getContext ().header (format ("Using alternate data.location {1}", (std::string) data));
// Keep looping, because if there are multiple rc:file arguments, the last
// one should dominate.
@@ -297,10 +295,10 @@ void CLI2::applyOverrides (int argc, const char** argv)
{
std::string name = raw.substr (3, sep - 3);
std::string value = raw.substr (sep + 1);
context.config.set (name, value);
Context::getContext ().config.set (name, value);
if (context.verbose("override"))
context.footnote (format ("Configuration override rc.{1}:{2}", name, value));
if (Context::getContext ().verbose("override"))
Context::getContext ().footnote (format ("Configuration override rc.{1}:{2}", name, value));
}
}
}
@@ -469,8 +467,8 @@ void CLI2::lexArguments ()
}
}
if (context.config.getInteger ("debug.parser") >= 2)
context.debug (dump ("CLI2::analyze lexArguments"));
if (Context::getContext ().config.getInteger ("debug.parser") >= 2)
Context::getContext ().debug (dump ("CLI2::analyze lexArguments"));
}
////////////////////////////////////////////////////////////////////////////////
@@ -500,7 +498,7 @@ void CLI2::demotion ()
else if (a._lextype == Lexer::Type::pair &&
canonicalize (canonical, "pseudo", a.attribute ("name")))
{
context.config.set (canonical, a.attribute ("value"));
Context::getContext ().config.set (canonical, a.attribute ("value"));
changes = true;
// Equivalent to erasing 'a'.
@@ -511,16 +509,16 @@ void CLI2::demotion ()
}
if (changes &&
context.config.getInteger ("debug.parser") >= 2)
context.debug (dump ("CLI2::analyze demotion"));
Context::getContext ().config.getInteger ("debug.parser") >= 2)
Context::getContext ().debug (dump ("CLI2::analyze demotion"));
}
////////////////////////////////////////////////////////////////////////////////
// Intended to be called after ::add() to perform the final analysis.
void CLI2::analyze ()
{
if (context.config.getInteger ("debug.parser") >= 2)
context.debug (dump ("CLI2::analyze"));
if (Context::getContext ().config.getInteger ("debug.parser") >= 2)
Context::getContext ().debug (dump ("CLI2::analyze"));
// Process _original_args.
_args.clear ();
@@ -577,10 +575,10 @@ void CLI2::addContextFilter ()
return;
// Detect if any context is set, and bail out if not
std::string contextName = context.config.get ("context");
std::string contextName = Context::getContext ().config.get ("context");
if (contextName == "")
{
context.debug ("No context.");
Context::getContext ().debug ("No context.");
return;
}
@@ -591,23 +589,23 @@ void CLI2::addContextFilter ()
a._lextype == Lexer::Type::number ||
a._lextype == Lexer::Type::set)
{
context.debug (format ("UUID/ID argument found '{1}', not applying context.", a.attribute ("raw")));
Context::getContext ().debug (format ("UUID/ID argument found '{1}', not applying context.", a.attribute ("raw")));
return;
}
}
// Apply context
context.debug ("Applying context: " + contextName);
std::string contextFilter = context.config.get ("context." + contextName);
Context::getContext ().debug ("Applying context: " + contextName);
std::string contextFilter = Context::getContext ().config.get ("context." + contextName);
if (contextFilter == "")
context.debug ("Context '" + contextName + "' not defined.");
Context::getContext ().debug ("Context '" + contextName + "' not defined.");
else
{
_context_filter_added = true;
addFilter (contextFilter);
if (context.verbose ("context"))
context.footnote (format ("Context '{1}' set. Use 'task context none' to remove.", contextName));
if (Context::getContext ().verbose ("context"))
Context::getContext ().footnote (format ("Context '{1}' set. Use 'task context none' to remove.", contextName));
}
}
@@ -633,7 +631,7 @@ void CLI2::prepareFilter ()
desugarFilterPatterns ();
insertJunctions (); // Deliberately after all desugar calls.
if (context.verbose ("filter"))
if (Context::getContext ().verbose ("filter"))
{
std::string combined;
for (const auto& a : _args)
@@ -648,7 +646,7 @@ void CLI2::prepareFilter ()
}
if (combined.size ())
context.footnote (std::string ("Filter: ") + combined);
Context::getContext ().footnote (std::string ("Filter: ") + combined);
}
}
@@ -661,13 +659,13 @@ const std::vector <std::string> CLI2::getWords ()
if (a.hasTag ("MISCELLANEOUS"))
words.push_back (a.attribute ("raw"));
if (context.config.getInteger ("debug.parser") >= 2)
if (Context::getContext ().config.getInteger ("debug.parser") >= 2)
{
Color colorOrigArgs ("gray10 on gray4");
std::string message = " ";
for (const auto& word : words)
message += colorOrigArgs.colorize (word) + ' ';
context.debug ("CLI2::getWords" + message);
Context::getContext ().debug ("CLI2::getWords" + message);
}
return words;
@@ -854,11 +852,11 @@ void CLI2::aliasExpansion ()
while (action && counter++ < safetyValveDefault);
if (counter >= safetyValveDefault)
context.debug (format ("Nested alias limit of {1} reached.", safetyValveDefault));
Context::getContext ().debug (format ("Nested alias limit of {1} reached.", safetyValveDefault));
if (changes &&
context.config.getInteger ("debug.parser") >= 2)
context.debug (dump ("CLI2::analyze aliasExpansion"));
Context::getContext ().config.getInteger ("debug.parser") >= 2)
Context::getContext ().debug (dump ("CLI2::analyze aliasExpansion"));
}
////////////////////////////////////////////////////////////////////////////////
@@ -892,8 +890,8 @@ void CLI2::canonicalizeNames ()
}
if (changes &&
context.config.getInteger ("debug.parser") >= 2)
context.debug (dump ("CLI2::analyze canonicalizeNames"));
Context::getContext ().config.getInteger ("debug.parser") >= 2)
Context::getContext ().debug (dump ("CLI2::analyze canonicalizeNames"));
}
////////////////////////////////////////////////////////////////////////////////
@@ -902,7 +900,7 @@ void CLI2::categorizeArgs ()
{
// Context is only applied for commands that request it.
std::string command = getCommand ();
Command* cmd = context.commands[command];
Command* cmd = Context::getContext ().commands[command];
if (cmd && cmd->uses_context ())
addContextFilter ();
@@ -1013,8 +1011,8 @@ void CLI2::categorizeArgs ()
}
if (changes &&
context.config.getInteger ("debug.parser") >= 2)
context.debug (dump ("CLI2::analyze categorizeArgs"));
Context::getContext ().config.getInteger ("debug.parser") >= 2)
Context::getContext ().debug (dump ("CLI2::analyze categorizeArgs"));
}
////////////////////////////////////////////////////////////////////////////////
@@ -1082,8 +1080,8 @@ void CLI2::parenthesizeOriginalFilter ()
_args = reconstructed;
if (context.config.getInteger ("debug.parser") >= 2)
context.debug (dump ("CLI2::analyze parenthesizeOriginalFilter"));
if (Context::getContext ().config.getInteger ("debug.parser") >= 2)
Context::getContext ().debug (dump ("CLI2::analyze parenthesizeOriginalFilter"));
}
}
@@ -1114,7 +1112,7 @@ bool CLI2::findCommand ()
a.tag ("CMD");
// Apply command DNA as tags.
Command* command = context.commands[canonical];
Command* command = Context::getContext ().commands[canonical];
if (command->read_only ()) a.tag ("READONLY");
if (command->displays_id ()) a.tag ("SHOWSID");
if (command->needs_gc ()) a.tag ("RUNSGC");
@@ -1123,8 +1121,8 @@ bool CLI2::findCommand ()
if (command->accepts_modifications ()) a.tag ("ALLOWSMODIFICATIONS");
if (command->accepts_miscellaneous ()) a.tag ("ALLOWSMISC");
if (context.config.getInteger ("debug.parser") >= 2)
context.debug (dump ("CLI2::analyze findCommand"));
if (Context::getContext ().config.getInteger ("debug.parser") >= 2)
Context::getContext ().debug (dump ("CLI2::analyze findCommand"));
// Stop and indicate command found.
return true;
@@ -1185,8 +1183,8 @@ void CLI2::desugarFilterTags ()
{
_args = reconstructed;
if (context.config.getInteger ("debug.parser") >= 2)
context.debug (dump ("CLI2::prepareFilter desugarFilterTags"));
if (Context::getContext ().config.getInteger ("debug.parser") >= 2)
Context::getContext ().debug (dump ("CLI2::prepareFilter desugarFilterTags"));
}
}
@@ -1211,8 +1209,8 @@ void CLI2::findStrayModifications ()
}
if (changes)
if (context.config.getInteger ("debug.parser") >= 2)
context.debug (dump ("CLI2::prepareFilter findStrayModifications"));
if (Context::getContext ().config.getInteger ("debug.parser") >= 2)
Context::getContext ().debug (dump ("CLI2::prepareFilter findStrayModifications"));
}
////////////////////////////////////////////////////////////////////////////////
@@ -1249,12 +1247,12 @@ void CLI2::desugarFilterAttributes ()
// )
// Use this sequence in place of a single value.
std::vector <A2> values = lexExpression (value);
if (context.config.getInteger ("debug.parser") >= 2)
if (Context::getContext ().config.getInteger ("debug.parser") >= 2)
{
context.debug ("CLI2::lexExpression " + name + ':' + value);
Context::getContext ().debug ("CLI2::lexExpression " + name + ':' + value);
for (auto& v : values)
context.debug (" " + v.dump ());
context.debug (" ");
Context::getContext ().debug (" " + v.dump ());
Context::getContext ().debug (" ");
}
bool found = false;
@@ -1267,7 +1265,7 @@ void CLI2::desugarFilterAttributes ()
// date --> yes
// duration --> yes
bool evalSupported = true;
Column* col = context.columns[canonical];
Column* col = Context::getContext ().columns[canonical];
if (col && col->type () == "string")
evalSupported = false;
@@ -1413,8 +1411,8 @@ void CLI2::desugarFilterAttributes ()
{
_args = reconstructed;
if (context.config.getInteger ("debug.parser") >= 2)
context.debug (dump ("CLI2::prepareFilter desugarFilterAttributes"));
if (Context::getContext ().config.getInteger ("debug.parser") >= 2)
Context::getContext ().debug (dump ("CLI2::prepareFilter desugarFilterAttributes"));
}
}
@@ -1452,8 +1450,8 @@ void CLI2::desugarFilterPatterns ()
{
_args = reconstructed;
if (context.config.getInteger ("debug.parser") >= 2)
context.debug (dump ("CLI2::prepareFilter desugarFilterPatterns"));
if (Context::getContext ().config.getInteger ("debug.parser") >= 2)
Context::getContext ().debug (dump ("CLI2::prepareFilter desugarFilterPatterns"));
}
}
@@ -1470,7 +1468,7 @@ void CLI2::findIDs ()
{
bool changes = false;
if (context.config.getBoolean ("sugar"))
if (Context::getContext ().config.getBoolean ("sugar"))
{
bool previousFilterArgWasAnOperator = false;
int filterCount = 0;
@@ -1590,8 +1588,8 @@ void CLI2::findIDs ()
}
if (changes)
if (context.config.getInteger ("debug.parser") >= 2)
context.debug (dump ("CLI2::prepareFilter findIDs"));
if (Context::getContext ().config.getInteger ("debug.parser") >= 2)
Context::getContext ().debug (dump ("CLI2::prepareFilter findIDs"));
}
////////////////////////////////////////////////////////////////////////////////
@@ -1599,7 +1597,7 @@ void CLI2::findUUIDs ()
{
bool changes = false;
if (context.config.getBoolean ("sugar"))
if (Context::getContext ().config.getBoolean ("sugar"))
{
for (const auto& a : _args)
{
@@ -1651,8 +1649,8 @@ void CLI2::findUUIDs ()
}
if (changes)
if (context.config.getInteger ("debug.parser") >= 2)
context.debug (dump ("CLI2::prepareFilter findUUIDs"));
if (Context::getContext ().config.getInteger ("debug.parser") >= 2)
Context::getContext ().debug (dump ("CLI2::prepareFilter findUUIDs"));
}
////////////////////////////////////////////////////////////////////////////////
@@ -1798,8 +1796,8 @@ void CLI2::insertIDExpr ()
{
_args = reconstructed;
if (context.config.getInteger ("debug.parser") >= 2)
context.debug (dump ("CLI2::prepareFilter insertIDExpr"));
if (Context::getContext ().config.getInteger ("debug.parser") >= 2)
Context::getContext ().debug (dump ("CLI2::prepareFilter insertIDExpr"));
}
}
@@ -1835,8 +1833,8 @@ void CLI2::lexFilterArgs ()
{
_args = reconstructed;
if (context.config.getInteger ("debug.parser") >= 2)
context.debug (dump ("CLI2::prepareFilter lexFilterArgs"));
if (Context::getContext ().config.getInteger ("debug.parser") >= 2)
Context::getContext ().debug (dump ("CLI2::prepareFilter lexFilterArgs"));
}
}
@@ -1942,8 +1940,8 @@ void CLI2::desugarFilterPlainArgs ()
{
_args = reconstructed;
if (context.config.getInteger ("debug.parser") >= 2)
context.debug (dump ("CLI2::prepareFilter desugarFilterPlainArgs"));
if (Context::getContext ().config.getInteger ("debug.parser") >= 2)
Context::getContext ().debug (dump ("CLI2::prepareFilter desugarFilterPlainArgs"));
}
}
@@ -1996,8 +1994,8 @@ void CLI2::insertJunctions ()
{
_args = reconstructed;
if (context.config.getInteger ("debug.parser") >= 2)
context.debug (dump ("CLI2::prepareFilter insertJunctions"));
if (Context::getContext ().config.getInteger ("debug.parser") >= 2)
Context::getContext ().debug (dump ("CLI2::prepareFilter insertJunctions"));
}
}
@@ -2037,7 +2035,7 @@ void CLI2::defaultCommand ()
if (! found_sequence)
{
// Apply overrides, if any.
std::string defaultCommand = context.config.get ("default.command");
std::string defaultCommand = Context::getContext ().config.get ("default.command");
if (defaultCommand != "")
{
// Modify _args, _original_args to be:
@@ -2080,8 +2078,8 @@ void CLI2::defaultCommand ()
}
if (changes &&
context.config.getInteger ("debug.parser") >= 2)
context.debug (dump ("CLI2::analyze defaultCommand"));
Context::getContext ().config.getInteger ("debug.parser") >= 2)
Context::getContext ().debug (dump ("CLI2::analyze defaultCommand"));
}
////////////////////////////////////////////////////////////////////////////////