mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
FF4 - snapshot
This commit is contained in:
parent
04f60a4d8c
commit
3a9c98d342
11 changed files with 127 additions and 30 deletions
|
@ -34,7 +34,7 @@ class Att
|
|||
{
|
||||
public:
|
||||
Att (); // Default constructor
|
||||
Att (const std::string&, const std::string&);
|
||||
Att (const std::string&, const std::string&); // Simple constructor
|
||||
Att (const Att&); // Copy constructor
|
||||
Att& operator= (const Att&); // Assignment operator
|
||||
~Att (); // Destructor
|
||||
|
|
|
@ -25,11 +25,22 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <pwd.h>
|
||||
#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
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -67,24 +78,39 @@ Context::~Context ()
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Context::initialize ()
|
||||
void Context::initialize (int argc, char** argv)
|
||||
{
|
||||
throw std::string ("unimplemented Context::initialize");
|
||||
// TODO Load config.
|
||||
// Load the config 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 <std::string> all;
|
||||
split (all, location, ',');
|
||||
foreach (path, all)
|
||||
tdb.location (expandPath (*path));
|
||||
|
||||
// Allow user override of file locking. Solaris/NFS machines may want this.
|
||||
if (! config.get ("locking", true))
|
||||
tdb.noLock ();
|
||||
|
||||
// TODO Load pending.data.
|
||||
// TODO Load completed.data.
|
||||
// TODO Load deleted.data.
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int Context::commandLine (int argc, char** argv)
|
||||
{
|
||||
throw std::string ("unimplemented Context::commandLine");
|
||||
// TODO Support rc: override.
|
||||
// TODO Handle "--version, -v" right here.
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int Context::run ()
|
||||
{
|
||||
|
@ -97,4 +123,29 @@ int Context::run ()
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
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);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -31,8 +31,8 @@
|
|||
#include "Keymap.h"
|
||||
#include "Config.h"
|
||||
#include "Sequence.h"
|
||||
#include "TDB.h"
|
||||
#include "T.h"
|
||||
#include "TDB.h"
|
||||
|
||||
|
||||
class Context
|
||||
|
@ -43,10 +43,12 @@ public:
|
|||
Context& operator= (const Context&); // Assignment operator
|
||||
~Context (); // Destructor
|
||||
|
||||
void initialize ();
|
||||
int commandLine (int, char**);
|
||||
void initialize (int, char**);
|
||||
int run ();
|
||||
|
||||
private:
|
||||
void loadCorrectConfigFile (int, char**);
|
||||
|
||||
public:
|
||||
Config config;
|
||||
Filter filter;
|
||||
|
|
|
@ -3,7 +3,7 @@ CFLAGS = -I. -I.. -Wall -pedantic -ggdb3 -fno-rtti -fstack-check
|
|||
LFLAGS =
|
||||
LIBS =
|
||||
OBJECTS = main.o Context.o TDB.o T.o Sequence.o Filter.o Att.o Keymap.o \
|
||||
../util.o ../text.o ../Config.o ../Date.o
|
||||
Record.o ../util.o ../text.o ../Config.o ../Date.o
|
||||
|
||||
all: $(PROJECT)
|
||||
|
||||
|
|
|
@ -57,4 +57,9 @@ Record::~Record ()
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Record::parse (const std::string& input)
|
||||
{
|
||||
throw std::string ("unimplemented Record::parse");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -36,7 +36,11 @@ public:
|
|||
Record (); // Default constructor
|
||||
Record (const Record&); // Copy constructor
|
||||
Record& operator= (const Record&); // Assignment operator
|
||||
~Record (); // Destructor
|
||||
virtual ~Record (); // Destructor
|
||||
|
||||
virtual std::string composeF4 () = 0;
|
||||
virtual std::string composeCSV () = 0;
|
||||
void parse (const std::string&);
|
||||
|
||||
private:
|
||||
std::vector <Att> mAtts;
|
||||
|
|
|
@ -34,11 +34,13 @@ T::T ()
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
T::T (const T& other)
|
||||
{
|
||||
throw std::string ("unimplemented T::T");
|
||||
// mOne = other.mOne;
|
||||
}
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
T::T (const std::string& input)
|
||||
|
@ -78,9 +80,3 @@ std::string T::composeCSV ()
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void T::parse (const std::string& input)
|
||||
{
|
||||
throw std::string ("unimplemented T::parse");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -28,19 +28,19 @@
|
|||
#define INCLUDED_T
|
||||
|
||||
#include <string>
|
||||
#include "Record.h"
|
||||
|
||||
class T
|
||||
class T : public Record
|
||||
{
|
||||
public:
|
||||
T (); // Default constructor
|
||||
T (const T&); // Copy constructor
|
||||
// T (const T&); // Copy constructor
|
||||
T (const std::string&); // Parse
|
||||
T& operator= (const T&); // Assignment operator
|
||||
~T (); // Destructor
|
||||
|
||||
std::string composeF4 ();
|
||||
std::string composeCSV ();
|
||||
void parse (const std::string&);
|
||||
|
||||
private:
|
||||
};
|
||||
|
|
|
@ -26,10 +26,14 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <string>
|
||||
#include "text.h"
|
||||
#include "util.h"
|
||||
#include "TDB.h"
|
||||
#include "task.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
TDB::TDB ()
|
||||
: mLock (true)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -60,7 +64,11 @@ TDB::~TDB ()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
void TDB::location (const std::string& path)
|
||||
{
|
||||
throw std::string ("unimplemented TDB::location");
|
||||
if (access (expandPath (path).c_str (), F_OK))
|
||||
throw std::string ("Data location '") +
|
||||
path +
|
||||
"' does not exist, or is not readable and writable.";
|
||||
|
||||
mLocations.push_back (path);
|
||||
}
|
||||
|
||||
|
@ -94,3 +102,27 @@ void TDB::upgrade ()
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void TDB::noLock ()
|
||||
{
|
||||
mLock = false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void TDB::getPendingFiles (std::vector <std::string> files)
|
||||
{
|
||||
files.clear ();
|
||||
|
||||
foreach (location, mLocations)
|
||||
files.push_back (*location + "/pending.data");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void TDB::getCompletedFiles (std::vector <std::string> files)
|
||||
{
|
||||
files.clear ();
|
||||
|
||||
foreach (location, mLocations)
|
||||
files.push_back (*location + "/completed.data");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -46,8 +46,16 @@ public:
|
|||
int commit ();
|
||||
void upgrade ();
|
||||
|
||||
void noLock ();
|
||||
|
||||
private:
|
||||
void getPendingFiles (std::vector <std::string>);
|
||||
void getCompletedFiles (std::vector <std::string>);
|
||||
|
||||
private:
|
||||
std::vector <std::string> mLocations;
|
||||
bool mLock;
|
||||
|
||||
// TODO Need cache of raw file contents.
|
||||
};
|
||||
|
||||
|
|
|
@ -8,8 +8,7 @@ int main (int argc, char** argv)
|
|||
try
|
||||
{
|
||||
Context c;
|
||||
c.initialize ();
|
||||
c.commandLine (argc, argv);
|
||||
c.initialize (argc, argv);
|
||||
c.run ();
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue