From b10ff955a370b7fd2add5c5493f1987b5d7b6600 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 15 Aug 2004 02:39:13 -0400 Subject: cleaned up binary data writing, and file handling --- ledger.cc | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'ledger.cc') diff --git a/ledger.cc b/ledger.cc index 19be9d62..3a58fce5 100644 --- a/ledger.cc +++ b/ledger.cc @@ -177,30 +177,23 @@ entry_t * journal_t::derive_entry(strings_list::iterator i, return added; } -int parse_journal_file(char * p, journal_t * journal) +int parse_journal_file(const std::string& path, journal_t * journal) { - char * sep = std::strrchr(p, '='); - if (sep) *sep++ = '\0'; + journal->sources.push_back(path); - std::ifstream stream(p); + if (access(path.c_str(), R_OK) == -1) + return 0; - account_t * master; - if (sep) - master = journal->find_account(sep); - else - master = journal->master; - - journal->sources.push_back(p); + std::ifstream stream(path.c_str()); unsigned long magic; - std::istream::pos_type start = stream.tellg(); stream.read((char *)&magic, sizeof(magic)); - stream.seekg(start); + stream.seekg(0); if (magic == binary_magic_number) - return read_binary_journal(stream, "", journal, master); + return read_binary_journal(stream, journal, journal->master); else - return parse_textual_journal(stream, journal, master); + return parse_textual_journal(stream, journal, journal->master); } } // namespace ledger -- cgit v1.2.3