Tree Cleanup

- Switched from the addition of a LOCK tag to the removal of a ? tag.  The
  result is cleaner.
- Moved metadata into the ORIGINAL node.
This commit is contained in:
Paul Beckingham 2013-08-31 19:00:09 -04:00
parent e4671dd518
commit f293e74ae6

View file

@ -46,6 +46,7 @@ A3t::A3t (int argc, char** argv)
Tree* branch = _tree->addBranch (new Tree (format ("arg{1}", i))); Tree* branch = _tree->addBranch (new Tree (format ("arg{1}", i)));
branch->attribute ("raw", argv[i]); branch->attribute ("raw", argv[i]);
branch->tag ("ORIGINAL"); branch->tag ("ORIGINAL");
branch->tag ("?");
} }
} }
@ -99,9 +100,6 @@ bool A3t::canonicalize (
std::vector <std::string> matches; std::vector <std::string> matches;
if (autoComplete (value, options, matches, minimumMatchLength) == 1) if (autoComplete (value, options, matches, minimumMatchLength) == 1)
{ {
// for (auto& i: matches)
// std::cout << "match: " << i << "\n";
canonicalized = matches[0]; canonicalized = matches[0];
return true; return true;
} }
@ -116,8 +114,8 @@ void A3t::findBinary ()
{ {
if (_tree->_branches.size () >= 1) if (_tree->_branches.size () >= 1)
{ {
_tree->_branches[0]->unTag ("?");
_tree->_branches[0]->tag ("BINARY"); _tree->_branches[0]->tag ("BINARY");
_tree->_branches[0]->tag ("LOCK");
std::string binary = _tree->_branches[0]->attribute ("raw"); std::string binary = _tree->_branches[0]->attribute ("raw");
std::string::size_type slash = binary.rfind ('/'); std::string::size_type slash = binary.rfind ('/');
if (slash != std::string::npos) if (slash != std::string::npos)
@ -143,14 +141,14 @@ void A3t::findTerminator ()
{ {
if ((*i)->attribute ("raw") == "--") if ((*i)->attribute ("raw") == "--")
{ {
(*i)->unTag ("?");
(*i)->tag ("TERMINATOR"); (*i)->tag ("TERMINATOR");
(*i)->tag ("LOCK");
found = true; found = true;
} }
else if (found) else if (found)
{ {
(*i)->unTag ("?");
(*i)->tag ("WORD"); (*i)->tag ("WORD");
(*i)->tag ("LOCK");
} }
} }
} }
@ -168,40 +166,40 @@ void A3t::findCommand ()
if ((*i)->attribute ("raw") == "--") if ((*i)->attribute ("raw") == "--")
break; break;
// Skip locked args. // Skip known args.
if ((*i)->hasTag ("LOCK")) if (! (*i)->hasTag ("?"))
continue; continue;
if (canonicalize (command, "report", (*i)->attribute ("raw"))) if (canonicalize (command, "report", (*i)->attribute ("raw")))
{ {
(*i)->attribute ("canonical", command); (*i)->unTag ("?");
(*i)->tag ("REPORT");
(*i)->tag ("CMD"); (*i)->tag ("CMD");
(*i)->tag ("LOCK"); (*i)->tag ("REPORT");
(*i)->attribute ("canonical", command);
} }
else if (canonicalize (command, "readcmd", (*i)->attribute ("raw"))) else if (canonicalize (command, "readcmd", (*i)->attribute ("raw")))
{ {
(*i)->attribute ("canonical", command); (*i)->unTag ("?");
(*i)->tag ("READCMD");
(*i)->tag ("CMD"); (*i)->tag ("CMD");
(*i)->tag ("LOCK"); (*i)->tag ("READCMD");
(*i)->attribute ("canonical", command);
} }
else if (canonicalize (command, "writecmd", (*i)->attribute ("raw"))) else if (canonicalize (command, "writecmd", (*i)->attribute ("raw")))
{ {
(*i)->attribute ("canonical", command); (*i)->unTag ("?");
(*i)->tag ("WRITECMD");
(*i)->tag ("CMD"); (*i)->tag ("CMD");
(*i)->tag ("LOCK"); (*i)->tag ("WRITECMD");
(*i)->attribute ("canonical", command);
} }
else if (canonicalize (command, "specialcmd", (*i)->attribute ("raw"))) else if (canonicalize (command, "specialcmd", (*i)->attribute ("raw")))
{ {
(*i)->attribute ("canonical", command); (*i)->unTag ("?");
(*i)->tag ("SPECIALCMD");
(*i)->tag ("CMD"); (*i)->tag ("CMD");
(*i)->tag ("LOCK"); (*i)->tag ("SPECIALCMD");
(*i)->attribute ("canonical", command);
} }
} }
} }
@ -216,17 +214,16 @@ void A3t::findFileOverride ()
if ((*i)->attribute ("raw") == "--") if ((*i)->attribute ("raw") == "--")
break; break;
// Skip locked args. // Skip known args.
if ((*i)->hasTag ("LOCK")) if (! (*i)->hasTag ("?"))
continue; continue;
std::string arg = (*i)->attribute ("raw"); std::string arg = (*i)->attribute ("raw");
if (arg.find ("rc:") == 0) if (arg.find ("rc:") == 0)
{ {
(*i)->unTag ("?");
(*i)->tag ("RC"); (*i)->tag ("RC");
(*i)->tag ("LOCK"); (*i)->attribute ("file", arg.substr (3));
Tree* b = (*i)->addBranch (new Tree ("metadata"));
b->attribute ("file", arg.substr (3));
} }
} }
} }
@ -242,8 +239,8 @@ void A3t::findConfigOverride ()
if ((*i)->attribute ("raw") == "--") if ((*i)->attribute ("raw") == "--")
break; break;
// Skip locked args. // Skip known args.
if ((*i)->hasTag ("LOCK")) if (! (*i)->hasTag ("?"))
continue; continue;
std::string arg = (*i)->attribute ("raw"); std::string arg = (*i)->attribute ("raw");
@ -255,11 +252,10 @@ void A3t::findConfigOverride ()
if (sep != std::string::npos) if (sep != std::string::npos)
{ {
(*i)->unTag ("?");
(*i)->tag ("CONFIG"); (*i)->tag ("CONFIG");
(*i)->tag ("LOCK"); (*i)->attribute ("name", arg.substr (3, sep - 3));
Tree* b = (*i)->addBranch (new Tree ("metadata")); (*i)->attribute ("value", arg.substr (sep + 1));
b->attribute ("name", arg.substr (3, sep - 3));
b->attribute ("value", arg.substr (sep + 1));
} }
} }
} }
@ -276,8 +272,8 @@ void A3t::findPattern ()
if ((*i)->attribute ("raw") == "--") if ((*i)->attribute ("raw") == "--")
break; break;
// Skip locked args. // Skip known args.
if ((*i)->hasTag ("LOCK")) if (! (*i)->hasTag ("?"))
continue; continue;
Nibbler n ((*i)->attribute ("raw")); Nibbler n ((*i)->attribute ("raw"));
@ -286,10 +282,9 @@ void A3t::findPattern ()
n.depleted () && n.depleted () &&
pattern.length () > 0) pattern.length () > 0)
{ {
(*i)->unTag ("?");
(*i)->tag ("PATTERN"); (*i)->tag ("PATTERN");
(*i)->tag ("LOCK"); (*i)->attribute ("pattern", pattern);
Tree* b = (*i)->addBranch (new Tree ("metadata"));
b->attribute ("pattern", pattern);
} }
} }
} }
@ -305,8 +300,8 @@ void A3t::findSubstitution ()
if ((*i)->attribute ("raw") == "--") if ((*i)->attribute ("raw") == "--")
break; break;
// Skip locked args. // Skip known args.
if ((*i)->hasTag ("LOCK")) if (! (*i)->hasTag ("?"))
continue; continue;
std::string raw = (*i)->attribute ("raw"); std::string raw = (*i)->attribute ("raw");
@ -325,12 +320,11 @@ void A3t::findSubstitution ()
if (n.depleted () && if (n.depleted () &&
!Directory (raw).exists ()) !Directory (raw).exists ())
{ {
(*i)->unTag ("?");
(*i)->tag ("SUBSTITUTION"); (*i)->tag ("SUBSTITUTION");
(*i)->tag ("LOCK"); (*i)->attribute ("from", from);
Tree* b = (*i)->addBranch (new Tree ("metadata")); (*i)->attribute ("to", to);
b->attribute ("from", from); (*i)->attribute ("global", global ? 1 : 0);
b->attribute ("to", to);
b->attribute ("global", global ? 1 : 0);
} }
} }
} }
@ -347,8 +341,8 @@ void A3t::findTag ()
if ((*i)->attribute ("raw") == "--") if ((*i)->attribute ("raw") == "--")
break; break;
// Skip locked args. // Skip known args.
if ((*i)->hasTag ("LOCK")) if (! (*i)->hasTag ("?"))
continue; continue;
std::string raw = (*i)->attribute ("raw"); std::string raw = (*i)->attribute ("raw");
@ -361,11 +355,10 @@ void A3t::findTag ()
n.getUntilEOS (tag) && n.getUntilEOS (tag) &&
tag.find (' ') == std::string::npos) tag.find (' ') == std::string::npos)
{ {
(*i)->unTag ("?");
(*i)->tag ("TAG"); (*i)->tag ("TAG");
(*i)->tag ("LOCK"); (*i)->attribute ("sign", sign);
Tree* b = (*i)->addBranch (new Tree ("metadata")); (*i)->attribute ("tag", tag);
b->attribute ("sign", sign);
b->attribute ("tag", tag);
} }
} }
} }
@ -381,8 +374,8 @@ void A3t::findAttribute ()
if ((*i)->attribute ("raw") == "--") if ((*i)->attribute ("raw") == "--")
break; break;
// Skip locked args. // Skip known args.
if ((*i)->hasTag ("LOCK")) if (! (*i)->hasTag ("?"))
continue; continue;
std::string raw = (*i)->attribute ("raw"); std::string raw = (*i)->attribute ("raw");
@ -398,15 +391,14 @@ void A3t::findAttribute ()
std::string value; std::string value;
if (n.getUntilEOS (value)) if (n.getUntilEOS (value))
{ {
Tree* b = (*i)->addBranch (new Tree ("metadata"));
b->attribute ("value", value);
std::string canonical; std::string canonical;
if (canonicalize (canonical, "attribute", name)) if (canonicalize (canonical, "attribute", name))
{ {
(*i)->unTag ("?");
(*i)->tag ("ATTRIBUTE"); (*i)->tag ("ATTRIBUTE");
(*i)->tag ("LOCK"); (*i)->attribute ("name", canonical);
b->attribute ("name", canonical); (*i)->attribute ("value", value);
} }
if (canonicalize (canonical, "uda", name)) if (canonicalize (canonical, "uda", name))
@ -414,9 +406,10 @@ void A3t::findAttribute ()
if (canonicalize (canonical, "pseudo", name)) if (canonicalize (canonical, "pseudo", name))
{ {
(*i)->unTag ("?");
(*i)->tag ("PSEUDO"); (*i)->tag ("PSEUDO");
(*i)->tag ("LOCK"); (*i)->attribute ("name", canonical);
b->attribute ("name", canonical); (*i)->attribute ("value", value);
} }
} }
} }
@ -431,8 +424,7 @@ void A3t::validate ()
// Look for any unrecognized original args. // Look for any unrecognized original args.
std::vector <Tree*>::iterator i; std::vector <Tree*>::iterator i;
for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i) for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i)
if ((*i)->hasTag ("ORIGINAL") && if ((*i)->hasTag ("?"))
! (*i)->hasTag ("LOCK"))
//throw std::string ("Unrecognized argument '") + (*i)->attribute ("raw") + "'"; //throw std::string ("Unrecognized argument '") + (*i)->attribute ("raw") + "'";
std::cout << "Unrecognized argument '" << (*i)->attribute ("raw") << "'\n"; std::cout << "Unrecognized argument '" << (*i)->attribute ("raw") << "'\n";