- Removed unused variable only detectable on Ubuntu 8.
- Removed misplaced files.
This commit is contained in:
304
Date.cpp
304
Date.cpp
@@ -1,304 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2005 - 2008, Paul Beckingham. All rights reserved.
|
||||
//
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include <iostream>
|
||||
#include <time.h>
|
||||
#include <assert.h>
|
||||
#include "task.h"
|
||||
#include "Date.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Defaults to "now".
|
||||
Date::Date ()
|
||||
{
|
||||
mT = time (NULL);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Date::Date (const time_t t)
|
||||
{
|
||||
mT = t;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Date::Date (const int m, const int d, const int y)
|
||||
{
|
||||
// Error if not valid.
|
||||
struct tm t = {0};
|
||||
t.tm_mday = d;
|
||||
t.tm_mon = m - 1;
|
||||
t.tm_year = y - 1900;
|
||||
|
||||
mT = mktime (&t);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Date::Date (const std::string& mdy)
|
||||
{
|
||||
size_t firstSlash = mdy.find ("/");
|
||||
size_t secondSlash = mdy.find ("/", firstSlash + 1);
|
||||
if (firstSlash != std::string::npos &&
|
||||
secondSlash != std::string::npos)
|
||||
{
|
||||
int m = ::atoi (mdy.substr (0, firstSlash ).c_str ());
|
||||
int d = ::atoi (mdy.substr (firstSlash + 1, secondSlash - firstSlash).c_str ());
|
||||
int y = ::atoi (mdy.substr (secondSlash + 1, std::string::npos ).c_str ());
|
||||
if (!valid (m, d, y))
|
||||
throw std::string ("\"") + mdy + "\" is not a valid date.";
|
||||
|
||||
// Duplicate Date::Date (const int, const int, const int);
|
||||
struct tm t = {0};
|
||||
t.tm_mday = d;
|
||||
t.tm_mon = m - 1;
|
||||
t.tm_year = y - 1900;
|
||||
|
||||
mT = mktime (&t);
|
||||
}
|
||||
else
|
||||
throw std::string ("\"") + mdy + "\" is not a valid date.";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Date::Date (const Date& rhs)
|
||||
{
|
||||
mT = rhs.mT;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Date::~Date ()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
time_t Date::toEpoch ()
|
||||
{
|
||||
return mT;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Date::toEpoch (time_t& epoch)
|
||||
{
|
||||
epoch = mT;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Date::toMDY (int& m, int& d, int& y)
|
||||
{
|
||||
struct tm* t = localtime (&mT);
|
||||
|
||||
m = t->tm_mon + 1;
|
||||
d = t->tm_mday;
|
||||
y = t->tm_year + 1900;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Date::toString (std::string& output)
|
||||
{
|
||||
output = toString ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string Date::toString (void)
|
||||
{
|
||||
int m, d, y;
|
||||
toMDY (m, d, y);
|
||||
|
||||
char formatted [11];
|
||||
sprintf (formatted, "%d/%d/%d", m, d, y);
|
||||
return std::string (formatted);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Date::valid (const int m, const int d, const int y)
|
||||
{
|
||||
// Check that the year is valid.
|
||||
if (y < 0)
|
||||
return false;
|
||||
|
||||
// Check that the month is valid.
|
||||
if (m < 1 || m > 12)
|
||||
return false;
|
||||
|
||||
// Finally check that the days fall within the acceptable range for this
|
||||
// month, and whether or not this is a leap year.
|
||||
if (d < 1 || d > Date::daysInMonth (m, y))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Date::leapYear (int year)
|
||||
{
|
||||
bool ly = false;
|
||||
|
||||
if (!(year % 4)) ly = true;
|
||||
else if (!(year % 400)) ly = true;
|
||||
else if (!(year % 100)) ly = false;
|
||||
|
||||
return ly;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int Date::daysInMonth (int month, int year)
|
||||
{
|
||||
static int days[2][12] =
|
||||
{
|
||||
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
|
||||
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
|
||||
};
|
||||
|
||||
return days[Date::leapYear (year) ? 1 : 0][month - 1];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string Date::monthName (int month)
|
||||
{
|
||||
static const char* months[12] =
|
||||
{
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",
|
||||
"July",
|
||||
"August",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December",
|
||||
};
|
||||
|
||||
assert (month > 0);
|
||||
assert (month <= 12);
|
||||
return months[month -1];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Date::dayName (int dow, std::string& name)
|
||||
{
|
||||
static const char* days[7] =
|
||||
{
|
||||
"Sunday",
|
||||
"Monday",
|
||||
"Tuesday",
|
||||
"Wednesday",
|
||||
"Thursday",
|
||||
"Friday",
|
||||
"Saturday",
|
||||
};
|
||||
|
||||
name = days[dow];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string Date::dayName (int dow)
|
||||
{
|
||||
static const char* days[7] =
|
||||
{
|
||||
"Sunday",
|
||||
"Monday",
|
||||
"Tuesday",
|
||||
"Wednesday",
|
||||
"Thursday",
|
||||
"Friday",
|
||||
"Saturday",
|
||||
};
|
||||
|
||||
return days[dow];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int Date::dayOfWeek ()
|
||||
{
|
||||
struct tm* t = localtime (&mT);
|
||||
return t->tm_wday;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int Date::month ()
|
||||
{
|
||||
struct tm* t = localtime (&mT);
|
||||
return t->tm_mon + 1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int Date::day ()
|
||||
{
|
||||
struct tm* t = localtime (&mT);
|
||||
return t->tm_mday;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int Date::year ()
|
||||
{
|
||||
struct tm* t = localtime (&mT);
|
||||
return t->tm_year + 1900;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Date::operator== (const Date& rhs)
|
||||
{
|
||||
return rhs.mT == mT;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Date::operator!= (const Date& rhs)
|
||||
{
|
||||
return rhs.mT != mT;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Date::operator< (const Date& rhs)
|
||||
{
|
||||
return mT < rhs.mT;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Date::operator> (const Date& rhs)
|
||||
{
|
||||
return mT > rhs.mT;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Date::operator<= (const Date& rhs)
|
||||
{
|
||||
return mT <= rhs.mT;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Date::operator>= (const Date& rhs)
|
||||
{
|
||||
return mT >= rhs.mT;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Date Date::operator+ (const int delta)
|
||||
{
|
||||
return Date::Date (mT + delta);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Date& Date::operator+= (const int delta)
|
||||
{
|
||||
mT += (time_t) delta;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Date& Date::operator-= (const int delta)
|
||||
{
|
||||
mT -= (time_t) delta;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
time_t Date::operator- (const Date& rhs)
|
||||
{
|
||||
return mT - rhs.mT;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
379
parse.cpp
379
parse.cpp
@@ -1,379 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2006 - 2008, Paul Beckingham. All rights reserved.
|
||||
//
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "Date.h"
|
||||
#include "task.h"
|
||||
#include "T.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
static const char* colors[] =
|
||||
{
|
||||
"bold",
|
||||
"underline",
|
||||
"bold_underline",
|
||||
|
||||
"black",
|
||||
"red",
|
||||
"green",
|
||||
"yellow",
|
||||
"blue",
|
||||
"magenta",
|
||||
"cyan",
|
||||
"white",
|
||||
|
||||
"bold_black",
|
||||
"bold_red",
|
||||
"bold_green",
|
||||
"bold_yellow",
|
||||
"bold_blue",
|
||||
"bold_magenta",
|
||||
"bold_cyan",
|
||||
"bold_white",
|
||||
|
||||
"underline_black",
|
||||
"underline_red",
|
||||
"underline_green",
|
||||
"underline_yellow",
|
||||
"underline_blue",
|
||||
"underline_magenta",
|
||||
"underline_cyan",
|
||||
"underline_white",
|
||||
|
||||
"bold_underline_black",
|
||||
"bold_underline_red",
|
||||
"bold_underline_green",
|
||||
"bold_underline_yellow",
|
||||
"bold_underline_blue",
|
||||
"bold_underline_magenta",
|
||||
"bold_underline_cyan",
|
||||
"bold_underline_white",
|
||||
|
||||
"on_black",
|
||||
"on_red",
|
||||
"on_green",
|
||||
"on_yellow",
|
||||
"on_blue",
|
||||
"on_magenta",
|
||||
"on_cyan",
|
||||
"on_white",
|
||||
|
||||
"on_bright_black",
|
||||
"on_bright_red",
|
||||
"on_bright_green",
|
||||
"on_bright_yellow",
|
||||
"on_bright_blue",
|
||||
"on_bright_magenta",
|
||||
"on_bright_cyan",
|
||||
"on_bright_white",
|
||||
"",
|
||||
};
|
||||
|
||||
static const char* attributes[] =
|
||||
{
|
||||
"project",
|
||||
"priority",
|
||||
"fg",
|
||||
"bg",
|
||||
"due",
|
||||
"entry",
|
||||
"start",
|
||||
"end",
|
||||
"",
|
||||
};
|
||||
|
||||
static const char* commands[] =
|
||||
{
|
||||
"active",
|
||||
"add",
|
||||
"calendar",
|
||||
"colors",
|
||||
"completed",
|
||||
"delete",
|
||||
"done",
|
||||
"export",
|
||||
"history",
|
||||
"info",
|
||||
"list",
|
||||
"long",
|
||||
"ls",
|
||||
"next",
|
||||
"overdue",
|
||||
"projects",
|
||||
"start",
|
||||
"stats",
|
||||
"summary",
|
||||
"tags",
|
||||
"usage",
|
||||
"version",
|
||||
"",
|
||||
};
|
||||
|
||||
void guess (const std::string& type, const char** list, std::string& candidate)
|
||||
{
|
||||
std::vector <std::string> options;
|
||||
for (int i = 0; list[i][0]; ++i)
|
||||
options.push_back (list[i]);
|
||||
|
||||
std::vector <std::string> matches;
|
||||
autoComplete (candidate, options, matches);
|
||||
if (1 == matches.size ())
|
||||
candidate = matches[0];
|
||||
|
||||
else if (0 == matches.size ())
|
||||
throw std::string ("Unrecognized ") + type + " '" + candidate + "'";
|
||||
|
||||
else
|
||||
{
|
||||
std::string error = "Ambiguous ";
|
||||
error += type;
|
||||
error += " '";
|
||||
error += candidate;
|
||||
error += "' - could be either of ";
|
||||
for (size_t i = 0; i < matches.size (); ++i)
|
||||
{
|
||||
if (i)
|
||||
error += ", ";
|
||||
error += matches[i];
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
static bool isCommand (const std::string& candidate)
|
||||
{
|
||||
std::vector <std::string> options;
|
||||
for (int i = 0; commands[i][0]; ++i)
|
||||
options.push_back (commands[i]);
|
||||
|
||||
std::vector <std::string> matches;
|
||||
autoComplete (candidate, options, matches);
|
||||
if (0 == matches.size ())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool validDate (std::string& date)
|
||||
{
|
||||
size_t firstSlash = date.find ("/");
|
||||
size_t secondSlash = date.find ("/", firstSlash + 1);
|
||||
if (firstSlash != std::string::npos &&
|
||||
secondSlash != std::string::npos)
|
||||
{
|
||||
int m = ::atoi (date.substr (0, firstSlash ).c_str ());
|
||||
int d = ::atoi (date.substr (firstSlash + 1, secondSlash - firstSlash).c_str ());
|
||||
int y = ::atoi (date.substr (secondSlash + 1, std::string::npos ).c_str ());
|
||||
if (!Date::valid (m, d, y))
|
||||
throw std::string ("\"") + date + "\" is not a valid date.";
|
||||
|
||||
// Convert to epoch form.
|
||||
Date dt (m, d, y);
|
||||
time_t t;
|
||||
dt.toEpoch (t);
|
||||
char converted[12];
|
||||
sprintf (converted, "%u", (unsigned int) t);
|
||||
date = converted;
|
||||
}
|
||||
else
|
||||
throw std::string ("Badly formed date - use the MM/DD/YYYY format");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
static bool validPriority (std::string& input)
|
||||
{
|
||||
if (input != "H" &&
|
||||
input != "M" &&
|
||||
input != "L" &&
|
||||
input != "")
|
||||
throw std::string ("\"") +
|
||||
input +
|
||||
"\" is not a valid priority. Use H, M, L or leave blank.";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
static bool validAttribute (std::string& name, std::string& value)
|
||||
{
|
||||
guess ("attribute", attributes, name);
|
||||
|
||||
if ((name == "fg" || name == "bg") && value != "")
|
||||
guess ("color", colors, value);
|
||||
|
||||
else if (name == "due" && value != "")
|
||||
validDate (value);
|
||||
|
||||
else if (name == "priority")
|
||||
{
|
||||
for (std::string::iterator i = value.begin (); i != value.end (); ++i)
|
||||
*i = ::toupper (*i);
|
||||
|
||||
return validPriority (value);
|
||||
}
|
||||
|
||||
else if (name == "entry" ||
|
||||
name == "start" ||
|
||||
name == "end")
|
||||
throw std::string ("\"") +
|
||||
name +
|
||||
"\" is not an attribute you may modify directly.";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
static bool validId (const std::string& input)
|
||||
{
|
||||
for (size_t i = 0; i < input.length (); ++i)
|
||||
if (!::isdigit (input[i]))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
static bool validTag (std::string& input)
|
||||
{
|
||||
if ((input[0] == '-' || input[0] == '+') &&
|
||||
input.length () > 1)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
static bool validDescription (const std::string& input)
|
||||
{
|
||||
if (input.length () > 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
static bool validCommand (std::string& input)
|
||||
{
|
||||
guess ("command", commands, input);
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
static bool validSubstitution (
|
||||
std::string& input,
|
||||
std::string& from,
|
||||
std::string& to)
|
||||
{
|
||||
size_t first = input.find ('/');
|
||||
if (first != std::string::npos)
|
||||
{
|
||||
size_t second = input.find ('/', first + 1);
|
||||
if (second != std::string::npos)
|
||||
{
|
||||
size_t third = input.find ('/', second + 1);
|
||||
if (third != std::string::npos)
|
||||
{
|
||||
if (first == 0 &&
|
||||
first < second &&
|
||||
second < third &&
|
||||
third == input.length () - 1)
|
||||
{
|
||||
from = input.substr (first + 1, second - first - 1);
|
||||
to = input.substr (second + 1, third - second - 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Token Distinguishing characteristic
|
||||
// ------- -----------------------------
|
||||
// command first positional
|
||||
// id \d+
|
||||
// description default, accumulate
|
||||
// substitution /\w+/\w*/
|
||||
// tags [-+]\w+
|
||||
// attributes \w+:.+
|
||||
//
|
||||
void parse (
|
||||
std::vector <std::string>& args,
|
||||
std::string& command,
|
||||
T& task)
|
||||
{
|
||||
command = "";
|
||||
|
||||
std::string descCandidate = "";
|
||||
for (size_t i = 0; i < args.size (); ++i)
|
||||
{
|
||||
std::string arg (args[i]);
|
||||
size_t colon; // Pointer to colon in argument.
|
||||
std::string from;
|
||||
std::string to;
|
||||
|
||||
// An id is the first argument found that contains all digits.
|
||||
if (command != "add" && // "add" doesn't require an ID
|
||||
task.getId () == 0 &&
|
||||
validId (arg))
|
||||
task.setId (::atoi (arg.c_str ()));
|
||||
|
||||
// Tags begin with + or - and contain arbitrary text.
|
||||
else if (validTag (arg))
|
||||
{
|
||||
if (arg[0] == '+')
|
||||
task.addTag (arg.substr (1, std::string::npos));
|
||||
else if (arg[0] == '-')
|
||||
task.addRemoveTag (arg.substr (1, std::string::npos));
|
||||
}
|
||||
|
||||
// Attributes contain a constant string followed by a colon, followed by a
|
||||
// value.
|
||||
else if ((colon = arg.find (":")) != std::string::npos)
|
||||
{
|
||||
std::string name = arg.substr (0, colon);
|
||||
std::string value = arg.substr (colon + 1, std::string::npos);
|
||||
|
||||
if (validAttribute (name, value))
|
||||
task.setAttribute (name, value);
|
||||
}
|
||||
|
||||
// Substitution of description text.
|
||||
else if (validSubstitution (arg, from, to))
|
||||
{
|
||||
task.setSubstitution (from, to);
|
||||
}
|
||||
|
||||
// Command.
|
||||
else if (command == "")
|
||||
{
|
||||
if (!isCommand (arg))
|
||||
descCandidate += std::string (arg) + " ";
|
||||
else if (validCommand (arg))
|
||||
command = arg;
|
||||
}
|
||||
|
||||
// Anything else is just considered description.
|
||||
else
|
||||
descCandidate += std::string (arg) + " ";
|
||||
}
|
||||
|
||||
if (validDescription (descCandidate))
|
||||
task.setDescription (descCandidate);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
11
src/task.cpp
11
src/task.cpp
@@ -2144,17 +2144,6 @@ void handleReportOverdue (const TDB& tdb, T& task, Config& conf)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void handleReportStats (const TDB& tdb, T& task, Config& conf)
|
||||
{
|
||||
// Determine window size, and set table accordingly.
|
||||
int width = 80;
|
||||
#ifdef HAVE_LIBNCURSES
|
||||
if (conf.get ("curses", true))
|
||||
{
|
||||
WINDOW* w = initscr ();
|
||||
width = w->_maxx + 1;
|
||||
endwin ();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Get all the tasks.
|
||||
std::vector <T> tasks;
|
||||
tdb.allT (tasks);
|
||||
|
||||
Reference in New Issue
Block a user