Code Cleanup

- Removed obsolete code from main.cpp.
This commit is contained in:
Paul Beckingham 2009-06-11 21:34:40 -04:00
parent 37e08df8ba
commit 5836430cc1
3 changed files with 29 additions and 102 deletions

View file

@ -66,6 +66,13 @@ Context::~Context ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Context::initialize (int argc, char** argv) void Context::initialize (int argc, char** argv)
{ {
// Set up randomness.
#ifdef HAVE_SRANDOM
srandom (time (NULL));
#else
srand (time (NULL));
#endif
// Capture the args. // Capture the args.
for (int i = 0; i < argc; ++i) for (int i = 0; i < argc; ++i)
if (i == 0) if (i == 0)
@ -221,6 +228,18 @@ void Context::shadow ()
std::string shadowFile = expandPath (config.get ("shadow.file")); std::string shadowFile = expandPath (config.get ("shadow.file"));
if (shadowFile != "") if (shadowFile != "")
{ {
// TODO Reinstate these checks.
/*
// Check for silly shadow file settings.
if (shadowFile == dataLocation + "/pending.data")
throw std::string ("Configuration variable 'shadow.file' is set to "
"overwrite your pending tasks. Please change it.");
if (shadowFile == dataLocation + "/completed.data")
throw std::string ("Configuration variable 'shadow.file' is set to "
"overwrite your completed tasks. Please change it.");
*/
std::string oldCurses = config.get ("curses"); std::string oldCurses = config.get ("curses");
std::string oldColor = config.get ("color"); std::string oldColor = config.get ("color");
config.set ("curses", "off"); config.set ("curses", "off");

View file

@ -54,7 +54,6 @@ extern Context context;
// via the .taskrc file. // via the .taskrc file.
std::string handleCustomReport (const std::string& report) std::string handleCustomReport (const std::string& report)
{ {
/*
// Load report configuration. // Load report configuration.
std::string columnList = context.config.get ("report." + report + ".columns"); std::string columnList = context.config.get ("report." + report + ".columns");
std::vector <std::string> columns; std::vector <std::string> columns;
@ -67,7 +66,7 @@ std::string handleCustomReport (const std::string& report)
if (columns.size () != labels.size () && labels.size () != 0) if (columns.size () != labels.size () && labels.size () != 0)
throw std::string ("There are a different number of columns than labels ") + throw std::string ("There are a different number of columns than labels ") +
"for report '" + report + "'. Please correct this."; "for report '" + report + "'.";
std::map <std::string, std::string> columnLabels; std::map <std::string, std::string> columnLabels;
if (labels.size ()) if (labels.size ())
@ -83,6 +82,14 @@ std::string handleCustomReport (const std::string& report)
std::vector <std::string> filterArgs; std::vector <std::string> filterArgs;
split (filterArgs, filterList, ' '); split (filterArgs, filterList, ' ');
// Get all the tasks.
std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true));
// TODO Include filter from custom report.
context.tdb.load (tasks, context.filter);
context.tdb.unlock ();
/*
// Load all pending tasks. // Load all pending tasks.
std::vector <T> tasks; std::vector <T> tasks;
tdb.allPendingT (tasks); tdb.allPendingT (tasks);

View file

@ -24,44 +24,14 @@
// USA // USA
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <iostream> #include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <pwd.h>
#include <time.h>
#include "Context.h" #include "Context.h"
#include "Date.h"
#include "Duration.h"
#include "Table.h"
#include "T.h"
#include "text.h"
#include "util.h"
#include "main.h"
#ifdef HAVE_LIBNCURSES
#include <ncurses.h>
#endif
// Global context for use by all.
Context context; Context context;
////////////////////////////////////////////////////////////////////////////////
int main (int argc, char** argv) int main (int argc, char** argv)
{ {
// Set up randomness.
#ifdef HAVE_SRANDOM
srandom (time (NULL));
#else
srand (time (NULL));
#endif
int status = 0; int status = 0;
try try
@ -71,33 +41,6 @@ int main (int argc, char** argv)
status = context.interactive (); status = context.interactive ();
else else
status = context.run (); status = context.run ();
// start OBSOLETE
/*
TDB tdb;
std::string dataLocation = expandPath (context.config.get ("data.location"));
tdb.dataDirectory (dataLocation);
// Allow user override of file locking. Solaris/NFS machines may want this.
if (! context.config.get ("locking", true))
tdb.noLock ();
// Check for silly shadow file settings.
std::string shadowFile = expandPath (context.config.get ("shadow.file"));
if (shadowFile != "")
{
if (shadowFile == dataLocation + "/pending.data")
throw std::string ("Configuration variable 'shadow.file' is set to "
"overwrite your pending tasks. Please change it.");
if (shadowFile == dataLocation + "/completed.data")
throw std::string ("Configuration variable 'shadow.file' is set to "
"overwrite your completed tasks. Please change it.");
}
std::cout << runTaskCommand (context.args, tdb);
*/
// end OBSOLETE
} }
catch (std::string& error) catch (std::string& error)
@ -116,45 +59,3 @@ int main (int argc, char** argv)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// TODO Obsolete
void updateShadowFile ()
{
}
////////////////////////////////////////////////////////////////////////////////
// TODO Obsolete
std::string runTaskCommand (
int argc,
char** argv,
// TDB& tdb,
bool gc /* = true */,
bool shadow /* = true */)
{
/*
std::vector <std::string> args;
for (int i = 1; i < argc; ++i)
if (strncmp (argv[i], "rc:", 3) &&
strncmp (argv[i], "rc.", 3))
{
std::cout << "arg=" << argv[i] << std::endl;
args.push_back (argv[i]);
}
return runTaskCommand (args, tdb, gc, shadow);
*/
return "";
}
////////////////////////////////////////////////////////////////////////////////
// TODO Obsolete
std::string runTaskCommand (
std::vector <std::string>& args,
// TDB& tdb,
bool gc /* = false */,
bool shadow /* = false */)
{
std::string out;
return out;
}
////////////////////////////////////////////////////////////////////////////////