A3t::find*Override

- Locates and parses rc:<file>.
- Locates and parses rc.<name>=<value>.
- Adds a stubbed validate method to check for a sane tree.
This commit is contained in:
Paul Beckingham 2013-08-31 10:55:30 -04:00
parent ac1497ff1a
commit 96a06eafbf
3 changed files with 68 additions and 3 deletions

View file

@ -58,6 +58,8 @@ Tree* A3t::parse ()
findBinary (); findBinary ();
findTerminator (); findTerminator ();
findCommand (); findCommand ();
findFileOverride ();
findConfigOverride ();
return _tree; return _tree;
} }
@ -112,7 +114,12 @@ void A3t::findBinary ()
if (slash != std::string::npos) if (slash != std::string::npos)
binary = binary.substr (slash + 1); binary = binary.substr (slash + 1);
_tree->_branches[0]->attribute ("basename", "binary"); _tree->_branches[0]->attribute ("basename", binary);
if (binary == "cal" || binary == "calendar")
_tree->_branches[0]->tag ("CALENDAR");
else
_tree->_branches[0]->tag ("TW");
} }
} }
@ -176,3 +183,58 @@ void A3t::findCommand ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void A3t::findFileOverride ()
{
std::vector <Tree*>::iterator i;
for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i)
{
// Parser override operator.
if ((*i)->attribute ("raw") == "--")
break;
std::string arg = (*i)->attribute ("raw");
if (arg.find ("rc:") == 0)
{
(*i)->tag ("RC");
Tree* b = (*i)->addBranch (new Tree ("data"));
b->attribute ("file", arg.substr (3));
}
}
}
////////////////////////////////////////////////////////////////////////////////
// rc.<name>[:=]<value>
void A3t::findConfigOverride ()
{
std::vector <Tree*>::iterator i;
for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i)
{
// Parser override operator.
if ((*i)->attribute ("raw") == "--")
break;
std::string arg = (*i)->attribute ("raw");
if (arg.find ("rc.") == 0)
{
std::string::size_type sep = arg.find ('=', 3);
if (sep == std::string::npos)
sep = arg.find (':', 3);
if (sep != std::string::npos)
{
(*i)->tag ("CONFIG");
Tree* b = (*i)->addBranch (new Tree ("data"));
b->attribute ("name", arg.substr (3, sep - 3));
b->attribute ("value", arg.substr (sep + 1));
}
}
}
}
////////////////////////////////////////////////////////////////////////////////
// Validate the parse tree.
void A3t::validate ()
{
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -44,6 +44,9 @@ private:
void findBinary (); void findBinary ();
void findTerminator (); void findTerminator ();
void findCommand (); void findCommand ();
void findFileOverride ();
void findConfigOverride ();
void validate ();
private: private:
Tree* _tree; Tree* _tree;

View file

@ -8,6 +8,6 @@
#echo; ./args rc:x rc.debug:1 1234 done pri:H #echo; ./args rc:x rc.debug:1 1234 done pri:H
#echo; ./args rc:x rc.debug:1 a.b\<c \(one or two\) modify 'quoted string' \'not quoted\' due:eom+1wk+1d #echo; ./args rc:x rc.debug:1 a.b\<c \(one or two\) modify 'quoted string' \'not quoted\' due:eom+1wk+1d
echo; ./args 123 mod pro:'P 1' +home /from/to/g echo; ./args rc:~/.taskrc 123 mod pro:'P 1' +home /from/to/g rc.name=value
echo; ./args add -- modify +tag /from/to/g name:value echo; ./args rc:~/..taskrc rc.name=value add -- modify +tag /from/to/g name:value