Code Cleanup

- Eliminated obsolete Arguments.h, Arguments.cpp.
This commit is contained in:
Paul Beckingham 2011-07-26 00:25:57 -04:00
parent ab8a6d9e88
commit 0c08b29e48
24 changed files with 74 additions and 1976 deletions

View file

@ -836,7 +836,7 @@ const A3 A3::expand (const A3& input) const
std::string mod;
std::string value;
std::string sense;
Arguments::extract_attmod (arg->_raw, name, mod, value, sense);
extract_attmod (arg->_raw, name, mod, value, sense);
// name.before:value --> name < value
if (mod == "before" || mod == "under" || mod == "below")
@ -942,7 +942,7 @@ const A3 A3::expand (const A3& input) const
{
char type;
std::string value;
A3::extract_tag (arg->_raw, type, value);
extract_tag (arg->_raw, type, value);
expanded.push_back (Arg ("tags", "dom"));
expanded.push_back (Arg (type == '+' ? "~" : "!~", "op"));
@ -961,7 +961,7 @@ const A3 A3::expand (const A3& input) const
else if (arg->_category == "pattern")
{
std::string value;
A3::extract_pattern (arg->_raw, value);
extract_pattern (arg->_raw, value);
expanded.push_back (Arg ("description", "dom"));
expanded.push_back (Arg ("~", "op"));
@ -990,10 +990,10 @@ const A3 A3::sequence (const A3& input) const
for (arg = input.begin (); arg != input.end (); ++arg)
{
if (arg->_category == "id")
A3::extract_id (arg->_raw, ids);
extract_id (arg->_raw, ids);
else if (arg->_category == "uuid")
A3::extract_uuid (arg->_raw, uuids);
extract_uuid (arg->_raw, uuids);
}
// If there is no sequence, we're done.
@ -1109,13 +1109,13 @@ const A3 A3::postfix (const A3& input) const
else
throw std::string ("Mismatched parentheses in expression");
}
else if (A3::is_operator (arg->_raw, type, precedence, associativity))
else if (is_operator (arg->_raw, type, precedence, associativity))
{
char type2;
int precedence2;
char associativity2;
while (op_stack.size () > 0 &&
A3::is_operator (op_stack.back ()._raw, type2, precedence2, associativity2) &&
is_operator (op_stack.back ()._raw, type2, precedence2, associativity2) &&
((associativity == 'l' && precedence <= precedence2) ||
(associativity == 'r' && precedence < precedence2)))
{

File diff suppressed because it is too large Load diff

View file

@ -1,143 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// 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_ARGUMENTS
#define INCLUDED_ARGUMENTS
#define L10N // Localization complete.
#include <vector>
#include <string>
#include <File.h>
#define ARGUMENTS_SEQUENCE_MAX_RANGE 1000
class Triple
{
public:
Triple (
const std::string& one,
const std::string& two,
const std::string& three)
: _first (one)
, _second (two)
, _third (three)
{
}
Triple (const Triple& other)
{
_first = other._first;
_second = other._second;
_third = other._third;
}
Triple& operator= (const Triple& other)
{
if (this != &other)
{
_first = other._first;
_second = other._second;
_third = other._third;
}
return *this;
}
bool operator== (const Triple& other) const
{
return _first == other._first &&
_second == other._second &&
_third == other._third;
}
public:
std::string _first; // Represents token to be evaluated
std::string _second; // Represents progressive token type
std::string _third; // Represent original category
};
class Arguments : public std::vector <Triple>
{
public:
Arguments ();
~Arguments ();
void capture (int, const char**);
void capture (const std::string&);
void capture_first (const std::string&);
void categorize ();
void append_stdin ();
void rc_override (std::string&, File&);
void get_data_location (std::string&);
void apply_overrides ();
void resolve_aliases ();
void inject_defaults ();
std::vector <std::string> list ();
static std::vector <std::string> operator_list ();
std::string combine ();
bool find_command (std::string&);
std::string find_limit ();
static bool is_multipart (const std::string&, std::vector <std::string>&);
static bool is_command (const std::vector <std::string>&, std::string&);
static bool is_attr (const std::string&);
static bool is_attmod (const std::string&);
static bool is_subst (const std::string&);
static bool is_pattern (const std::string&);
static bool is_id (const std::string&);
static bool is_uuid (const std::string&);
static bool is_tag (const std::string&);
static bool is_operator (const std::string&);
static bool is_operator (const std::string&, char&, int&, char&);
static bool is_symbol_operator (const std::string&);
static bool is_attribute (const std::string&, std::string&);
static bool is_modifier (const std::string&);
static bool is_expression (const std::string&);
static bool extract_attr (const std::string&, std::string&, std::string&);
static bool extract_attmod (const std::string&, std::string&, std::string&, std::string&, std::string&);
static bool extract_subst (const std::string&, std::string&, std::string&, bool&);
static bool extract_pattern (const std::string&, std::string&);
static bool extract_id (const std::string&, std::vector <int>&);
static bool extract_uuid (const std::string&, std::vector <std::string>&);
static bool extract_tag (const std::string&, char&, std::string&);
static bool extract_operator (const std::string&, std::string&);
Arguments extract_read_only_filter ();
Arguments extract_write_filter ();
Arguments extract_modifications (bool include_seq = false);
Arguments extract_simple_words ();
static bool valid_modifier (const std::string&);
void dump (const std::string&);
};
#endif
////////////////////////////////////////////////////////////////////////////////

View file

@ -7,7 +7,6 @@ include_directories (${CMAKE_SOURCE_DIR}
set (task_SRCS A3.cpp A3.h
API.cpp API.h
Arguments.cpp Arguments.h
Att.cpp Att.h
Color.cpp Color.h
Config.cpp Config.h

View file

@ -72,21 +72,18 @@ int Context::initialize (int argc, const char** argv)
try
{
// char** argv --> std::vector <std::string> Context::args.
args.capture (argc, argv);
// char** argv --> std::vector <std::string> Context::a3.
a3.capture (argc, argv);
// echo one two -- three | task zero --> task zero one two
// 'three' is left in the input buffer.
args.append_stdin ();
a3.append_stdin ();
// Assume default .taskrc and .task locations.
assumeLocations ();
// Process 'rc:<file>' command line override, and remove the argument from the
// Context::args.
args.rc_override (home_dir, rc_file);
// Context::a3.
a3.categorize ();
a3.rc_override (home_dir, rc_file);
@ -107,7 +104,6 @@ int Context::initialize (int argc, const char** argv)
// Handle Aliases.
loadAliases ();
args.resolve_aliases ();
a3.resolve_aliases ();
// Apply rc overrides to Context::config, capturing raw args for later use.
@ -124,11 +120,9 @@ int Context::initialize (int argc, const char** argv)
Column::factory (columns);
// Categorize all arguments one more time. THIS IS NECESSARY.
args.categorize ();
a3.categorize ();
// Handle default command and assumed 'info' command.
args.inject_defaults ();
a3.inject_defaults ();
a3.dump ("Context::initialize"); // TODO Remove.
@ -526,7 +520,7 @@ void Context::clear ()
{
tdb.clear (); // TODO Obsolete
// tdb2.clear ();
args.clear ();
a3.clear ();
clearMessages ();
}
@ -539,7 +533,7 @@ void Context::updateXtermTitle ()
if (config.getBoolean ("xterm.title"))
{
std::string command;
args.find_command (command);
a3.find_command (command);
std::string title;
join (title, " ", a3.list ());

View file

@ -39,7 +39,6 @@
#include <Path.h>
#include <File.h>
#include <Directory.h>
#include <Arguments.h>
#include <A3.h>
class Context
@ -82,7 +81,6 @@ private:
public:
std::string program;
Arguments args;
A3 a3;
std::string home_dir;
File rc_file;

View file

@ -115,11 +115,11 @@ const std::string DOM::get (const std::string& name)
name.substr (0, 8) == "context.")
{
if (name == "context.program")
return /*_cache[name] =*/ context.args[0]._first;
return /*_cache[name] =*/ context.a3[0]._raw;
else if (name == "context.args")
{
return /*_cache[name] =*/ context.args.combine ();
return /*_cache[name] =*/ context.a3.combine ();
}
else if (name == "context.width")
{
@ -238,7 +238,7 @@ const std::string DOM::get (const std::string& name, const Task& task)
return /*_cache[name] =*/ copy_name;
// <attr>
else if (Arguments::is_attribute (name, canonical))
else if (A3::is_attribute (name, canonical))
return task.get (canonical);
// <id>.<name>

View file

@ -56,8 +56,7 @@ int CmdAdd::execute (std::string& output)
task.set ("uuid", uuid ());
// Apply the command line modifications to the new task.
Arguments modifications = context.args.extract_modifications (true);
modify_task_description_replace (task, modifications);
modify_task_description_replace (task, context.a3.extract_modifications ());
apply_defaults (task);
// Only valid tasks can be added.

View file

@ -69,7 +69,7 @@ int CmdAnnotate::execute (std::string& output)
}
// Apply the command line modifications to the completed task.
Arguments modifications = context.args.extract_modifications ();
A3 modifications = context.a3.extract_modifications ();
if (!modifications.size ())
throw std::string (STRING_CMD_XPEND_NEED_TEXT);

View file

@ -69,7 +69,7 @@ int CmdAppend::execute (std::string& output)
}
// Apply the command line modifications to the started task.
Arguments modifications = context.args.extract_modifications ();
A3 modifications = context.a3.extract_modifications ();
if (!modifications.size ())
throw std::string (STRING_CMD_XPEND_NEED_TEXT);

View file

@ -998,10 +998,10 @@ int CmdBurndownMonthly::execute (std::string& output)
Chart chart ('M');
// Use any filter as a title.
if (context.args.size () > 2)
if (context.a3.size () > 2)
{
std::string combined = "("
+ context.args.extract_read_only_filter ().combine ()
+ context.a3.extract_filter ().combine ()
+ ")";
chart.description (combined);
}
@ -1042,10 +1042,10 @@ int CmdBurndownWeekly::execute (std::string& output)
Chart chart ('W');
// Use any filter as a title.
if (context.args.size () > 2)
if (context.a3.size () > 2)
{
std::string combined = "("
+ context.args.extract_read_only_filter ().combine ()
+ context.a3.extract_filter ().combine ()
+ ")";
chart.description (combined);
}
@ -1086,10 +1086,10 @@ int CmdBurndownDaily::execute (std::string& output)
Chart chart ('D');
// Use any filter as a title.
if (context.args.size () > 2)
if (context.a3.size () > 2)
{
std::string combined = "("
+ context.args.extract_read_only_filter ().combine ()
+ context.a3.extract_filter ().combine ()
+ ")";
chart.description (combined);
}

View file

@ -86,10 +86,7 @@ int CmdCustom::execute (std::string& output)
split (filterArgs, reportFilter, ' ');
std::vector <std::string>::iterator arg;
for (arg = filterArgs.begin (); arg != filterArgs.end (); ++ arg)
{
context.args.capture_first (*arg);
context.a3.capture_first (*arg);
}
context.a3.categorize ();
context.a3.dump ("CmdCustom::execute");
@ -290,7 +287,7 @@ void CmdCustom::getLimits (const std::string& report, int& rows, int& lines)
// If the custom report has a defined limit, then allow a numeric override.
// This is an integer specified as a filter (limit:10).
std::string limit = context.args.find_limit ();
std::string limit = context.a3.find_limit ();
if (limit != "")
{
if (limit == "page")

View file

@ -70,7 +70,7 @@ int CmdDelete::execute (std::string& output)
}
// Apply the command line modifications to the new task.
Arguments modifications = context.args.extract_modifications ();
A3 modifications = context.a3.extract_modifications ();
std::vector <Task>::iterator task;
for (task = filtered.begin (); task != filtered.end (); ++task)

View file

@ -69,7 +69,7 @@ int CmdDone::execute (std::string& output)
}
// Apply the command line modifications to the completed task.
Arguments modifications = context.args.extract_modifications ();
A3 modifications = context.a3.extract_modifications ();
Permission permission;
if (filtered.size () > (size_t) context.config.getInteger ("bulk"))

View file

@ -69,7 +69,7 @@ int CmdDuplicate::execute (std::string& output)
}
// Apply the command line modifications to the completed task.
Arguments modifications = context.args.extract_modifications ();
A3 modifications = context.a3.extract_modifications ();
std::vector <Task>::iterator task;
for (task = filtered.begin (); task != filtered.end (); ++task)

View file

@ -48,12 +48,12 @@ CmdExec::CmdExec ()
int CmdExec::execute (std::string& output)
{
std::string command_line;
std::vector <Triple>::iterator arg;
for (arg = context.args.begin (); arg != context.args.end (); ++arg)
std::vector <Arg>::iterator arg;
for (arg = context.a3.begin (); arg != context.a3.end (); ++arg)
{
if (arg != context.args.begin () &&
arg->_first != "execute")
command_line += arg->_first;
if (arg != context.a3.begin () &&
arg->_raw != "execute")
command_line += arg->_raw;
}
return system (command_line.c_str ());

View file

@ -56,7 +56,7 @@ int CmdLog::execute (std::string& output)
task.set ("uuid", uuid ());
// Apply the command line modifications to the new task.
Arguments modifications = context.args.extract_modifications ();
A3 modifications = context.a3.extract_modifications ();
modify_task_description_replace (task, modifications);
apply_defaults (task);

View file

@ -69,7 +69,7 @@ int CmdModify::execute (std::string& output)
}
// Apply the command line modifications to the new task.
Arguments modifications = context.args.extract_modifications ();
A3 modifications = context.a3.extract_modifications ();
Permission permission;
if (filtered.size () > (size_t) context.config.getInteger ("bulk"))

View file

@ -69,7 +69,7 @@ int CmdPrepend::execute (std::string& output)
}
// Apply the command line modifications to the started task.
Arguments modifications = context.args.extract_modifications ();
A3 modifications = context.a3.extract_modifications ();
if (!modifications.size ())
throw std::string (STRING_CMD_XPEND_NEED_TEXT);

View file

@ -57,7 +57,7 @@ int CmdShow::execute (std::string& output)
// Obtain the arguments from the description. That way, things like '--'
// have already been handled.
if (context.args.size () > 2)
if (context.a3.size () > 2)
throw std::string (STRING_CMD_SHOW_ARGS);
int width = context.getWidth ();

View file

@ -69,7 +69,7 @@ int CmdStart::execute (std::string& output)
}
// Apply the command line modifications to the started task.
Arguments modifications = context.args.extract_modifications ();
A3 modifications = context.a3.extract_modifications ();
Permission permission;
if (filtered.size () > (size_t) context.config.getInteger ("bulk"))

View file

@ -69,7 +69,7 @@ int CmdStop::execute (std::string& output)
}
// Apply the command line modifications to the stopped task.
Arguments modifications = context.args.extract_modifications ();
A3 modifications = context.a3.extract_modifications ();
Permission permission;
if (filtered.size () > (size_t) context.config.getInteger ("bulk"))

View file

@ -271,13 +271,7 @@ void Command::filter (std::vector <Task>& input, std::vector <Task>& output)
A3 filt = context.a3.extract_filter ();
filt.dump ("extract_filter");
Arguments f;
if (read_only ())
f = context.args.extract_read_only_filter ();
else
f = context.args.extract_write_filter ();
if (f.size ())
if (filt.size ())
{
E9 e (filt);
@ -299,13 +293,7 @@ void Command::filter (std::vector <Task>& output)
A3 filt = context.a3.extract_filter ();
filt.dump ("extract_filter");
Arguments f;
if (read_only ())
f = context.args.extract_read_only_filter ();
else
f = context.args.extract_write_filter ();
if (f.size ())
if (filt.size ())
{
const std::vector <Task>& pending = context.tdb2.pending.get_tasks ();
E9 e (filt);
@ -316,7 +304,7 @@ void Command::filter (std::vector <Task>& output)
if (e.evalFilter (*task))
output.push_back (*task);
if (! filter_shortcut (f))
if (! filter_shortcut (filt))
{
const std::vector <Task>& completed = context.tdb2.completed.get_tasks (); // TODO Optional
for (task = completed.begin (); task != completed.end (); ++task)
@ -343,23 +331,23 @@ void Command::filter (std::vector <Task>& output)
////////////////////////////////////////////////////////////////////////////////
// If the filter contains the restriction "status:pending", as the first filter
// term, then completed.data does not need to be loaded.
bool Command::filter_shortcut (const Arguments& filter)
bool Command::filter_shortcut (const A3& filter)
{
/**/
if (filter.size () >= 3)
{
std::cout << "# filter[0] " << filter[0]._first << "\n"
<< "# filter[1] " << filter[1]._first << "\n"
<< "# filter[2] " << filter[2]._first << "\n";
std::cout << "# filter[0] " << filter[0]._raw << "\n"
<< "# filter[1] " << filter[1]._raw << "\n"
<< "# filter[2] " << filter[2]._raw << "\n";
}
/**/
// Postfix: <status> <"pending"> <=>
// 0 1 2
if (filter.size () >= 3 &&
filter[0]._first == "status" &&
filter[1]._first.find ("pending") != std::string::npos &&
filter[2]._first == "=")
if (filter.size () >= 3 &&
filter[0]._raw == "status" &&
filter[1]._raw.find ("pending") != std::string::npos &&
filter[2]._raw == "=")
return true;
return false;
@ -367,7 +355,7 @@ bool Command::filter_shortcut (const Arguments& filter)
////////////////////////////////////////////////////////////////////////////////
// Apply the modifications in arguments to the task.
void Command::modify_task_description_replace (Task& task, Arguments& arguments)
void Command::modify_task_description_replace (Task& task, const A3& arguments)
{
std::string description;
modify_task (task, arguments, description);
@ -377,7 +365,7 @@ void Command::modify_task_description_replace (Task& task, Arguments& arguments)
}
////////////////////////////////////////////////////////////////////////////////
void Command::modify_task_description_prepend (Task& task, Arguments& arguments)
void Command::modify_task_description_prepend (Task& task, const A3& arguments)
{
std::string description;
modify_task (task, arguments, description);
@ -387,7 +375,7 @@ void Command::modify_task_description_prepend (Task& task, Arguments& arguments)
}
////////////////////////////////////////////////////////////////////////////////
void Command::modify_task_description_append (Task& task, Arguments& arguments)
void Command::modify_task_description_append (Task& task, const A3& arguments)
{
std::string description;
modify_task (task, arguments, description);
@ -397,7 +385,7 @@ void Command::modify_task_description_append (Task& task, Arguments& arguments)
}
////////////////////////////////////////////////////////////////////////////////
void Command::modify_task_annotate (Task& task, Arguments& arguments)
void Command::modify_task_annotate (Task& task, const A3& arguments)
{
std::string description;
modify_task (task, arguments, description);
@ -410,20 +398,20 @@ void Command::modify_task_annotate (Task& task, Arguments& arguments)
// Worker function that does all the updates, but never overwrites description.
void Command::modify_task (
Task& task,
Arguments& arguments,
const A3& arguments,
std::string& description)
{
std::vector <Triple>::iterator arg;
std::vector <Arg>::const_iterator arg;
for (arg = arguments.begin (); arg != arguments.end (); ++arg)
{
// Attributes are essentially name:value pairs, and correspond directly
// to stored attributes.
if (arg->_third == "attr")
if (arg->_category == "attr")
{
std::string name;
std::string value;
Arguments::extract_attr (arg->_first, name, value);
if (Arguments::is_attribute (name, name)) // Canonicalize
A3::extract_attr (arg->_raw, name, value);
if (A3::is_attribute (name, name)) // Canonicalize
{
// All values must be eval'd first.
A3 fragment;
@ -462,11 +450,11 @@ void Command::modify_task (
// Tags need special handling because they are essentially a vector stored
// in a single string, therefore Task::{add,remove}Tag must be called as
// appropriate.
else if (arg->_third == "tag")
else if (arg->_category == "tag")
{
char type;
std::string value;
Arguments::extract_tag (arg->_first, type, value);
A3::extract_tag (arg->_raw, type, value);
if (type == '+')
task.addTag (value);
@ -475,29 +463,29 @@ void Command::modify_task (
}
// Words and operators are aggregated into a description.
else if (arg->_third == "word" ||
arg->_third == "op")
else if (arg->_category == "word" ||
arg->_category == "op")
{
if (description.length ())
description += " ";
description += arg->_first;
description += arg->_raw;
}
// Substitutions.
else if (arg->_third == "subst")
else if (arg->_category == "subst")
{
std::string from;
std::string to;
bool global;
Arguments::extract_subst (arg->_first, from, to, global);
A3::extract_subst (arg->_raw, from, to, global);
task.substitute (from, to, global);
}
// Any additional argument types are indicative of a failure in
// Arguments::extract_modifications.
// A3::extract_modifications.
else
throw format (STRING_CMD_MOD_UNEXPECTED, arg->_first);
throw format (STRING_CMD_MOD_UNEXPECTED, arg->_raw);
}
}

View file

@ -32,7 +32,7 @@
#include <vector>
#include <string>
#include <Task.h>
#include <Arguments.h>
#include <A3.h>
class Command
{
@ -55,13 +55,13 @@ public:
protected:
void filter (std::vector <Task>&, std::vector <Task>&);
void filter (std::vector <Task>&);
bool filter_shortcut (const Arguments&);
bool filter_shortcut (const A3&);
void modify_task_description_replace (Task&, Arguments&);
void modify_task_description_prepend (Task&, Arguments&);
void modify_task_description_append (Task&, Arguments&);
void modify_task_annotate (Task&, Arguments&);
void modify_task (Task&, Arguments&, std::string&);
void modify_task_description_replace (Task&, const A3&);
void modify_task_description_prepend (Task&, const A3&);
void modify_task_description_append (Task&, const A3&);
void modify_task_annotate (Task&, const A3&);
void modify_task (Task&, const A3&, std::string&);
void apply_defaults (Task&);
protected: