fixes
This commit is contained in:
parent
a9b207205f
commit
f19aeb6d44
7 changed files with 143 additions and 8 deletions
25
binary.h
Normal file
25
binary.h
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
#ifndef _BINARY_H
|
||||||
|
#define _BINARY_H
|
||||||
|
|
||||||
|
#include "parser.h"
|
||||||
|
|
||||||
|
namespace ledger {
|
||||||
|
|
||||||
|
class binary_parser_t : public parser_t
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual bool test(std::istream& in) const;
|
||||||
|
|
||||||
|
virtual unsigned int parse(std::istream& in,
|
||||||
|
journal_t * journal,
|
||||||
|
account_t * master = NULL,
|
||||||
|
const std::string * original_file = NULL);
|
||||||
|
};
|
||||||
|
|
||||||
|
void write_binary_journal(std::ostream& out,
|
||||||
|
journal_t * journal,
|
||||||
|
strings_list * files = NULL);
|
||||||
|
|
||||||
|
} // namespace ledger
|
||||||
|
|
||||||
|
#endif // _BINARY_H
|
||||||
12
main.cc
12
main.cc
|
|
@ -195,13 +195,13 @@ int main(int argc, char * argv[], char * envp[])
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (! config->init_file.empty())
|
if (! config->init_file.empty())
|
||||||
if (parser_t::parse(config->init_file, journal.get()))
|
if (parser_t::parse_file(config->init_file, journal.get()))
|
||||||
throw error("Entries not allowed in initialization file");
|
throw error("Entries not allowed in initialization file");
|
||||||
|
|
||||||
if (use_cache && ! config->cache_file.empty() &&
|
if (use_cache && ! config->cache_file.empty() &&
|
||||||
! config->data_file.empty()) {
|
! config->data_file.empty()) {
|
||||||
entry_count += parser_t::parse(config->cache_file, journal.get(),
|
entry_count += parser_t::parse_file(config->cache_file, journal.get(),
|
||||||
NULL, &config->data_file);
|
NULL, &config->data_file);
|
||||||
journal->sources.pop_front(); // remove cache_file
|
journal->sources.pop_front(); // remove cache_file
|
||||||
|
|
||||||
if (entry_count == 0) {
|
if (entry_count == 0) {
|
||||||
|
|
@ -221,12 +221,12 @@ int main(int argc, char * argv[], char * envp[])
|
||||||
use_cache = false;
|
use_cache = false;
|
||||||
entry_count += text_parser->parse(std::cin, journal.get(), account);
|
entry_count += text_parser->parse(std::cin, journal.get(), account);
|
||||||
} else {
|
} else {
|
||||||
entry_count += parser_t::parse(config->data_file, journal.get(),
|
entry_count += parser_t::parse_file(config->data_file, journal.get(),
|
||||||
account);
|
account);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! config->price_db.empty())
|
if (! config->price_db.empty())
|
||||||
if (parser_t::parse(config->price_db, journal.get()))
|
if (parser_t::parse_file(config->price_db, journal.get()))
|
||||||
throw error("Entries not allowed in price history file");
|
throw error("Entries not allowed in price history file");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
35
parser.cc
Normal file
35
parser.cc
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
#include "parser.h"
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
namespace ledger {
|
||||||
|
|
||||||
|
parsers_list parser_t::parsers;
|
||||||
|
|
||||||
|
unsigned int parser_t::parse_file(const std::string& path,
|
||||||
|
journal_t * journal,
|
||||||
|
account_t * master,
|
||||||
|
const std::string * original_file)
|
||||||
|
{
|
||||||
|
journal->sources.push_back(path);
|
||||||
|
|
||||||
|
if (access(path.c_str(), R_OK) == -1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
std::ifstream stream(path.c_str());
|
||||||
|
|
||||||
|
if (! master)
|
||||||
|
master = journal->master;
|
||||||
|
if (! original_file)
|
||||||
|
original_file = &path;
|
||||||
|
|
||||||
|
for (parsers_list::iterator i = parser_t::parsers.begin();
|
||||||
|
i != parser_t::parsers.end();
|
||||||
|
i++)
|
||||||
|
if ((*i)->test(stream))
|
||||||
|
return (*i)->parse(stream, journal, master, original_file);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace ledger
|
||||||
31
parser.h
Normal file
31
parser.h
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
#ifndef _PARSER_H
|
||||||
|
#define _PARSER_H
|
||||||
|
|
||||||
|
#include "ledger.h"
|
||||||
|
|
||||||
|
namespace ledger {
|
||||||
|
|
||||||
|
class parser_t;
|
||||||
|
typedef std::list<parser_t *> parsers_list;
|
||||||
|
|
||||||
|
class parser_t
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual bool test(std::istream& in) const = 0;
|
||||||
|
|
||||||
|
virtual unsigned int parse(std::istream& in,
|
||||||
|
journal_t * journal,
|
||||||
|
account_t * master = NULL,
|
||||||
|
const std::string * original_file = NULL) = 0;
|
||||||
|
|
||||||
|
static parsers_list parsers;
|
||||||
|
|
||||||
|
static unsigned int parse_file(const std::string& path,
|
||||||
|
journal_t * journal,
|
||||||
|
account_t * master = NULL,
|
||||||
|
const std::string * original_file = NULL);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace ledger
|
||||||
|
|
||||||
|
#endif // _PARSER_H
|
||||||
21
qif.h
Normal file
21
qif.h
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
#ifndef _QIF_H
|
||||||
|
#define _QIF_H
|
||||||
|
|
||||||
|
#include "parser.h"
|
||||||
|
|
||||||
|
namespace ledger {
|
||||||
|
|
||||||
|
class qif_parser_t : public parser_t
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual bool test(std::istream& in) const;
|
||||||
|
|
||||||
|
virtual unsigned int parse(std::istream& in,
|
||||||
|
journal_t * journal,
|
||||||
|
account_t * master = NULL,
|
||||||
|
const std::string * original_file = NULL);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace ledger
|
||||||
|
|
||||||
|
#endif // _QIF_H
|
||||||
|
|
@ -533,8 +533,8 @@ unsigned int textual_parser_t::parse(std::istream& in,
|
||||||
|
|
||||||
push_var<unsigned int> save_linenum(linenum);
|
push_var<unsigned int> save_linenum(linenum);
|
||||||
push_var<std::string> save_path(path);
|
push_var<std::string> save_path(path);
|
||||||
count += parser_t::parse(skip_ws(line), journal,
|
count += parser_t::parse_file(skip_ws(line), journal,
|
||||||
account_stack.front());
|
account_stack.front());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
||||||
23
textual.h
Normal file
23
textual.h
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
#ifndef _TEXTUAL_H
|
||||||
|
#define _TEXTUAL_H
|
||||||
|
|
||||||
|
#include "parser.h"
|
||||||
|
|
||||||
|
namespace ledger {
|
||||||
|
|
||||||
|
class textual_parser_t : public parser_t
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual bool test(std::istream& in) const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual unsigned int parse(std::istream& in,
|
||||||
|
journal_t * journal,
|
||||||
|
account_t * master = NULL,
|
||||||
|
const std::string * original_file = NULL);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace ledger
|
||||||
|
|
||||||
|
#endif // _TEXTUAL_H
|
||||||
Loading…
Add table
Reference in a new issue