From e4c7b1753bf5c0fb5f1dd89efeee733fb7b5be23 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Wed, 21 Jan 2009 18:30:37 -0400 Subject: [PATCH] Resolve outstanding stdin parsing issues by buffering the data. --- lib/cppunit | 2 +- lib/libofx | 2 +- src/session.cc | 18 +++++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/cppunit b/lib/cppunit index 1f41e59a..fccfbd74 160000 --- a/lib/cppunit +++ b/lib/cppunit @@ -1 +1 @@ -Subproject commit 1f41e59a4dae47720d0aacb422548b45be0daa19 +Subproject commit fccfbd741a0fd974945bb259854768cc70258f07 diff --git a/lib/libofx b/lib/libofx index 699016bf..31ab2c05 160000 --- a/lib/libofx +++ b/lib/libofx @@ -1 +1 @@ -Subproject commit 699016bfd00e2be7f13120f314a4f976eeacadd6 +Subproject commit 31ab2c052edb3e72fc1fda385d6d118c479407f3 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);