summaryrefslogtreecommitdiff
path: root/parser.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-01-21 18:29:20 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-01-21 18:29:20 -0400
commitebae0257fbb3cc420cdde80236ae63f6a1ab612e (patch)
treeb6be932c11ae58206efa923b436fd361688326a6 /parser.cc
parent8abf8baa534b31c18a4475ed4922a3d58462ad5a (diff)
downloadfork-ledger-ebae0257fbb3cc420cdde80236ae63f6a1ab612e.tar.gz
fork-ledger-ebae0257fbb3cc420cdde80236ae63f6a1ab612e.tar.bz2
fork-ledger-ebae0257fbb3cc420cdde80236ae63f6a1ab612e.zip
Resolve outstanding stdin parsing issues by buffering the data.
Diffstat (limited to 'parser.cc')
-rw-r--r--parser.cc25
1 files changed, 15 insertions, 10 deletions
diff --git a/parser.cc b/parser.cc
index 9c660f8f..5c54d6f2 100644
--- a/parser.cc
+++ b/parser.cc
@@ -166,16 +166,21 @@ unsigned int parse_ledger_data(config_t& config,
"rejected cache, parsing " << config.data_file);
if (config.data_file == "-") {
config.use_cache = false;
- journal->sources.push_back("<stdin>");
-#if 0
- // jww (2006-03-23): Why doesn't XML work on stdin?
- if (xml_parser && std::cin.peek() == '<')
- entry_count += xml_parser->parse(std::cin, config, journal,
- acct);
- else if (stdin_parser)
-#endif
- entry_count += stdin_parser->parse(std::cin, config,
- journal, acct);
+ journal->sources.push_back("/dev/stdin");
+
+ std::ostringstream buffer;
+
+ while (std::cin.good() && ! std::cin.eof()) {
+ static char line[8192];
+ std::cin.read(line, 8192);
+ std::streamsize count = std::cin.gcount();
+ buffer.write(line, count);
+ }
+ buffer.flush();
+
+ std::istringstream buf_in(buffer.str());
+
+ entry_count += parse_journal(buf_in, config, journal, acct);
}
else if (access(config.data_file.c_str(), R_OK) != -1) {
entry_count += parse_journal_file(config.data_file, config,