diff --git a/DEVELOPERS b/DEVELOPERS index 6351d0819..e1bda67fe 100644 --- a/DEVELOPERS +++ b/DEVELOPERS @@ -1,22 +1,23 @@ Developers may wish to change task, and here is a high-level guide to the files included. - task.{cpp,h} Implements main, high level processing. - command.cpp Implements all non-report task commands. - report.cpp Implements all task reports. - parse.cpp Parses the command line. - TDB.{cpp,h} The task database, performs all file I/O. - T.{cpp,h} Represents a single task - parses a record from TDB, and also - composes record for TDB. Provides accessors for tasks. - Grid.{cpp,h} Implements a sparse 2D array, provides data storage for the - Table object. - Table.{cpp,h} Implements tabular data rendering, wrapping etc. - Config.{cpp,h} Implements a reader for the .taskrc file. - Date.{cpp,h} General date class for the time_t type. - text.cpp Text manipulation functions. - util.cpp General utility functions. - color.cpp Color support functions. - rules.cpp Auto-colorization rules. + task.{cpp,h} Implements main, high level processing. + command.cpp Implements all non-report task commands. + report.cpp Implements all task reports. + parse.cpp Parses the command line. + TDB.{cpp,h} The task database, performs all file I/O. + T.{cpp,h} Represents a single task - parses a record from TDB, and also + composes record for TDB. Provides accessors for tasks. + Grid.{cpp,h} Implements a sparse 2D array, provides data storage for the + Table object. + Table.{cpp,h} Implements tabular data rendering, wrapping etc. + Config.{cpp,h} Implements a reader for the .taskrc file. + Date.{cpp,h} General date class for the time_t type. + Duration.{cpp,h} General duration class for time deltas. + text.cpp Text manipulation functions. + util.cpp General utility functions. + color.cpp Color support functions. + rules.cpp Auto-colorization rules. Please send bugs, patches to task@beckingham.net diff --git a/src/.gitignore b/src/.gitignore index 5761abcfd..1e4ffeb31 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1 +1,2 @@ *.o +Makefile.in diff --git a/src/Att.cpp b/src/Att.cpp new file mode 100644 index 000000000..27146b10b --- /dev/null +++ b/src/Att.cpp @@ -0,0 +1,238 @@ +//////////////////////////////////////////////////////////////////////////////// +// task - a command line task list manager. +// +// Copyright 2006 - 2009, Paul Beckingham. +// 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 "Att.h" + +//////////////////////////////////////////////////////////////////////////////// +Att::Att () +: mName ("") +, mValue ("") +{ + mMods.clear (); +} + +//////////////////////////////////////////////////////////////////////////////// +Att::Att (const std::string& name, const std::string& value) +{ + throw std::string ("unimplemented Att::Att"); + mName = name; + mValue = value; + + mMods.clear (); +} + +//////////////////////////////////////////////////////////////////////////////// +Att::Att (const Att& other) +{ + throw std::string ("unimplemented Att::Att"); + mName = other.mName; + mValue = other.mValue; + mMods = other.mMods; +} + +//////////////////////////////////////////////////////////////////////////////// +Att& Att::operator= (const Att& other) +{ + throw std::string ("unimplemented Att::operator="); + if (this != &other) + { + mName = other.mName; + mValue = other.mValue; + mMods = other.mMods; + } + + return *this; +} + +//////////////////////////////////////////////////////////////////////////////// +Att::~Att () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +// Parse the following forms: +// name [[.mod] ...] : [value] +void Att::parse (const std::string& input) +{ + throw std::string ("unimplemented Att::parse"); +} + +//////////////////////////////////////////////////////////////////////////////// +// name : " value " +std::string Att::composeF4 () const +{ + std::string value = mValue; + encode (value); + enquote (value); + + return mName + ":" + value; +} + +//////////////////////////////////////////////////////////////////////////////// +void Att::addMod (const std::string&) +{ + throw std::string ("unimplemented Att::addMod"); +} + +//////////////////////////////////////////////////////////////////////////////// +std::string Att::name () const +{ + return mName; +} + +//////////////////////////////////////////////////////////////////////////////// +void Att::name (const std::string& name) +{ + mName = name; +} + +//////////////////////////////////////////////////////////////////////////////// +std::string Att::value () const +{ + return mValue; +} + +//////////////////////////////////////////////////////////////////////////////// +void Att::value (const std::string& value) +{ + mValue = value; +} + +//////////////////////////////////////////////////////////////////////////////// +int Att::value_int () const +{ + throw std::string ("unimplemented Att::value_int"); + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// +void Att::value_int (int) +{ + throw std::string ("unimplemented Att::value_int"); +} + +//////////////////////////////////////////////////////////////////////////////// +bool Att::filter () const +{ + throw std::string ("unimplemented filter"); + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +bool Att::required () const +{ + throw std::string ("unimplemented Att::required"); + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +bool Att::reserved () const +{ + throw std::string ("unimplemented Att::reserved"); + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +// Add quotes. +void Att::enquote (std::string& value) const +{ + value = '"' + value + '"'; +} + +//////////////////////////////////////////////////////////////////////////////// +// Remove quotes. +void Att::dequote (std::string& value) const +{ + if (value.length () > 2 && + value[0] == '"' && + value[value.length () - 1] == '"') + value = value.substr (1, value.length () - 2); +} + +//////////////////////////////////////////////////////////////////////////////// +// Encode values prior to serialization. +// \t -> &tab; +// " -> " +// , -> , +// [ -> &open; +// ] -> &close; +// : -> : +void Att::encode (std::string& value) const +{ + std::string::size_type i; + + while ((i = value.find ('\t')) != std::string::npos) + value.replace (i, 1, "&tab;"); + + while ((i = value.find ('"')) != std::string::npos) + value.replace (i, 1, """); + + while ((i = value.find (',')) != std::string::npos) + value.replace (i, 1, ","); + + while ((i = value.find ('[')) != std::string::npos) + value.replace (i, 1, "&open;"); + + while ((i = value.find (']')) != std::string::npos) + value.replace (i, 1, "&close;"); + + while ((i = value.find (':')) != std::string::npos) + value.replace (i, 1, ":"); +} + +//////////////////////////////////////////////////////////////////////////////// +// Decode values after parse. +// \t <- &tab; +// " <- " +// , <- , +// [ <- &open; +// ] <- &close; +// : <- : +void Att::decode (std::string& value) const +{ + std::string::size_type i; + + while ((i = value.find ("&tab;")) != std::string::npos) + value.replace (i, 5, "\t"); + + while ((i = value.find (""")) != std::string::npos) + value.replace (i, 6, "\""); + + while ((i = value.find (",")) != std::string::npos) + value.replace (i, 7, ","); + + while ((i = value.find ("&open;")) != std::string::npos) + value.replace (i, 6, "["); + + while ((i = value.find ("&close;")) != std::string::npos) + value.replace (i, 7, "]"); + + while ((i = value.find (":")) != std::string::npos) + value.replace (i, 7, ":"); +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/Att.h b/src/Att.h new file mode 100644 index 000000000..d0c116cc1 --- /dev/null +++ b/src/Att.h @@ -0,0 +1,73 @@ +//////////////////////////////////////////////////////////////////////////////// +// task - a command line task list manager. +// +// Copyright 2006 - 2009, Paul Beckingham. +// 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_ATT +#define INCLUDED_ATT + +#include +#include + +class Att +{ +public: + Att (); // Default constructor + Att (const std::string&, const std::string&); // Simple constructor + Att (const Att&); // Copy constructor + Att& operator= (const Att&); // Assignment operator + ~Att (); // Destructor + + void parse (const std::string&); + std::string composeF4 () const; + + void addMod (const std::string&); + + std::string name () const; + void name (const std::string&); + + std::string value () const; + void value (const std::string&); + + int value_int () const; + void value_int (int); + + bool filter () const; + bool required () const; + bool reserved () const; + +private: + void enquote (std::string&) const; + void dequote (std::string&) const; + void encode (std::string&) const; + void decode (std::string&) const; + +private: + std::string mName; + std::string mValue; + std::vector mMods; +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/Config.cpp b/src/Config.cpp index 6a99189ad..ac63f9871 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -32,8 +32,9 @@ #include #include #include -#include "task.h" #include "Config.h" +#include "text.h" +#include "util.h" //////////////////////////////////////////////////////////////////////////////// // These are default (but overridable) reports. These entries are necessary diff --git a/src/Date.cpp b/src/Date.cpp index 995011345..cdc5cc7d3 100644 --- a/src/Date.cpp +++ b/src/Date.cpp @@ -28,8 +28,9 @@ #include #include #include -#include "task.h" #include "Date.h" +#include "text.h" +#include "util.h" //////////////////////////////////////////////////////////////////////////////// // Defaults to "now". diff --git a/src/Duration.cpp b/src/Duration.cpp new file mode 100644 index 000000000..7c55be345 --- /dev/null +++ b/src/Duration.cpp @@ -0,0 +1,160 @@ +//////////////////////////////////////////////////////////////////////////////// +// task - a command line task list manager. +// +// Copyright 2006 - 2009, Paul Beckingham. +// 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 +#include "text.h" +#include "util.h" +#include "Duration.h" + +//////////////////////////////////////////////////////////////////////////////// +Duration::Duration () +: mDays (0) +{ +} + +//////////////////////////////////////////////////////////////////////////////// +Duration::Duration (const Duration& other) +{ + throw std::string ("unimplemented Duration::Duration"); + mDays = other.mDays; +} + +//////////////////////////////////////////////////////////////////////////////// +Duration::Duration (const std::string& input) +{ + parse (input); +} + +//////////////////////////////////////////////////////////////////////////////// +Duration& Duration::operator= (const Duration& other) +{ + throw std::string ("unimplemented Duration::operator="); + if (this != &other) + { + mDays = other.mDays; + } + + return *this; +} + +//////////////////////////////////////////////////////////////////////////////// +Duration::operator int () +{ + return (int) mDays; +} + +//////////////////////////////////////////////////////////////////////////////// +Duration::operator time_t () +{ + return mDays; +} + +//////////////////////////////////////////////////////////////////////////////// +bool Duration::operator< (const Duration& other) +{ + return mDays < other.mDays; +} + +//////////////////////////////////////////////////////////////////////////////// +bool Duration::operator> (const Duration& other) +{ + return mDays > other.mDays; +} + +//////////////////////////////////////////////////////////////////////////////// +Duration::~Duration () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +void Duration::parse (const std::string& input) +{ + std::string lower_input = lowerCase (input); + + std::vector supported; + supported.push_back ("daily"); + supported.push_back ("day"); + supported.push_back ("weekly"); + supported.push_back ("weekdays"); + supported.push_back ("sennight"); + supported.push_back ("biweekly"); + supported.push_back ("fortnight"); + supported.push_back ("monthly"); + supported.push_back ("bimonthly"); + supported.push_back ("quarterly"); + supported.push_back ("biannual"); + supported.push_back ("biyearly"); + supported.push_back ("annual"); + supported.push_back ("semiannual"); + supported.push_back ("yearly"); + + std::vector matches; + if (autoComplete (lower_input, supported, matches) == 1) + { + std::string found = matches[0]; + + if (found == "daily" || found == "day") mDays = 1; + else if (found == "weekdays") mDays = 1; + else if (found == "weekly" || found == "sennight") mDays = 7; + else if (found == "biweekly" || found == "fortnight") mDays = 14; + else if (found == "monthly") mDays = 30; + else if (found == "bimonthly") mDays = 61; + else if (found == "quarterly") mDays = 91; + else if (found == "semiannual") mDays = 183; + else if (found == "yearly" || found == "annual") mDays = 365; + else if (found == "biannual" || found == "biyearly") mDays = 730; + } + + // Support \d+ d|w|m|q|y + else + { + // Verify all digits followed by d, w, m, q, or y. + unsigned int length = lower_input.length (); + for (unsigned int i = 0; i < length; ++i) + { + if (! isdigit (lower_input[i]) && + i == length - 1) + { + int number = ::atoi (lower_input.substr (0, i).c_str ()); + + switch (lower_input[length - 1]) + { + case 'd': mDays = number * 1; break; + case 'w': mDays = number * 7; break; + case 'm': mDays = number * 30; break; + case 'q': mDays = number * 91; break; + case 'y': mDays = number * 365; break; + } + } + } + } + + if (mDays == 0) + throw std::string ("The duration '") + input + "' was not recognized."; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/Duration.h b/src/Duration.h new file mode 100644 index 000000000..d5e1361dc --- /dev/null +++ b/src/Duration.h @@ -0,0 +1,54 @@ +//////////////////////////////////////////////////////////////////////////////// +// task - a command line task list manager. +// +// Copyright 2006 - 2009, Paul Beckingham. +// 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_DURATION +#define INCLUDED_DURATION + +#include +#include + +class Duration +{ +public: + Duration (); // Default constructor + Duration (const Duration&); // Copy constructor + Duration (const std::string&); // Parse + Duration& operator= (const Duration&); // Assignment operator + bool operator< (const Duration&); + bool operator> (const Duration&); + ~Duration (); // Destructor + + operator int (); + operator time_t (); + + void parse (const std::string&); + +private: + time_t mDays; +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/Makefile.am b/src/Makefile.am index 1d898a521..98250b935 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,2 +1,2 @@ bin_PROGRAMS = task -task_SOURCES = Config.cpp Date.cpp T.cpp TDB.cpp Table.cpp Grid.cpp Timer.cpp color.cpp parse.cpp task.cpp command.cpp edit.cpp report.cpp util.cpp text.cpp rules.cpp import.cpp Config.h Date.h T.h TDB.h Table.h Grid.h Timer.h color.h task.h +task_SOURCES = Config.cpp Date.cpp Record.cpp T.cpp TDB.cpp Att.cpp Mod.cpp Table.cpp Grid.cpp Timer.cpp Duration.cpp StringTable.cpp color.cpp parse.cpp task.cpp command.cpp edit.cpp report.cpp util.cpp text.cpp rules.cpp import.cpp Config.h Date.h Record.h T.h TDB.h Att.h Mod.h Table.h Grid.h Timer.h Duration.h StringTable.h color.h task.h diff --git a/src/Mod.cpp b/src/Mod.cpp new file mode 100644 index 000000000..3bfea6c5e --- /dev/null +++ b/src/Mod.cpp @@ -0,0 +1,100 @@ +//////////////////////////////////////////////////////////////////////////////// +// task - a command line task list manager. +// +// Copyright 2006 - 2009, Paul Beckingham. +// 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 "Mod.h" + +//////////////////////////////////////////////////////////////////////////////// +Mod::Mod () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +Mod::~Mod () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +// before after +// not +// none any +// over under +// synth +// first last +// this +// next +// is isnt +// has hasnt +// startswith endswith +bool Mod::isValid () +{ + if (*this == "before" || *this == "after" || + *this == "not" || + *this == "none" || *this == "any" || + *this == "synth" || + *this == "under" || *this == "over" || + *this == "first" || *this == "last" || + *this == "this" || + *this == "next" || + *this == "is" || *this == "isnt" || + *this == "has" || *this == "hasnt" || + *this == "startswith" || *this == "endswith") + return true; + + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +bool Mod::eval (const Mod& other) +{ + // before + // after + // non + // none + // any + // synth + // under + // over + // first + // last + // this + // next + + if (*this == ".is") + return *this == other ? true : false; + + if (*this == ".isnt") + return *this != other ? true : false; + + // has + // hasnt + // startswith + // endswith + + return false; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/Mod.h b/src/Mod.h new file mode 100644 index 000000000..4e7e6e669 --- /dev/null +++ b/src/Mod.h @@ -0,0 +1,45 @@ +//////////////////////////////////////////////////////////////////////////////// +// task - a command line task list manager. +// +// Copyright 2006 - 2009, Paul Beckingham. +// 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_MOD +#define INCLUDED_MOD + +#include + +class Mod; + +class Mod : public std::string +{ +public: + Mod (); // Default constructor + ~Mod (); // Destructor + + bool isValid (); + bool eval (const Mod&); +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/Record.cpp b/src/Record.cpp new file mode 100644 index 000000000..4249ac7e0 --- /dev/null +++ b/src/Record.cpp @@ -0,0 +1,65 @@ +//////////////////////////////////////////////////////////////////////////////// +// task - a command line task list manager. +// +// Copyright 2006 - 2009, Paul Beckingham. +// 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 "Record.h" + +//////////////////////////////////////////////////////////////////////////////// +Record::Record () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +Record::Record (const Record& other) +{ + throw std::string ("unimplemented Record::Record"); + mAtts = other.mAtts; +} + +//////////////////////////////////////////////////////////////////////////////// +Record& Record::operator= (const Record& other) +{ + throw std::string ("unimplemented Record:operator="); + if (this != &other) + { + mAtts = other.mAtts; + } + + return *this; +} + +//////////////////////////////////////////////////////////////////////////////// +Record::~Record () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +void Record::parse (const std::string& input) +{ + throw std::string ("unimplemented Record::parse"); +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/Record.h b/src/Record.h new file mode 100644 index 000000000..d35e8a02e --- /dev/null +++ b/src/Record.h @@ -0,0 +1,50 @@ +//////////////////////////////////////////////////////////////////////////////// +// task - a command line task list manager. +// +// Copyright 2006 - 2009, Paul Beckingham. +// 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_RECORD +#define INCLUDED_RECORD + +#include +#include "Att.h" + +class Record +{ +public: + Record (); // Default constructor + Record (const Record&); // Copy constructor + Record& operator= (const Record&); // Assignment operator + virtual ~Record (); // Destructor + + virtual std::string composeF4 () = 0; + virtual std::string composeCSV () = 0; + void parse (const std::string&); + +private: + std::vector mAtts; +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/StringTable.cpp b/src/StringTable.cpp new file mode 100644 index 000000000..9dac4626f --- /dev/null +++ b/src/StringTable.cpp @@ -0,0 +1,84 @@ +//////////////////////////////////////////////////////////////////////////////// +// task - a command line task list manager. +// +// Copyright 2006 - 2009, Paul Beckingham. +// 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 +#include "StringTable.h" + +//////////////////////////////////////////////////////////////////////////////// +StringTable::StringTable () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +StringTable::StringTable (const StringTable& other) +{ + throw std::string ("unimplemented StringTable::StringTable"); + mMapping = other.mMapping; +} + +//////////////////////////////////////////////////////////////////////////////// +StringTable& StringTable::operator= (const StringTable& other) +{ + throw std::string ("unimplemented StringTable::operator="); + if (this != &other) + { + mMapping = other.mMapping; + } + + return *this; +} + +//////////////////////////////////////////////////////////////////////////////// +StringTable::~StringTable () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +// [data.location] / language . XX +// UTF-8 encoding +// +// 123 This is the string +// 124 This is another string +// ... +void StringTable::load (const std::string& file) +{ + // TODO Load the specified file. +} + +//////////////////////////////////////////////////////////////////////////////// +std::string StringTable::get (int id) +{ + // Return the right string. + if (mMapping.find (id) != mMapping.end ()) + return mMapping[id]; + + std::stringstream error; + error << "MISSING " << id; + return error.str (); +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/StringTable.h b/src/StringTable.h new file mode 100644 index 000000000..ef0080d97 --- /dev/null +++ b/src/StringTable.h @@ -0,0 +1,49 @@ +//////////////////////////////////////////////////////////////////////////////// +// task - a command line task list manager. +// +// Copyright 2006 - 2009, Paul Beckingham. +// 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_STRINGTABLE +#define INCLUDED_STRINGTABLE + +#include +#include + +class StringTable +{ +public: + StringTable (); // Default constructor + StringTable (const StringTable&); // Copy constructor + StringTable& operator= (const StringTable&); // Assignment operator + ~StringTable (); // Destructor + + void load (const std::string&); + std::string get (int); + +private: + std::map mMapping; +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/T.cpp b/src/T.cpp index 58a280f62..43bf0e200 100644 --- a/src/T.cpp +++ b/src/T.cpp @@ -27,8 +27,9 @@ #include #include #include -#include "task.h" #include "T.h" +#include "text.h" +#include "util.h" //////////////////////////////////////////////////////////////////////////////// // Default diff --git a/src/TDB.cpp b/src/TDB.cpp index 98c2c8009..299eda3e6 100644 --- a/src/TDB.cpp +++ b/src/TDB.cpp @@ -31,8 +31,9 @@ #include #include -#include "task.h" +#include "T.h" #include "TDB.h" +#include "util.h" //////////////////////////////////////////////////////////////////////////////// TDB::TDB () diff --git a/src/Table.cpp b/src/Table.cpp index 1d78dfde1..f737d52e6 100644 --- a/src/Table.cpp +++ b/src/Table.cpp @@ -48,7 +48,9 @@ #include #include #include -#include +#include +#include "text.h" +#include "util.h" //////////////////////////////////////////////////////////////////////////////// Table::Table () @@ -989,7 +991,7 @@ void Table::sort (std::vector & order) break; else if ((std::string)*left != "" && (std::string)*right == "") SWAP - else if (convertDuration ((std::string)*left) > convertDuration ((std::string)*right)) + else if (Duration ((std::string)*left) > Duration ((std::string)*right)) SWAP break; @@ -998,7 +1000,7 @@ void Table::sort (std::vector & order) break; else if ((std::string)*left == "" && (std::string)*right != "") SWAP - else if (convertDuration ((std::string)*left) < convertDuration ((std::string)*right)) + else if (Duration ((std::string)*left) < Duration ((std::string)*right)) SWAP break; } diff --git a/src/command.cpp b/src/command.cpp index 41e8c6530..9f8e7b4a3 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -34,6 +34,10 @@ #include #include +#include "T.h" +#include "TDB.h" +#include "text.h" +#include "util.h" #include "task.h" #ifdef HAVE_LIBNCURSES diff --git a/src/edit.cpp b/src/edit.cpp index 445e8a1c6..30be75ec7 100644 --- a/src/edit.cpp +++ b/src/edit.cpp @@ -33,6 +33,11 @@ #include #include #include +#include "T.h" +#include "TDB.h" +#include "Date.h" +#include "text.h" +#include "util.h" #include "task.h" //////////////////////////////////////////////////////////////////////////////// diff --git a/src/import.cpp b/src/import.cpp index 163dca30d..bcb154147 100644 --- a/src/import.cpp +++ b/src/import.cpp @@ -29,6 +29,10 @@ #include #include #include "Date.h" +#include "T.h" +#include "TDB.h" +#include "text.h" +#include "util.h" #include "task.h" //////////////////////////////////////////////////////////////////////////////// diff --git a/src/objects/.gitignore b/src/objects/.gitignore new file mode 100644 index 000000000..625934097 --- /dev/null +++ b/src/objects/.gitignore @@ -0,0 +1 @@ +1.8 diff --git a/src/objects/Context.cpp b/src/objects/Context.cpp new file mode 100644 index 000000000..20233e4eb --- /dev/null +++ b/src/objects/Context.cpp @@ -0,0 +1,151 @@ +//////////////////////////////////////////////////////////////////////////////// +// task - a command line task list manager. +// +// Copyright 2006 - 2009, Paul Beckingham. +// 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 +#include "Context.h" +#include "text.h" +#include "util.h" +#include "task.h" +#include "../auto.h" + +//////////////////////////////////////////////////////////////////////////////// +Context::Context () +{ + // Set up randomness. +#ifdef HAVE_SRANDOM + srandom (time (NULL)); +#else + srand (time (NULL)); +#endif +} + +//////////////////////////////////////////////////////////////////////////////// +Context::Context (const Context& other) +{ + throw std::string ("unimplemented Context::Context"); + config = other.config; + filter = other.filter; + keymap = other.keymap; + sequence = other.sequence; + task = other.task; + tdb = other.tdb; +} + +//////////////////////////////////////////////////////////////////////////////// +Context& Context::operator= (const Context& other) +{ + throw std::string ("unimplemented Context::operator="); + if (this != &other) + { + config = other.config; + filter = other.filter; + keymap = other.keymap; + sequence = other.sequence; + task = other.task; + tdb = other.tdb; + } + + return *this; +} + +//////////////////////////////////////////////////////////////////////////////// +Context::~Context () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +void Context::initialize (int argc, char** argv) +{ + // Load the configuration file from the home directory. If the file cannot + // be found, offer to create a sample one. + loadCorrectConfigFile (argc, argv); + + // When redirecting output to a file, do not use color, curses. + if (!isatty (fileno (stdout))) + { + config.set ("curses", "off"); + + if (! config.get (std::string ("_forcecolor"), false)) + config.set ("color", "off"); + } + + // TODO Handle "--version, -v" right here. + + // init TDB. + std::string location = config.get ("data.location"); + std::vector all; + split (all, location, ','); + foreach (path, all) + tdb.location (expandPath (*path)); + + // Allow user override of file locking. Solaris/NFS machines may want this. + tdb.lock (config.get ("locking", true)); + + // TODO Load pending.data. + // TODO Load completed.data. + // TODO Load deleted.data. +} + +//////////////////////////////////////////////////////////////////////////////// +int Context::run () +{ + // TODO Dispatch to command handlers. + // TODO Auto shadow update. + // TODO Auto gc. + // TODO tdb.load (Filter); + + throw std::string ("unimplemented Context::run"); + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// +void Context::loadCorrectConfigFile (int argc, char** argv) +{ + for (int i = 1; i < argc; ++i) + { + if (! strncmp (argv[i], "rc:", 3)) + { + if (! access (&(argv[i][3]), F_OK)) + { + std::string file = &(argv[i][3]); + config.load (file); + return; + } + else + throw std::string ("Could not read configuration file '") + &(argv[i][3]) + "'"; + } + } + + struct passwd* pw = getpwuid (getuid ()); + if (!pw) + throw std::string ("Could not read home directory from passwd file."); + + std::string file = pw->pw_dir; + config.createDefault (file); +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/objects/Context.h b/src/objects/Context.h new file mode 100644 index 000000000..c0d50c68a --- /dev/null +++ b/src/objects/Context.h @@ -0,0 +1,64 @@ +//////////////////////////////////////////////////////////////////////////////// +// task - a command line task list manager. +// +// Copyright 2006 - 2009, Paul Beckingham. +// 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_CONTEXT +#define INCLUDED_CONTEXT + +#include "Filter.h" +#include "Keymap.h" +#include "Config.h" +#include "Sequence.h" +#include "T.h" +#include "TDB.h" + + +class Context +{ +public: + Context (); // Default constructor + Context (const Context&); // Copy constructor + Context& operator= (const Context&); // Assignment operator + ~Context (); // Destructor + + void initialize (int, char**); + int run (); + +private: + void loadCorrectConfigFile (int, char**); + +public: + Config config; + Filter filter; + Keymap keymap; + Sequence sequence; + T task; + TDB tdb; + +private: +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/objects/Filter.cpp b/src/objects/Filter.cpp new file mode 100644 index 000000000..69751fb32 --- /dev/null +++ b/src/objects/Filter.cpp @@ -0,0 +1,78 @@ +//////////////////////////////////////////////////////////////////////////////// +// task - a command line task list manager. +// +// Copyright 2006 - 2009, Paul Beckingham. +// 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 "Filter.h" + +//////////////////////////////////////////////////////////////////////////////// +Filter::Filter () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +Filter::Filter (const Filter& other) +{ + throw std::string ("unimplemented Filter::Filter"); + mAtts = other.mAtts; +} + +//////////////////////////////////////////////////////////////////////////////// +Filter& Filter::operator= (const Filter& other) +{ + throw std::string ("unimplemented Filter::operator="); + if (this != &other) + { + mAtts = other.mAtts; + } + + return *this; +} + +//////////////////////////////////////////////////////////////////////////////// +Filter::~Filter () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +void Filter::add (Att& att) +{ + mAtts.push_back (att); +} + +//////////////////////////////////////////////////////////////////////////////// +bool Filter::pass (Record& record) +{ + throw std::string ("unimplemented Filter::pass"); +/* + foreach (att, mAtts) + if (! att->match (record)) + return false; +*/ + + return true; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/objects/Filter.h b/src/objects/Filter.h new file mode 100644 index 000000000..879956fe3 --- /dev/null +++ b/src/objects/Filter.h @@ -0,0 +1,50 @@ +//////////////////////////////////////////////////////////////////////////////// +// task - a command line task list manager. +// +// Copyright 2006 - 2009, Paul Beckingham. +// 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_FILTER +#define INCLUDED_FILTER + +#include +#include "Att.h" +#include "Record.h" + +class Filter +{ +public: + Filter (); // Default constructor + Filter (const Filter&); // Copy constructor + Filter& operator= (const Filter&); // Assignment operator + ~Filter (); // Destructor + + void add (Att&); + bool pass (Record&); + +private: + std::vector mAtts; +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/objects/Keymap.cpp b/src/objects/Keymap.cpp new file mode 100644 index 000000000..388300cfd --- /dev/null +++ b/src/objects/Keymap.cpp @@ -0,0 +1,66 @@ +//////////////////////////////////////////////////////////////////////////////// +// task - a command line task list manager. +// +// Copyright 2006 - 2009, Paul Beckingham. +// 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 +#include "Keymap.h" + +//////////////////////////////////////////////////////////////////////////////// +Keymap::Keymap () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +Keymap::Keymap (const Keymap& other) +{ + throw std::string ("unimplemented Keymap::Keymap"); +// mOne = other.mOne; +} + +//////////////////////////////////////////////////////////////////////////////// +Keymap& Keymap::operator= (const Keymap& other) +{ + throw std::string ("unimplemented Keymap::operator="); + if (this != &other) + { +// mOne = other.mOne; + } + + return *this; +} + +//////////////////////////////////////////////////////////////////////////////// +Keymap::~Keymap () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +void Keymap::load (const std::string& file) +{ + throw std::string ("unimplemented Keymap::load"); +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/objects/Keymap.h b/src/objects/Keymap.h new file mode 100644 index 000000000..6ba8986f9 --- /dev/null +++ b/src/objects/Keymap.h @@ -0,0 +1,51 @@ +//////////////////////////////////////////////////////////////////////////////// +// task - a command line task list manager. +// +// Copyright 2006 - 2009, Paul Beckingham. +// 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_KEYMAP +#define INCLUDED_KEYMAP + +#include + +class Keymap +{ +public: + Keymap (); // Default constructor + Keymap (const Keymap&); // Copy constructor + Keymap& operator= (const Keymap&); // Assignment operator + ~Keymap (); // Destructor + + void load (const std::string&); // Load the map file +/* + real (); // Convert soft to real + soft (); // Convert real to soft +*/ + +private: + // TODO Structure for mapping strings to keys. +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/objects/Sequence.cpp b/src/objects/Sequence.cpp new file mode 100644 index 000000000..4c6bcf7f7 --- /dev/null +++ b/src/objects/Sequence.cpp @@ -0,0 +1,64 @@ +//////////////////////////////////////////////////////////////////////////////// +// task - a command line task list manager. +// +// Copyright 2006 - 2009, Paul Beckingham. +// 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 +#include "Sequence.h" + +//////////////////////////////////////////////////////////////////////////////// +Sequence::Sequence () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +Sequence::Sequence (const Sequence& other) +{ + throw std::string ("unimplemented Sequence::Sequence"); +} + +//////////////////////////////////////////////////////////////////////////////// +Sequence& Sequence::operator= (const Sequence& other) +{ + throw std::string ("unimplemented Sequence::operator="); + if (this != &other) + { + } + + return *this; +} + +//////////////////////////////////////////////////////////////////////////////// +Sequence::~Sequence () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +void Sequence::parse (const std::string& input) +{ + throw std::string ("unimplemented Sequence::parse"); +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/objects/Sequence.h b/src/objects/Sequence.h new file mode 100644 index 000000000..eb2abbee6 --- /dev/null +++ b/src/objects/Sequence.h @@ -0,0 +1,45 @@ +//////////////////////////////////////////////////////////////////////////////// +// task - a command line task list manager. +// +// Copyright 2006 - 2009, Paul Beckingham. +// 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_SEQUENCE +#define INCLUDED_SEQUENCE + +#include +#include + +class Sequence : public std::vector +{ +public: + Sequence (); // Default constructor + Sequence (const Sequence&); // Copy constructor + Sequence& operator= (const Sequence&); // Assignment operator + ~Sequence (); // Destructor + + void parse (const std::string&); +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/objects/T.cpp b/src/objects/T.cpp new file mode 100644 index 000000000..d3b761766 --- /dev/null +++ b/src/objects/T.cpp @@ -0,0 +1,74 @@ +//////////////////////////////////////////////////////////////////////////////// +// task - a command line task list manager. +// +// Copyright 2006 - 2009, Paul Beckingham. +// 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 +#include "T.h" + +//////////////////////////////////////////////////////////////////////////////// +T::T () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +T::T (const std::string& input) +{ + throw std::string ("unimplemented T::T"); +} + +//////////////////////////////////////////////////////////////////////////////// +T& T::operator= (const T& other) +{ + throw std::string ("unimplemented T::operator="); + if (this != &other) + { +// mOne = other.mOne; + } + + return *this; +} + +//////////////////////////////////////////////////////////////////////////////// +T::~T () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +// [name:value, name:"value",name:[name:value,name:value]] +std::string T::composeF4 () +{ + throw std::string ("unimplemented T::composeF4"); + return ""; +} + +//////////////////////////////////////////////////////////////////////////////// +std::string T::composeCSV () +{ + throw std::string ("unimplemented T::composeCSV"); + return ""; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/objects/T.h b/src/objects/T.h new file mode 100644 index 000000000..09683d4ab --- /dev/null +++ b/src/objects/T.h @@ -0,0 +1,48 @@ +//////////////////////////////////////////////////////////////////////////////// +// task - a command line task list manager. +// +// Copyright 2006 - 2009, Paul Beckingham. +// 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_T +#define INCLUDED_T + +#include +#include "Record.h" + +class T : public Record +{ +public: + T (); // Default constructor + T (const std::string&); // Parse + T& operator= (const T&); // Assignment operator + ~T (); // Destructor + + std::string composeF4 (); + std::string composeCSV (); + +private: +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/objects/TDB.cpp b/src/objects/TDB.cpp new file mode 100644 index 000000000..c53e9e9af --- /dev/null +++ b/src/objects/TDB.cpp @@ -0,0 +1,232 @@ +//////////////////////////////////////////////////////////////////////////////// +// task - a command line task list manager. +// +// Copyright 2006 - 2009, Paul Beckingham. +// 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 +#include +#include "text.h" +#include "util.h" +#include "TDB.h" +#include "task.h" + +//////////////////////////////////////////////////////////////////////////////// +// The ctor/dtor do nothing. +// The lock/unlock methods hold the file open. +// There should be only one commit. +// +// +- TDB::TDB +// | +// | +- TDB::lock +// | | open +// | | [lock] +// | | +// | | +- TDB::load (Filter) +// | | | read all +// | | | apply filter +// | | | return subset +// | | | +// | | +- TDB::add (T) +// | | | +// | | +- TDB::update (T, T') +// | | | +// | | +- TDB::commit +// | | write all +// | | +// | +- TDB::unlock +// | [unlock] +// | close +// | +// +- TDB::~TDB +// [TDB::unlock] +// +TDB::TDB () +: mLock (true) +, mAllOpenAndLocked (false) +{ +} + +//////////////////////////////////////////////////////////////////////////////// +TDB::TDB (const TDB& other) +{ + throw std::string ("unimplemented TDB::TDB"); + mLocations = other.mLocations; + mLock = other.mLock; + mAllOpenAndLocked = false; // Deliberately so. + + // Set all to NULL. + foreach (location, mLocations) + mLocations[location->first] = NULL; +} + +//////////////////////////////////////////////////////////////////////////////// +TDB& TDB::operator= (const TDB& other) +{ + throw std::string ("unimplemented TDB::operator="); + if (this != &other) + { + mLocations = other.mLocations; + mLock = other.mLock; + mAllOpenAndLocked = false; // Deliberately so. + + // Set all to NULL. + foreach (location, mLocations) + mLocations[location->first] = NULL; + } + + return *this; +} + +//////////////////////////////////////////////////////////////////////////////// +TDB::~TDB () +{ + if (mAllOpenAndLocked) + unlock (); +} + +//////////////////////////////////////////////////////////////////////////////// +void TDB::location (const std::string& path) +{ + if (access (expandPath (path).c_str (), F_OK)) + throw std::string ("Data location '") + + path + + "' does not exist, or is not readable and writable."; + + mLocations[path] = NULL; +} + +//////////////////////////////////////////////////////////////////////////////// +void TDB::lock (bool lockFile /* = true */) +{ + mLock = lockFile; + + foreach (location, mLocations) + mLocations[location->first] = openAndLock (location->first); + + mAllOpenAndLocked = true; +} + +//////////////////////////////////////////////////////////////////////////////// +void TDB::unlock () +{ + foreach (location, mLocations) + { + if (mLocations[location->first] != NULL) + { + fclose (mLocations[location->first]); + mLocations[location->first] = NULL; + } + } + + mAllOpenAndLocked = false; +} + +//////////////////////////////////////////////////////////////////////////////// +// TODO Returns number of filtered tasks. +int TDB::load (std::vector & tasks, Filter& filter) +{ + throw std::string ("unimplemented TDB::load"); + + // TODO Read each row. + // TODO Let T::parse disassemble it. + // TODO If task passes filter, add to tasks. + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// +// TODO Write to transaction log. +void TDB::add (T& after) +{ + throw std::string ("unimplemented TDB::add"); + + // TODO Seek to end of pending. + // TODO write after.composeFF4 (). +} + +//////////////////////////////////////////////////////////////////////////////// +// TODO Write to transaction log. +void TDB::update (T& before, T& after) +{ + throw std::string ("unimplemented TDB::update"); +} + +//////////////////////////////////////////////////////////////////////////////// +// TODO writes all, including comments +int TDB::commit () +{ + throw std::string ("unimplemented TDB::commit"); +} + +//////////////////////////////////////////////////////////////////////////////// +// TODO -> FF4 +void TDB::upgrade () +{ + throw std::string ("unimplemented TDB::upgrade"); +} + +//////////////////////////////////////////////////////////////////////////////// +void TDB::getPendingFiles (std::vector files) +{ + files.clear (); + + foreach (location, mLocations) + files.push_back (location->first + "/pending.data"); +} + +//////////////////////////////////////////////////////////////////////////////// +void TDB::getCompletedFiles (std::vector files) +{ + files.clear (); + + foreach (location, mLocations) + files.push_back (location->first + "/completed.data"); +} + +//////////////////////////////////////////////////////////////////////////////// +FILE* TDB::openAndLock (const std::string& file) +{ + // Check for access. + if (access (file.c_str (), F_OK | R_OK | W_OK)) + throw std::string ("Task does not have the correct permissions for '") + + file + "'."; + + // Open the file. + FILE* in = fopen (file.c_str (), "rw"); + if (!in) + throw std::string ("Could not open '") + file + "'."; + + // Lock if desired. Try three times before failing. + int retry = 0; + if (mLock) + while (flock (fileno (in), LOCK_EX) && ++retry <= 3) + delay (0.1); + + if (!in) + throw std::string ("Could not lock '") + file + "'."; + + return in; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/objects/TDB.h b/src/objects/TDB.h new file mode 100644 index 000000000..c2f94f697 --- /dev/null +++ b/src/objects/TDB.h @@ -0,0 +1,69 @@ +//////////////////////////////////////////////////////////////////////////////// +// task - a command line task list manager. +// +// Copyright 2006 - 2009, Paul Beckingham. +// 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_TDB +#define INCLUDED_TDB + +#include +#include +#include +#include "Filter.h" +#include "T.h" + +class TDB +{ +public: + TDB (); // Default constructor + TDB (const TDB&); // Copy constructor + TDB& operator= (const TDB&); // Assignment operator + ~TDB (); // Destructor + + void location (const std::string&); + + void lock (bool lockFile = true); + void unlock (); + + int load (std::vector &, Filter&); + void add (T&); + void update (T&, T&); + int commit (); + void upgrade (); + +private: + void getPendingFiles (std::vector ); + void getCompletedFiles (std::vector ); + FILE* openAndLock (const std::string&); + +private: + std::map mLocations; + bool mLock; + bool mAllOpenAndLocked; + + // TODO Need cache of raw file contents. +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/objects/main.cpp b/src/objects/main.cpp new file mode 100644 index 000000000..a4571e89e --- /dev/null +++ b/src/objects/main.cpp @@ -0,0 +1,30 @@ +//////////////////////////////////////////////////////////////////////////////// +#include +#include +#include "Context.h" + +int main (int argc, char** argv) +{ + try + { + Context c; + c.initialize (argc, argv); + c.run (); + + return 0; + } + + catch (std::string e) + { + std::cerr << e << std::endl; + } + + catch (...) + { + std::cerr << "task internal error." << std::endl; + } + + return -1; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/parse.cpp b/src/parse.cpp index ae10e2be5..b4e40aa34 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -31,8 +31,10 @@ #include #include "Date.h" -#include "task.h" +#include "Duration.h" #include "T.h" +#include "text.h" +#include "util.h" //////////////////////////////////////////////////////////////////////////////// // NOTE: These are static arrays only because there is no initializer list for @@ -445,7 +447,9 @@ static bool validSubstitution ( //////////////////////////////////////////////////////////////////////////////// bool validDuration (std::string& input) { - return (convertDuration (input) != 0) ? true : false; + try { Duration (input); } + catch (...) { return false; } + return true; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/report.cpp b/src/report.cpp index 050f6e85c..17f5bd1fb 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -40,6 +40,8 @@ #include "Table.h" #include "TDB.h" #include "T.h" +#include "text.h" +#include "util.h" #include "task.h" #ifdef HAVE_LIBNCURSES diff --git a/src/rules.cpp b/src/rules.cpp index 5744dd3ca..2030e1a36 100644 --- a/src/rules.cpp +++ b/src/rules.cpp @@ -30,7 +30,8 @@ #include "Table.h" #include "Date.h" #include "T.h" -#include "task.h" +#include "text.h" +#include "util.h" static std::map gsFg; static std::map gsBg; diff --git a/src/task.cpp b/src/task.cpp index 4d2390154..57526180a 100644 --- a/src/task.cpp +++ b/src/task.cpp @@ -38,9 +38,12 @@ #include "Config.h" #include "Date.h" +#include "Duration.h" #include "Table.h" #include "TDB.h" #include "T.h" +#include "text.h" +#include "util.h" #include "task.h" #ifdef HAVE_LIBNCURSES @@ -717,7 +720,10 @@ Date getNextRecurrence (Date& current, std::string& period) } // If the period is an 'easy' one, add it to current, and we're done. - int days = convertDuration (period); + int days = 0; + try { Duration du (period); days = du; } + catch (...) { days = 0; } + return current + (days * 86400); } diff --git a/src/task.h b/src/task.h index 7599007ea..3104c5d6d 100644 --- a/src/task.h +++ b/src/task.h @@ -33,26 +33,8 @@ #include "Table.h" #include "Date.h" #include "color.h" -#include "TDB.h" -#include "T.h" #include "../auto.h" -#ifndef min -#define min(a,b) ((a) < (b) ? (a) : (b)) -#endif - -#ifndef max -#define max(a,b) ((a) > (b) ? (a) : (b)) -#endif - -#define foreach(i, c) \ -for (typeof (c) *foreach_p = & (c); \ - foreach_p; \ - foreach_p = 0) \ - for (typeof (foreach_p->begin()) i = foreach_p->begin(); \ - i != foreach_p->end(); \ - ++i) - // parse.cpp void parse (std::vector &, std::string&, T&, Config&); bool validPriority (const std::string&); @@ -120,44 +102,6 @@ std::string handleCustomReport (TDB&, T&, Config&, const std::string&); void validReportColumns (const std::vector &); void validSortColumns (const std::vector &, const std::vector &); -// text.cpp -void wrapText (std::vector &, const std::string&, const int); -std::string trimLeft (const std::string& in, const std::string& t = " "); -std::string trimRight (const std::string& in, const std::string& t = " "); -std::string trim (const std::string& in, const std::string& t = " "); -std::string unquoteText (const std::string&); -void extractLine (std::string&, std::string&, int); -void split (std::vector&, const std::string&, const char); -void split (std::vector&, const std::string&, const std::string&); -void join (std::string&, const std::string&, const std::vector&); -std::string commify (const std::string&); -std::string lowerCase (const std::string&); -std::string upperCase (const std::string&); -const char* optionalBlankLine (Config&); - -// util.cpp -bool confirm (const std::string&); -void delay (float); -void formatTimeDeltaDays (std::string&, time_t); -std::string formatSeconds (time_t); -int autoComplete (const std::string&, const std::vector&, std::vector&); -const std::string uuid (); -int convertDuration (const std::string&); -std::string expandPath (const std::string&); - -#ifdef SOLARIS - #define LOCK_SH 1 - #define LOCK_EX 2 - #define LOCK_NB 4 - #define LOCK_UN 8 - - int flock (int, int); -#endif - -bool slurp (const std::string&, std::vector &, bool trimLines = false); -bool slurp (const std::string&, std::string&, bool trimLines = false); -void spit (const std::string&, const std::string&); - // rules.cpp void initializeColorRules (Config&); void autoColorize (T&, Text::color&, Text::color&, Config&); diff --git a/src/tests/Makefile b/src/tests/Makefile index a71c8633e..6278cf5e7 100644 --- a/src/tests/Makefile +++ b/src/tests/Makefile @@ -2,7 +2,8 @@ PROJECT = t.t tdb.t date.t duration.t t.benchmark.t text.t autocomplete.t \ parse.t CFLAGS = -I. -I.. -Wall -pedantic -ggdb3 -fno-rtti LFLAGS = -L/usr/local/lib -OBJECTS = ../TDB.o ../T.o ../parse.o ../text.o ../Date.o ../util.o ../Config.o +OBJECTS = ../TDB.o ../T.o ../parse.o ../text.o ../Date.o ../Duration.o \ + ../util.o ../Config.o all: $(PROJECT) diff --git a/src/tests/duration.t.cpp b/src/tests/duration.t.cpp index 77e46a95c..c1c5e2108 100644 --- a/src/tests/duration.t.cpp +++ b/src/tests/duration.t.cpp @@ -25,9 +25,8 @@ // //////////////////////////////////////////////////////////////////////////////// #include -#include +#include #include -#include <../task.h> //////////////////////////////////////////////////////////////////////////////// // daily, day, Nd @@ -36,29 +35,37 @@ // 1st 2nd 3rd 4th .. 31st // quarterly, Nq // biannual, biyearly, annual, semiannual, yearly, Ny + +int convertDuration (const std::string& input) +{ + try { Duration d (input); return (int) d; } + catch (...) {} + return 0; +} + int main (int argc, char** argv) { UnitTest t (17); std::string d; - d = "daily"; t.is (convertDuration (d), 1, "duration daily = 1"); - d = "weekdays"; t.is (convertDuration (d), 1, "duration weekdays = 1"); - d = "day"; t.is (convertDuration (d), 1, "duration day = 1"); - d = "0d"; t.is (convertDuration (d), 0, "duration 0d = 0"); - d = "1d"; t.is (convertDuration (d), 1, "duration 1d = 1"); - d = "7d"; t.is (convertDuration (d), 7, "duration 7d = 7"); - d = "10d"; t.is (convertDuration (d), 10, "duration 10d = 10"); - d = "100d"; t.is (convertDuration (d), 100, "duration 100d = 100"); + t.is (convertDuration ("daily"), 1, "duration daily = 1"); + t.is (convertDuration ("weekdays"), 1, "duration weekdays = 1"); + t.is (convertDuration ("day"), 1, "duration day = 1"); + t.is (convertDuration ("0d"), 0, "duration 0d = 0"); + t.is (convertDuration ("1d"), 1, "duration 1d = 1"); + t.is (convertDuration ("7d"), 7, "duration 7d = 7"); + t.is (convertDuration ("10d"), 10, "duration 10d = 10"); + t.is (convertDuration ("100d"), 100, "duration 100d = 100"); - d = "weekly"; t.is (convertDuration (d), 7, "duration weekly = 7"); - d = "sennight"; t.is (convertDuration (d), 7, "duration sennight = 7"); - d = "biweekly"; t.is (convertDuration (d), 14, "duration biweekly = 14"); - d = "fortnight"; t.is (convertDuration (d), 14, "duration fortnight = 14"); - d = "0w"; t.is (convertDuration (d), 0, "duration 0w = 0"); - d = "1w"; t.is (convertDuration (d), 7, "duration 1w = 7"); - d = "7w"; t.is (convertDuration (d), 49, "duration 7w = 49"); - d = "10w"; t.is (convertDuration (d), 70, "duration 10w = 70"); - d = "100w"; t.is (convertDuration (d), 700, "duration 100w = 700"); + t.is (convertDuration ("weekly"), 7, "duration weekly = 7"); + t.is (convertDuration ("sennight"), 7, "duration sennight = 7"); + t.is (convertDuration ("biweekly"), 14, "duration biweekly = 14"); + t.is (convertDuration ("fortnight"), 14, "duration fortnight = 14"); + t.is (convertDuration ("0w"), 0, "duration 0w = 0"); + t.is (convertDuration ("1w"), 7, "duration 1w = 7"); + t.is (convertDuration ("7w"), 49, "duration 7w = 49"); + t.is (convertDuration ("10w"), 70, "duration 10w = 70"); + t.is (convertDuration ("100w"), 700, "duration 100w = 700"); return 0; } diff --git a/src/text.cpp b/src/text.cpp index 69689a5ac..ac1015031 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -27,7 +27,9 @@ #include #include #include -#include "task.h" +#include "Config.h" +#include "util.h" +#include "text.h" static const char* newline = "\n"; static const char* noline = ""; diff --git a/src/text.h b/src/text.h new file mode 100644 index 000000000..458d714d0 --- /dev/null +++ b/src/text.h @@ -0,0 +1,51 @@ +//////////////////////////////////////////////////////////////////////////////// +// task - a command line task list manager. +// +// Copyright 2006 - 2009, Paul Beckingham. +// 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_TEXT +#define INCLUDED_TEXT + +#include +#include +#include "Config.h" +#include "../auto.h" + +// text.cpp +void wrapText (std::vector &, const std::string&, const int); +std::string trimLeft (const std::string& in, const std::string& t = " "); +std::string trimRight (const std::string& in, const std::string& t = " "); +std::string trim (const std::string& in, const std::string& t = " "); +std::string unquoteText (const std::string&); +void extractLine (std::string&, std::string&, int); +void split (std::vector&, const std::string&, const char); +void split (std::vector&, const std::string&, const std::string&); +void join (std::string&, const std::string&, const std::vector&); +std::string commify (const std::string&); +std::string lowerCase (const std::string&); +std::string upperCase (const std::string&); +const char* optionalBlankLine (Config&); + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/util.cpp b/src/util.cpp index 261e7d4af..8cbb9cfe2 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -38,6 +38,9 @@ #include #include "Date.h" #include "Table.h" +#include "T.h" +#include "TDB.h" +#include "text.h" #include "task.h" #include "../auto.h" @@ -280,74 +283,6 @@ const std::string uuid () } #endif -//////////////////////////////////////////////////////////////////////////////// -// Recognize the following constructs, and return the number of days represented -int convertDuration (const std::string& input) -{ - std::string lower_input = lowerCase (input); - Date today; - - std::vector supported; - supported.push_back ("daily"); - supported.push_back ("day"); - supported.push_back ("weekly"); - supported.push_back ("weekdays"); - supported.push_back ("sennight"); - supported.push_back ("biweekly"); - supported.push_back ("fortnight"); - supported.push_back ("monthly"); - supported.push_back ("bimonthly"); - supported.push_back ("quarterly"); - supported.push_back ("biannual"); - supported.push_back ("biyearly"); - supported.push_back ("annual"); - supported.push_back ("semiannual"); - supported.push_back ("yearly"); - - std::vector matches; - if (autoComplete (lower_input, supported, matches) == 1) - { - std::string found = matches[0]; - - if (found == "daily" || found == "day") return 1; - else if (found == "weekdays") return 1; - else if (found == "weekly" || found == "sennight") return 7; - else if (found == "biweekly" || found == "fortnight") return 14; - else if (found == "monthly") return 30; - else if (found == "bimonthly") return 61; - else if (found == "quarterly") return 91; - else if (found == "semiannual") return 183; - else if (found == "yearly" || found == "annual") return 365; - else if (found == "biannual" || found == "biyearly") return 730; - } - - // Support \d+ d|w|m|q|y - else - { - // Verify all digits followed by d, w, m, q, or y. - unsigned int length = lower_input.length (); - for (unsigned int i = 0; i < length; ++i) - { - if (! isdigit (lower_input[i]) && - i == length - 1) - { - int number = ::atoi (lower_input.substr (0, i).c_str ()); - - switch (lower_input[length - 1]) - { - case 'd': return number * 1; break; - case 'w': return number * 7; break; - case 'm': return number * 30; break; - case 'q': return number * 91; break; - case 'y': return number * 365; break; - } - } - } - } - - return 0; // Error. -} - //////////////////////////////////////////////////////////////////////////////// std::string expandPath (const std::string& in) { diff --git a/src/util.h b/src/util.h new file mode 100644 index 000000000..2bfaef59a --- /dev/null +++ b/src/util.h @@ -0,0 +1,76 @@ +//////////////////////////////////////////////////////////////////////////////// +// task - a command line task list manager. +// +// Copyright 2006 - 2009, Paul Beckingham. +// 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_UTIL +#define INCLUDED_UTIL + +#include +#include +#include +#include +#include "../auto.h" + +#ifndef min +#define min(a,b) ((a) < (b) ? (a) : (b)) +#endif + +#ifndef max +#define max(a,b) ((a) > (b) ? (a) : (b)) +#endif + +#define foreach(i, c) \ +for (typeof (c) *foreach_p = & (c); \ + foreach_p; \ + foreach_p = 0) \ + for (typeof (foreach_p->begin()) i = foreach_p->begin(); \ + i != foreach_p->end(); \ + ++i) + +// util.cpp +bool confirm (const std::string&); +void delay (float); +void formatTimeDeltaDays (std::string&, time_t); +std::string formatSeconds (time_t); +int autoComplete (const std::string&, const std::vector&, std::vector&); +const std::string uuid (); +int convertDuration (const std::string&); +std::string expandPath (const std::string&); + +#ifdef SOLARIS + #define LOCK_SH 1 + #define LOCK_EX 2 + #define LOCK_NB 4 + #define LOCK_UN 8 + + int flock (int, int); +#endif + +bool slurp (const std::string&, std::vector &, bool trimLines = false); +bool slurp (const std::string&, std::string&, bool trimLines = false); +void spit (const std::string&, const std::string&); + +#endif +////////////////////////////////////////////////////////////////////////////////