summaryrefslogtreecommitdiff
path: root/src/session.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-01-21 18:30:37 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-01-21 18:30:37 -0400
commite4c7b1753bf5c0fb5f1dd89efeee733fb7b5be23 (patch)
treef387038c56ce95c6bd149c2cc6163085de64e343 /src/session.cc
parente6c44a586faf28a626d6bdc334659b449ddaad39 (diff)
downloadfork-ledger-e4c7b1753bf5c0fb5f1dd89efeee733fb7b5be23.tar.gz
fork-ledger-e4c7b1753bf5c0fb5f1dd89efeee733fb7b5be23.tar.bz2
fork-ledger-e4c7b1753bf5c0fb5f1dd89efeee733fb7b5be23.zip
Resolve outstanding stdin parsing issues by buffering the data.
Diffstat (limited to 'src/session.cc')
-rw-r--r--src/session.cc18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/session.cc b/src/session.cc
index 113aeda0..fa61e08b 100644
--- a/src/session.cc
+++ b/src/session.cc
@@ -216,7 +216,23 @@ std::size_t session_t::read_data(journal_t& journal,
if (data_file == "-") {
use_cache = false;
journal.sources.push_back("/dev/stdin");
- entry_count += read_journal(journal, std::cin, "/dev/stdin", acct);
+
+ // To avoid problems with stdin and pipes, etc., we read the entire
+ // file in beforehand into a memory buffer, and then parcel it out
+ // from there.
+ 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 += read_journal(journal, buf_in, "/dev/stdin", acct);
}
else if (exists(data_file)) {
entry_count += read_journal(journal, data_file, acct);