using namespace std;
+ AsciiFileReader::AsciiFileReader(FILE* file)
+ : file(file), buffer(NULL), len(0)
+ {
+ if (file == NULL)
+ {
+ y2err("file is NULL");
+ throw exception(); // TODO
+ }
+ }
+
+
AsciiFileReader::AsciiFileReader(const string& filename)
: file(NULL), buffer(NULL), len(0)
{
{
public:
+ AsciiFileReader(FILE* file);
AsciiFileReader(const string& filename);
~AsciiFileReader();
try
{
- AsciiFileReader file(input);
+ AsciiFileReader asciifile(input);
string line;
- while (file.getline(line))
+ while (asciifile.getline(line))
{
- // TODO: more robust splitting
+ string::size_type pos = line.find(" ");
+ if (pos == string::npos)
+ continue;
- string name = string(line, 5);
-
- unsigned int status = stringToStatus(string(line, 0, 4));
+ unsigned int status = stringToStatus(string(line, 0, pos));
+ string name = string(line, pos + 1);
if (invert)
status = invertStatus(status);
{
try
{
- AsciiFileReader file(*it);
+ AsciiFileReader asciifile(*it);
string line;
- while (file.getline(line))
+ while (asciifile.getline(line))
ignore_patterns.push_back(line);
}
catch (...) // TODO
#include <snapper/SnapperTmpl.h>
#include <snapper/Compare.h>
#include <snapper/Enum.h>
+#include <snapper/AsciiFile.h>
#include "utils/Table.h"
#include "utils/GetOpts.h"
if (file)
{
- char* line = NULL;
- size_t len = 0;
+ AsciiFileReader asciifile(file);
- while (getline(&line, &len, file) != -1)
+ string line;
+ while (asciifile.getline(line))
{
- // TODO: more robust splitting, make status optional
+ if (line.empty())
+ continue;
- string name = string(line, 5, strlen(line) - 6);
+ string name = line;
+
+ // strip optional status
+ if (name[0] != '/')
+ {
+ string::size_type pos = name.find(" ");
+ if (pos == string::npos)
+ continue;
+
+ name.erase(0, pos + 1);
+ }
Files::iterator it = files.find(name);
if (it == files.end())
it->setRollback(true);
}
-
- free(line);
-
- fclose(file);
}
else
{