From 485899b0c5edc80a4d7d59b0754a6e7a599f5283 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 13 Jun 2015 14:34:25 -0400 Subject: [PATCH] CLI2: Begun ::analyze method - Renamed A to A2, to avoid collisions for now. - Added A2::attribute, ctor, dtor. - Stubbbed CLI2::analyze. --- src/CLI2.cpp | 93 ++++++++++++++++++++++++++++++++++++------------- src/CLI2.h | 18 ++++++---- src/Context.cpp | 2 ++ 3 files changed, 82 insertions(+), 31 deletions(-) diff --git a/src/CLI2.cpp b/src/CLI2.cpp index 2b87fcb95..d9b61259a 100644 --- a/src/CLI2.cpp +++ b/src/CLI2.cpp @@ -46,39 +46,40 @@ int CLI2::minimumMatchLength = 3; static int safetyValveDefault = 10; //////////////////////////////////////////////////////////////////////////////// -A::A () +A2::A2 () : _name ("") { } - +*/ //////////////////////////////////////////////////////////////////////////////// -A::A (const std::string& name, const std::string& raw) +A2::A2 (const std::string& name, const std::string& raw) +{ + _name = name; + attribute ("raw", raw); +} + +/* +//////////////////////////////////////////////////////////////////////////////// +A2::A2 (const std::string& name, const int raw) { _name = name; attribute ("raw", raw); } //////////////////////////////////////////////////////////////////////////////// -A::A (const std::string& name, const int raw) +A2::A2 (const std::string& name, const double raw) { _name = name; attribute ("raw", raw); } //////////////////////////////////////////////////////////////////////////////// -A::A (const std::string& name, const double raw) -{ - _name = name; - attribute ("raw", raw); -} - -//////////////////////////////////////////////////////////////////////////////// -A::~A () +A2::~A2 () { } //////////////////////////////////////////////////////////////////////////////// -A::A (const A& other) +A2::A2 (const A2& other) : _name (other._name) , _tags (other._tags) , _attributes (other._attributes) @@ -86,7 +87,7 @@ A::A (const A& other) } //////////////////////////////////////////////////////////////////////////////// -A& A::operator= (const A& other) +A2& A2::operator= (const A2& other) { if (this != &other) { @@ -99,7 +100,7 @@ A& A::operator= (const A& other) } //////////////////////////////////////////////////////////////////////////////// -bool A::hasTag (const std::string& tag) const +bool A2::hasTag (const std::string& tag) const { if (std::find (_tags.begin (), _tags.end (), tag) != _tags.end ()) return true; @@ -108,14 +109,14 @@ bool A::hasTag (const std::string& tag) const } //////////////////////////////////////////////////////////////////////////////// -void A::tag (const std::string& tag) +void A2::tag (const std::string& tag) { if (! hasTag (tag)) _tags.push_back (tag); } //////////////////////////////////////////////////////////////////////////////// -void A::unTag (const std::string& tag) +void A2::unTag (const std::string& tag) { for (auto i = _tags.begin (); i != _tags.end (); ++i) { @@ -128,35 +129,37 @@ void A::unTag (const std::string& tag) } //////////////////////////////////////////////////////////////////////////////// -void A::unTagAll () +void A2::unTagAll () { _tags.clear (); } +*/ //////////////////////////////////////////////////////////////////////////////// // Accessor for attributes. -void A::attribute (const std::string& name, const std::string& value) +void A2::attribute (const std::string& name, const std::string& value) { _attributes[name] = value; } +/* //////////////////////////////////////////////////////////////////////////////// // Accessor for attributes. -void A::attribute (const std::string& name, const int value) +void A2::attribute (const std::string& name, const int value) { _attributes[name] = format (value); } //////////////////////////////////////////////////////////////////////////////// // Accessor for attributes. -void A::attribute (const std::string& name, const double value) +void A2::attribute (const std::string& name, const double value) { _attributes[name] = format (value, 1, 8); } //////////////////////////////////////////////////////////////////////////////// // Accessor for attributes. -const std::string A::attribute (const std::string& name) const +const std::string A2::attribute (const std::string& name) const { // Prevent autovivification. auto i = _attributes.find (name); @@ -167,13 +170,13 @@ const std::string A::attribute (const std::string& name) const } //////////////////////////////////////////////////////////////////////////////// -void A::removeAttribute (const std::string& name) +void A2::removeAttribute (const std::string& name) { _attributes.erase (name); } //////////////////////////////////////////////////////////////////////////////// -const std::string A::dump () const +const std::string A2::dump () const { std::string output = _name; @@ -337,6 +340,48 @@ void CLI2::add (const std::string& argument) _original_args.push_back (argument); } +//////////////////////////////////////////////////////////////////////////////// +// Intended to be called after ::add() to perform the final analysis. +void CLI2::analyze () +{ + for (unsigned int i = 0; i < _original_args.size (); ++i) + { + std::string raw = _original_args[i]; + A a ("arg", raw); +/* + a.tag ("ORIGINAL"); + + if (i == 0) + { + a.tag ("BINARY"); + + std::string basename = "task"; + auto slash = raw.rfind ('/'); + if (slash != std::string::npos) + basename = raw.substr (slash + 1); + + a.attribute ("basename", basename); + if (basename == "cal" || basename == "calendar") + a.tag ("CALENDAR"); + else if (basename == "task" || basename == "tw" || basename == "t") + a.tag ("TW"); + } +*/ + _args.push_back (a); + +/* + if (a.hasTag ("CALENDAR")) + { + A cal ("argCal", "calendar"); + _args.push_back (cal); + } +*/ + } + + if (context.config.getInteger ("debug.parser") >= 3) + context.debug ("CLI2::analyze end"); +} + /* //////////////////////////////////////////////////////////////////////////////// // Capture the original, intact command line arguments. diff --git a/src/CLI2.h b/src/CLI2.h index 9f17772a0..f878f5d13 100644 --- a/src/CLI2.h +++ b/src/CLI2.h @@ -35,12 +35,12 @@ */ // Represents a single argument. -/* -class A +class A2 { public: - A (); - A (const std::string&, const std::string&); + A2 (); + A2 (const std::string&, const std::string&); +/* A (const std::string&, const int); A (const std::string&, const double); ~A (); @@ -50,19 +50,22 @@ public: void tag (const std::string&); void unTag (const std::string&); void unTagAll (); +*/ void attribute (const std::string&, const std::string&); +/* void attribute (const std::string&, const int); void attribute (const std::string&, const double); const std::string attribute (const std::string&) const; void removeAttribute (const std::string&); const std::string dump () const; - +*/ public: std::string _name; +/* std::vector _tags; +*/ std::map _attributes; }; -*/ // Represents the command line. class CLI2 @@ -81,6 +84,7 @@ public: void entity (const std::string&, const std::string&); void add (const std::string&); + void analyze (); /* void initialize (int, const char**); void add (const std::string&); @@ -146,9 +150,9 @@ public: std::multimap _entities; std::map _aliases; std::vector _original_args; -/* std::vector _args; +/* std::vector > _id_ranges; std::vector _uuid_list; bool _strict; diff --git a/src/Context.cpp b/src/Context.cpp index f2cd375d3..88d36de65 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -229,6 +229,8 @@ int Context::initialize (int argc, const char** argv) for (int i = 0; i < argc; i++) cli2.add (argv[i]); + cli2.analyze (); + cli.initialize (argc, argv); cli.analyze (true, true);