Enhancements - shadow file

- Implemented (bug not debugged) the shadow file update.
- Added oddly missing (and bypassed) Context::message and Context::footnote
  methods.
This commit is contained in:
Paul Beckingham 2009-06-11 01:30:14 -04:00
parent a58aa948b8
commit ed2ed7c2e2
2 changed files with 53 additions and 55 deletions

View file

@ -26,6 +26,7 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <iostream> #include <iostream>
#include <fstream>
#include <pwd.h> #include <pwd.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -114,18 +115,17 @@ int Context::run ()
try try
{ {
parse (); // Parse command line. parse (); // Parse command line.
dispatch (); // Dispatch to command handlers. std::cout << dispatch (); // Dispatch to command handlers.
shadow (); // Auto shadow update.
} }
catch (const std::string& error) catch (const std::string& error)
{ {
messages.push_back (error); message (error);
} }
catch (...) catch (...)
{ {
messages.push_back (stringtable.get (100, "Unknown error.")); message (stringtable.get (100, "Unknown error."));
} }
// Dump all messages. // Dump all messages.
@ -143,7 +143,7 @@ int Context::run ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Context::dispatch () std::string Context::dispatch ()
{ {
bool gcMod = false; // Change occurred by way of gc. bool gcMod = false; // Change occurred by way of gc.
bool cmdMod = false; // Change occurred by way of command type. bool cmdMod = false; // Change occurred by way of command type.
@ -199,33 +199,32 @@ void Context::dispatch ()
// Only update the shadow file if such an update was not suppressed (shadow), // Only update the shadow file if such an update was not suppressed (shadow),
// and if an actual change occurred (gcMod || cmdMod). // and if an actual change occurred (gcMod || cmdMod).
// if (shadow && (gcMod || cmdMod)) // if (shadow && (gcMod || cmdMod))
// updateShadowFile (tdb); // shadow ();
std::cout << out; return out;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Context::shadow () void Context::shadow ()
{ {
/*
try
{
// Determine if shadow file is enabled. // Determine if shadow file is enabled.
std::string shadowFile = expandPath (context.config.get ("shadow.file")); std::string shadowFile = expandPath (config.get ("shadow.file"));
if (shadowFile != "") if (shadowFile != "")
{ {
std::string oldCurses = context.config.get ("curses"); std::string oldCurses = config.get ("curses");
std::string oldColor = context.config.get ("color"); std::string oldColor = config.get ("color");
context.config.set ("curses", "off"); config.set ("curses", "off");
context.config.set ("color", "off"); config.set ("color", "off");
// Run report. Use shadow.command, using default.command as a fallback // Run report. Use shadow.command, using default.command as a fallback
// with "list" as a default. // with "list" as a default.
std::string command = context.config.get ("shadow.command", std::string command = config.get ("shadow.command",
context.config.get ("default.command", "list")); config.get ("default.command", "list"));
std::vector <std::string> args;
split (args, command, ' '); split (args, command, ' ');
std::string result = runTaskCommand (args, tdb);
initialize ();
parse ();
std::string result = dispatch ();
std::ofstream out (shadowFile.c_str ()); std::ofstream out (shadowFile.c_str ());
if (out.good ()) if (out.good ())
@ -236,26 +235,13 @@ void Context::shadow ()
else else
throw std::string ("Could not write file '") + shadowFile + "'"; throw std::string ("Could not write file '") + shadowFile + "'";
context.config.set ("curses", oldCurses); config.set ("curses", oldCurses);
context.config.set ("color", oldColor); config.set ("color", oldColor);
}
// Optionally display a notification that the shadow file was updated. // Optionally display a notification that the shadow file was updated.
if (context.config.get (std::string ("shadow.notify"), false)) if (config.get (std::string ("shadow.notify"), false))
std::cout << "[Shadow file '" << shadowFile << "' updated]" << std::endl; footnote (std::string ("[Shadow file '") + shadowFile + "' updated]");
} }
catch (std::string& error)
{
std::cerr << error << std::endl;
}
catch (...)
{
std::cerr << "Unknown error." << std::endl;
}
*/
throw std::string ("unimplemented Context::shadow");
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -269,7 +255,7 @@ void Context::loadCorrectConfigFile ()
if (access (file.c_str (), F_OK)) if (access (file.c_str (), F_OK))
throw std::string ("Could not read configuration file '") + file + "'"; throw std::string ("Could not read configuration file '") + file + "'";
messages.push_back (std::string ("Using alternate .taskrc file ") + file); // TODO i18n message (std::string ("Using alternate .taskrc file ") + file); // TODO i18n
config.load (file); config.load (file);
// No need to handle it again. // No need to handle it again.
@ -301,7 +287,7 @@ void Context::loadCorrectConfigFile ()
n.getUntilEOS (value)) n.getUntilEOS (value))
{ {
config.set (name, value); config.set (name, value);
messages.push_back (std::string ("Configuration override ") + // TODO i18n message (std::string ("Configuration override ") + // TODO i18n
arg->substr (3, std::string::npos)); arg->substr (3, std::string::npos));
} }
@ -461,3 +447,15 @@ void Context::constructFilter ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Context::message (const std::string& input)
{
messages.push_back (input);
}
////////////////////////////////////////////////////////////////////////////////
void Context::footnote (const std::string& input)
{
footnotes.push_back (input);
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -47,7 +47,7 @@ public:
void initialize (); // for reinitializing void initialize (); // for reinitializing
int run (); // task classic int run (); // task classic
int interactive (); // task interactive (not implemented) int interactive (); // task interactive (not implemented)
void dispatch (); // command handler dispatch std::string dispatch (); // command handler dispatch
void shadow (); // shadow file update void shadow (); // shadow file update
int getWidth (); // determine terminal width int getWidth (); // determine terminal width