summaryrefslogtreecommitdiff
path: root/parser.cc
blob: 6a97caa2afcdc3c937032f0266d990cc6570264c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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