diff --git a/src/Arguments.cpp b/src/Arguments.cpp index 90501d20f..b8955a23b 100644 --- a/src/Arguments.cpp +++ b/src/Arguments.cpp @@ -969,6 +969,150 @@ bool Arguments::extract_tag ( return false; } +//////////////////////////////////////////////////////////////////////////////// +Arguments Arguments::extract_read_only_filter () +{ + Arguments filter; + + std::vector >::iterator i; + for (i = this->begin (); i != this->end (); ++i) + { + // Excluded. + if (i->second == "program" || + i->second == "command" || + i->second == "rc" || + i->second == "override") + { + ; + } + + // Included. + else if (i->second == "tag" || + i->second == "pattern" || + i->second == "attribute" || + i->second == "attmod" || + i->second == "id" || + i->second == "uuid" || + i->second == "word") + { + filter.push_back (*i); + } + + // Error. + else + { + // substitution + throw std::string ("A substitutions '") + i->first + "' is not allowed " + "in a read-only command filter."; + } + } + + return filter; +} + +//////////////////////////////////////////////////////////////////////////////// +Arguments Arguments::extract_write_filter () +{ + Arguments filter; + + std::vector >::iterator i; + for (i = this->begin (); i != this->end (); ++i) + { + // Only use args prior to command. + if (i->second == "command") + break; + + // Excluded. + else if (i->second == "program" || + i->second == "rc" || + i->second == "override") + { + ; + } + + // Included. + else if (i->second == "tag" || + i->second == "pattern" || + i->second == "attribute" || + i->second == "attmod" || + i->second == "id" || + i->second == "uuid" || + i->second == "word") + { + filter.push_back (*i); + } + + // Error. + else + { + // substitution + throw std::string ("A substitutions '") + + i->first + + "' is not allowed in a read-only command filter."; + } + } + + return filter; +} + +//////////////////////////////////////////////////////////////////////////////// +Arguments Arguments::extract_modifications () +{ + Arguments modifications; + + bool seen_command = false; + std::vector >::iterator i; + for (i = this->begin (); i != this->end (); ++i) + { + // Only use args after command. + if (i->second == "command") + { + seen_command = true; + } + + else if (seen_command) + { + // Excluded. + if (i->second == "program" || + i->second == "rc" || + i->second == "override") + { + } + + // Included. + else if (i->second == "tag" || + i->second == "attribute" || + i->second == "substitution" || + i->second == "word") + { + modifications.push_back (*i); + } + + // Error. + else + { + if (i->second == "pattern") + throw std::string ("A pattern '") + + i->first + + "' is not allowed when modifiying a task."; + + else if (i->second == "attmod") + throw std::string ("Attribute modifiers '") + + i->first + + "' are not allowed when modifiying a task."; + + else if (i->second == "id") + throw std::string ("A task id cannot be modified."); + + else if (i->second == "uuid") + throw std::string ("A task uuid cannot be modified."); + } + } + } + + return modifications; +} + //////////////////////////////////////////////////////////////////////////////// bool Arguments::valid_modifier (const std::string& modifier) { diff --git a/src/Arguments.h b/src/Arguments.h index 4cb246a2f..b0cda3bbc 100644 --- a/src/Arguments.h +++ b/src/Arguments.h @@ -64,6 +64,7 @@ public: bool is_uuid (const std::string&); bool is_tag (const std::string&); + // TODO Decide if these are really useful. bool extract_attr (const std::string&, std::string&, std::string&); bool extract_attmod (const std::string&, std::string&, std::string&, std::string&, std::string&); bool extract_subst (const std::string&, std::string&, std::string&, bool&); @@ -72,11 +73,9 @@ public: bool extract_uuid (const std::string&, std::vector &); bool extract_tag (const std::string&, char&, std::string&); -/* - void extract_filter (); - void extract_modifications (); - void extract_words (); -*/ + Arguments extract_read_only_filter (); + Arguments extract_write_filter (); + Arguments extract_modifications (); bool valid_modifier (const std::string&); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e66d0fa3b..90c52c686 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,6 +15,7 @@ set (task_SRCS API.cpp API.h Date.cpp Date.h Directory.cpp Directory.h Duration.cpp Duration.h + Expression.cpp Expression.h File.cpp File.h Filter.cpp Filter.h Hooks.cpp Hooks.h diff --git a/src/Expression.cpp b/src/Expression.cpp new file mode 100644 index 000000000..5a4fef3d1 --- /dev/null +++ b/src/Expression.cpp @@ -0,0 +1,66 @@ +//////////////////////////////////////////////////////////////////////////////// +// taskwarrior - a command line task list manager. +// +// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez. +// All rights reserved. +// +// This program is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free Software +// Foundation; either version 2 of the License, or (at your option) any later +// version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +// details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, write to the +// +// Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, +// Boston, MA +// 02110-1301 +// USA +// +//////////////////////////////////////////////////////////////////////////////// + +#include + +//////////////////////////////////////////////////////////////////////////////// +Expression::Expression () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +Expression::Expression (Arguments& arguments) +{ +} + +//////////////////////////////////////////////////////////////////////////////// +Expression::~Expression () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +bool Expression::eval (Task& task) +{ + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +void Expression::toInfix () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +void Expression::toPostfix () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +void Expression::dump (const std::string& label) +{ +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/Expression.h b/src/Expression.h new file mode 100644 index 000000000..33da38890 --- /dev/null +++ b/src/Expression.h @@ -0,0 +1,51 @@ +//////////////////////////////////////////////////////////////////////////////// +// taskwarrior - a command line task list manager. +// +// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez. +// All rights reserved. +// +// This program is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free Software +// Foundation; either version 2 of the License, or (at your option) any later +// version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +// details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, write to the +// +// Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, +// Boston, MA +// 02110-1301 +// USA +// +//////////////////////////////////////////////////////////////////////////////// +#ifndef INCLUDED_EXPRESSION +#define INCLUDED_EXPRESSION +#define L10N // Localization complete. + +#include +#include +#include + +class Expression +{ +public: + Expression (); + Expression (Arguments&); + ~Expression (); + bool eval (Task&); + + void dump (const std::string&); + +private: + void toInfix (); + void toPostfix (); +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdCustom.cpp b/src/commands/CmdCustom.cpp index a7788237d..5a3ea5a80 100644 --- a/src/commands/CmdCustom.cpp +++ b/src/commands/CmdCustom.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -81,62 +82,20 @@ int CmdCustom::execute (std::string& output) split (sortOrder, reportSort, ','); validateSortColumns (sortOrder); -/* - // Apply rc overrides. - std::vector filterArgs; - std::vector filteredArgs; - split (filterArgs, reportFilter, ' '); -// context.applyOverrides (filterArgs, filteredArgs); -*/ - -/* - { - Cmd cmd (_keyword); - Task task; - Sequence sequence; - Subst subst; - Filter filter; - context.parse (filteredArgs, cmd, task, sequence, subst, filter); - - context.sequence.combine (sequence); - - // Special case: Allow limit to be overridden by the command line. - if (!context.task.has ("limit") && task.has ("limit")) - context.task.set ("limit", task.get ("limit")); - - Filter::iterator att; - for (att = filter.begin (); att != filter.end (); ++att) - context.filter.push_back (*att); - } -*/ - // Load the data. + // TODO Replace with TDB2. std::vector tasks; context.tdb.lock (context.config.getBoolean ("locking")); handleRecurrence (); -// context.tdb.load (tasks, context.filter); - Filter filter; - context.tdb.load (tasks, filter); // TODO No filter. + Filter filter; // Blank + context.tdb.load (tasks, filter); // No filter. context.tdb.commit (); context.tdb.unlock (); -/* - // Filter sequence. - if (context.sequence.size ()) - context.filter.applySequence (tasks, context.sequence); -*/ - //////////////////////////////////// - // TODO Create the filter - - //std::vector filter_args; - //context.args.extract_filter (filter_args); - - // TODO Apply the filter - // Filter filter (context.args); - - // std::vector filtered; - // thing.eval (filtered, context.args, tasks); + Arguments f = context.args.extract_read_only_filter (); + Expression e (f); + // TODO e.apply (tasks); //////////////////////////////////// // Sort the tasks.