diff --git a/src/sandbox/Location.cpp b/src/sandbox/Location.cpp new file mode 100644 index 000000000..984a2da98 --- /dev/null +++ b/src/sandbox/Location.cpp @@ -0,0 +1,70 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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 "Location.h" + +//////////////////////////////////////////////////////////////////////////////// +Location::Location () +: path ("") +, pending (NULL) +, completed (NULL) +{ +} + +//////////////////////////////////////////////////////////////////////////////// +Location::Location (const std::string& p) +: path (p) +{ +} + +//////////////////////////////////////////////////////////////////////////////// +Location::Location (const Location& other) +{ + path = other.path; + pending = other.pending; + completed = other.completed; +} + +//////////////////////////////////////////////////////////////////////////////// +Location& Location::operator= (const Location& other) +{ + if (this != &other) + { + path = other.path; + pending = other.pending; + completed = other.completed; + } + + return *this; +} + +//////////////////////////////////////////////////////////////////////////////// +Location::~Location () +{ +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/sandbox/Location.h b/src/sandbox/Location.h new file mode 100644 index 000000000..4a93ea7df --- /dev/null +++ b/src/sandbox/Location.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_LOCATION +#define INCLUDED_LOCATION + +#include +#include + +class Location +{ +public: + Location (); // Default constructor + Location (const std::string&); // Default constructor + Location (const Location&); // Copy constructor + Location& operator= (const Location&); // Assignment operator + ~Location (); // Destructor + +public: + std::string path; + FILE* pending; + FILE* completed; +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/sandbox/Makefile b/src/sandbox/Makefile index c0672cdbd..ae332b040 100644 --- a/src/sandbox/Makefile +++ b/src/sandbox/Makefile @@ -1,10 +1,10 @@ PROJECT = 1.8 -CFLAGS = -I. -I.. -Wall -pedantic -ggdb3 -fno-rtti -fstack-check +CFLAGS = -I. -I.. -Wall -pedantic -ggdb3 -fno-rtti -fno-stack-check LFLAGS = LIBS = OBJECTS = main.o Context.o TDB.o T.o ../Sequence.o ../Filter.o ../Att.o \ Keymap.o ../Record.o ../Mod.o ../StringTable.o ../util.o ../text.o \ - ../Date.o ../Config.o + ../Date.o ../Config.o Location.o all: $(PROJECT) diff --git a/src/sandbox/TDB.cpp b/src/sandbox/TDB.cpp index 3bca2e2f5..a92803fa3 100644 --- a/src/sandbox/TDB.cpp +++ b/src/sandbox/TDB.cpp @@ -73,30 +73,32 @@ TDB::TDB () 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; +// mLocations = other.mLocations; +// mFiles = other.mFiles; +// mLock = other.mLock; +// mAllOpenAndLocked = false; // Deliberately so. +// +// // Set all to NULL, otherwise we are duplicating open file handles. +// foreach (file, mFiles) +// mFiles[file->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; - } - +// if (this != &other) +// { +// mLocations = other.mLocations; +// mFiles = other.mFiles; +// mLock = other.mLock; +// mAllOpenAndLocked = false; // Deliberately so. +// +// // Set all to NULL, otherwise we are duplicating open file handles. +// foreach (file, mFiles) +// mFiles[file->first] = NULL; +// } +// return *this; } @@ -115,7 +117,7 @@ void TDB::location (const std::string& path) path + "' does not exist, or is not readable and writable."; - mLocations[path] = NULL; + mLocations.push_back (Location (path)); } //////////////////////////////////////////////////////////////////////////////// @@ -124,7 +126,10 @@ void TDB::lock (bool lockFile /* = true */) mLock = lockFile; foreach (location, mLocations) - mLocations[location->first] = openAndLock (location->first); + { + location->pending = openAndLock (location->path + "/pending.data"); + location->completed = openAndLock (location->path + "/completed.data"); + } mAllOpenAndLocked = true; } @@ -132,16 +137,18 @@ void TDB::lock (bool lockFile /* = true */) //////////////////////////////////////////////////////////////////////////////// void TDB::unlock () { - foreach (location, mLocations) + if (mAllOpenAndLocked) { - if (mLocations[location->first] != NULL) + foreach (location, mLocations) { - fclose (mLocations[location->first]); - mLocations[location->first] = NULL; + fclose (location->pending); + location->pending = NULL; + fclose (location->completed); + location->completed = NULL; } - } - mAllOpenAndLocked = false; + mAllOpenAndLocked = false; + } } //////////////////////////////////////////////////////////////////////////////// @@ -151,11 +158,27 @@ int TDB::load (std::vector & tasks, Filter& filter) char line[T_LINE_MAX]; foreach (location, mLocations) { + std::cout << "# location.path: " << location->path << std::endl; + while (fgets (line, T_LINE_MAX, location->pending)) + { + int length = ::strlen (line); + if (length > 1) + { + line[length - 1] = '\0'; // Kill \n + std::cout << "# line: " << line << std::endl; + T task (line); - std::cout << "# location: " << location->first << std::endl; - while (fgets (line, T_LINE_MAX, location->second)) + if (filter.pass (task)) + { + // TODO Add hidden attribute indicating source. + tasks.push_back (task); + } + } + } + + while (fgets (line, T_LINE_MAX, location->completed)) { int length = ::strlen (line); if (length > 1) @@ -208,39 +231,6 @@ 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"); -} - -//////////////////////////////////////////////////////////////////////////////// -void TDB::getContactFiles (std::vector files) -{ - files.clear (); - - foreach (location, mLocations) - files.push_back (location->first + "/contact.data"); -} - -//////////////////////////////////////////////////////////////////////////////// -void TDB::getUndoStack (std::string& file) -{ - throw std::string ("unimplemented TDB::getUndoStack"); -} - //////////////////////////////////////////////////////////////////////////////// FILE* TDB::openAndLock (const std::string& file) { diff --git a/src/sandbox/TDB.h b/src/sandbox/TDB.h index 5b09168ca..40afcfdc7 100644 --- a/src/sandbox/TDB.h +++ b/src/sandbox/TDB.h @@ -30,8 +30,9 @@ #include #include #include -#include "Filter.h" -#include "T.h" +#include +#include +#include // Length of longest line. #define T_LINE_MAX 32768 @@ -56,14 +57,10 @@ public: void upgrade (); private: - void getPendingFiles (std::vector ); - void getCompletedFiles (std::vector ); - void getContactFiles (std::vector ); - void getUndoStack (std::string&); FILE* openAndLock (const std::string&); private: - std::map mLocations; + std::vector mLocations; bool mLock; bool mAllOpenAndLocked;