From 96a06eafbf2ef6303978528f672c2a754f517b02 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 31 Aug 2013 10:55:30 -0400 Subject: [PATCH] A3t::find*Override - Locates and parses rc:. - Locates and parses rc.=. - Adds a stubbed validate method to check for a sane tree. --- src/parser/A3t.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++- src/parser/A3t.h | 3 +++ src/parser/run | 4 +-- 3 files changed, 68 insertions(+), 3 deletions(-) diff --git a/src/parser/A3t.cpp b/src/parser/A3t.cpp index bed0daff3..108eb86f3 100644 --- a/src/parser/A3t.cpp +++ b/src/parser/A3t.cpp @@ -58,6 +58,8 @@ Tree* A3t::parse () findBinary (); findTerminator (); findCommand (); + findFileOverride (); + findConfigOverride (); return _tree; } @@ -112,7 +114,12 @@ void A3t::findBinary () if (slash != std::string::npos) 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 ::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.[:=] +void A3t::findConfigOverride () +{ + std::vector ::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 () +{ +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/parser/A3t.h b/src/parser/A3t.h index ab3632c03..e1c27f719 100644 --- a/src/parser/A3t.h +++ b/src/parser/A3t.h @@ -44,6 +44,9 @@ private: void findBinary (); void findTerminator (); void findCommand (); + void findFileOverride (); + void findConfigOverride (); + void validate (); private: Tree* _tree; diff --git a/src/parser/run b/src/parser/run index 3525b2bea..c836e5611 100755 --- a/src/parser/run +++ b/src/parser/run @@ -8,6 +8,6 @@ #echo; ./args rc:x rc.debug:1 1234 done pri:H #echo; ./args rc:x rc.debug:1 a.b\