Enhancement - Path integration

- Obsoleted util.cpp spit, slurp calls
This commit is contained in:
Paul Beckingham 2010-01-16 17:45:45 -05:00
parent a8f03679ed
commit abffaa184b
8 changed files with 19 additions and 110 deletions

View file

@ -36,6 +36,7 @@
#include "util.h"
#include "TDB.h"
#include "Directory.h"
#include "File.h"
#include "Table.h"
#include "Timer.h"
#include "Color.h"
@ -513,7 +514,7 @@ void TDB::undo ()
// load undo.data
std::vector <std::string> u;
slurp (undoFile, u);
File::read (undoFile, u);
if (u.size () < 3)
throw std::string ("There are no recorded transactions to undo.");
@ -645,7 +646,7 @@ void TDB::undo ()
// load pending.data
std::vector <std::string> p;
slurp (pendingFile, p);
File::read (pendingFile, p);
// is 'current' in pending?
foreach (task, p)
@ -667,15 +668,15 @@ void TDB::undo ()
}
// Rewrite files.
spit (pendingFile, p);
spit (undoFile, u);
File::write (pendingFile, p);
File::write (undoFile, u);
return;
}
}
// load completed.data
std::vector <std::string> c;
slurp (completedFile, c);
File::read (completedFile, c);
// is 'current' in completed?
foreach (task, c)
@ -691,17 +692,17 @@ void TDB::undo ()
{
c.erase (task);
p.push_back (prior);
spit (completedFile, c);
spit (pendingFile, p);
spit (undoFile, u);
File::write (completedFile, c);
File::write (pendingFile, p);
File::write (undoFile, u);
std::cout << "Modified task reverted." << std::endl;
context.debug ("TDB::undo - task belongs in pending.data");
}
else
{
*task = prior;
spit (completedFile, c);
spit (undoFile, u);
File::write (completedFile, c);
File::write (undoFile, u);
std::cout << "Modified task reverted." << std::endl;
context.debug ("TDB::undo - task belongs in completed.data");
}

View file

@ -533,7 +533,7 @@ void editFile (Task& task)
// Format the contents, T -> text, write to a file.
std::string before = formatTask (task);
spit (file.str (), before);
File::write (file.str (), before);
// Determine correct editor: .taskrc:editor > $VISUAL > $EDITOR > vi
std::string editor = context.config.get ("editor");
@ -557,7 +557,7 @@ ARE_THESE_REALLY_HARMFUL:
// Slurp file.
std::string after;
slurp (file.str (), after, false);
File::read (file.str (), after);
// Update task based on what can be parsed back out of the file, but only
// if changes were made.
@ -584,7 +584,7 @@ ARE_THESE_REALLY_HARMFUL:
// Preserve the edits.
before = after;
spit (file.str (), before);
File::write (file.str (), before);
if (confirm ("Task couldn't handle your edits. Would you like to try again?"))
goto ARE_THESE_REALLY_HARMFUL;

View file

@ -28,6 +28,7 @@
#include <sstream>
#include <stdio.h>
#include <unistd.h>
#include "File.h"
#include "Date.h"
#include "text.h"
#include "util.h"
@ -1155,7 +1156,7 @@ int handleImport (std::string &outs)
{
// Load the file.
std::vector <std::string> all;
slurp (file, all, true);
File::read (file, all);
std::vector <std::string> lines;
std::vector <std::string>::iterator it;

View file

@ -1728,7 +1728,7 @@ int handleReportStats (std::string &outs)
dataSize += undo.size ();
std::vector <std::string> undoTxns;
slurp (undo, undoTxns, false);
File::read (undo, undoTxns);
int undoCount = 0;
foreach (tx, undoTxns)
if (tx->substr (0, 3) == "---")

View file

@ -27,6 +27,7 @@
#include <unistd.h>
#include <Context.h>
#include <StringTable.h>
#include <File.h>
#include <util.h>
#include <test.h>
@ -39,7 +40,7 @@ int main (int argc, char** argv)
// Create a string file.
std::string file = "./strings.xx-XX";
spit (file, "# comment\n1 found");
File::write (file, "# comment\n1 found");
t.is (access (file.c_str (), F_OK), 0, "strings.xx-XX created.");
// Load the string file.

View file

@ -514,10 +514,6 @@ int main (int argc, char** argv)
// TODO const std::string uuid ();
// TODO bool slurp (const std::string&, std::vector <std::string>&, bool trimLines = false);
// TODO bool slurp (const std::string&, std::string&, bool trimLines = false);
// TODO void spit (const std::string&, const std::string&);
// std::string taskDiff (const Task&, const Task&);
Task left;
left.set ("zero", "0");

View file

@ -375,92 +375,6 @@ int flock (int fd, int operation)
}
#endif
////////////////////////////////////////////////////////////////////////////////
bool slurp (
const std::string& file,
std::vector <std::string>& contents,
bool trimLines /* = false */)
{
contents.clear ();
std::ifstream in (file.c_str ());
if (in.good ())
{
std::string line;
while (getline (in, line))
{
if (trimLines) line = trim (line);
contents.push_back (line);
}
in.close ();
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
bool slurp (
const std::string& file,
std::string& contents,
bool trimLines /* = false */)
{
contents = "";
std::ifstream in (file.c_str ());
if (in.good ())
{
std::string line;
while (getline (in, line))
{
if (trimLines) line = trim (line);
contents += line + "\n";
}
in.close ();
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
void spit (const std::string& file, const std::string& contents)
{
std::ofstream out (file.c_str ());
if (out.good ())
{
out << contents;
out.close ();
}
else
throw std::string ("Could not write file '") + file + "'"; // TODO i18n
}
////////////////////////////////////////////////////////////////////////////////
void spit (
const std::string& file,
const std::vector <std::string>& lines,
bool addNewlines /* = true */)
{
std::ofstream out (file.c_str ());
if (out.good ())
{
foreach (line, lines)
{
out << *line;
if (addNewlines)
out << "\n";
}
out.close ();
}
else
throw std::string ("Could not write file '") + file + "'"; // TODO i18n
}
////////////////////////////////////////////////////////////////////////////////
bool taskDiff (const Task& before, const Task& after)
{

View file

@ -70,10 +70,6 @@ const std::string uuid ();
int flock (int, int);
#endif
bool slurp (const std::string&, std::vector <std::string>&, bool trimLines = false);
bool slurp (const std::string&, std::string&, bool trimLines = false);
void spit (const std::string&, const std::string&);
void spit (const std::string&, const std::vector <std::string>&, bool addNewlines = true);
bool taskDiff (const Task&, const Task&);
std::string taskDifferences (const Task&, const Task&);
std::string renderAttribute (const std::string&, const std::string&);