summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/ledger.15
-rw-r--r--src/item.cc46
-rw-r--r--src/item.h5
-rw-r--r--src/output.cc35
-rw-r--r--src/output.h4
-rw-r--r--src/report.cc4
6 files changed, 67 insertions, 32 deletions
diff --git a/doc/ledger.1 b/doc/ledger.1
index 28d14873..4cd11c14 100644
--- a/doc/ledger.1
+++ b/doc/ledger.1
@@ -172,6 +172,11 @@ See \fB\-\-leeway\fR.
.It Fl \-print-format Ar FMT
.It Fl \-quantity Pq Fl O
.It Fl \-quarterly
+.It Fl \-raw
+For use only with the
+.Nm print
+command, it causes Ledger to print out matching entries exactly as they
+appeared in the original journal file.
.It Fl \-real Pq Fl R
.It Fl \-register-format Ar FMT
.It Fl \-related Pq Fl r
diff --git a/src/item.cc b/src/item.cc
index 7621290a..27fc6ef3 100644
--- a/src/item.cc
+++ b/src/item.cc
@@ -359,6 +359,32 @@ bool item_t::valid() const
return true;
}
+void print_item(std::ostream& out,
+ const item_t& item,
+ const string& prefix)
+{
+ std::size_t len = item.end_pos - item.beg_pos;
+
+ ifstream in(item.pathname);
+ in.seekg(item.beg_pos, std::ios::beg);
+
+ scoped_array<char> buf(new char[len + 1]);
+ in.read(buf.get(), len);
+ assert(static_cast<std::size_t>(in.gcount()) == len);
+ buf[len] = '\0';
+
+ bool first = true;
+ for (char * p = std::strtok(buf.get(), "\n");
+ p;
+ p = std::strtok(NULL, "\n")) {
+ if (first)
+ first = false;
+ else
+ out << '\n';
+ out << prefix << p;
+ }
+}
+
string item_context(const item_t& item, const string& desc)
{
std::size_t len = item.end_pos - item.beg_pos;
@@ -375,14 +401,6 @@ string item_context(const item_t& item, const string& desc)
return out.str();
}
- ifstream in(item.pathname);
- in.seekg(item.beg_pos, std::ios::beg);
-
- scoped_array<char> buf(new char[len + 1]);
- in.read(buf.get(), len);
- assert(static_cast<std::size_t>(in.gcount()) == len);
- buf[len] = '\0';
-
out << desc << " from \"" << item.pathname.string() << "\"";
if (item.beg_line != item.end_line)
@@ -391,16 +409,8 @@ string item_context(const item_t& item, const string& desc)
else
out << ", line " << item.beg_line << ":\n";
- bool first = true;
- for (char * p = std::strtok(buf.get(), "\n");
- p;
- p = std::strtok(NULL, "\n")) {
- if (first)
- first = false;
- else
- out << '\n';
- out << "> " << p;
- }
+ print_item(out, item, "> ");
+
return out.str();
}
diff --git a/src/item.h b/src/item.h
index 96e0899b..94bb7e10 100644
--- a/src/item.h
+++ b/src/item.h
@@ -159,8 +159,9 @@ public:
};
value_t get_comment(item_t& item);
-
-string item_context(const item_t& item, const string& desc);
+void print_item(std::ostream& out, const item_t& item,
+ const string& prefix = "");
+string item_context(const item_t& item, const string& desc);
} // namespace ledger
diff --git a/src/output.cc b/src/output.cc
index d1214c33..fd27e2bb 100644
--- a/src/output.cc
+++ b/src/output.cc
@@ -33,8 +33,11 @@
namespace ledger {
-format_xacts::format_xacts(report_t& _report, const string& format)
- : report(_report), last_entry(NULL), last_xact(NULL)
+format_xacts::format_xacts(report_t& _report,
+ const string& format,
+ bool _print_raw)
+ : report(_report), last_entry(NULL), last_xact(NULL),
+ print_raw(_print_raw)
{
TRACE_CTOR(format_xacts, "report&, const string&");
@@ -59,23 +62,37 @@ void format_xacts::operator()(xact_t& xact)
{
std::ostream& out(report.output_stream);
- if (! xact.has_xdata() ||
- ! xact.xdata().has_flags(XACT_EXT_DISPLAYED)) {
+ if (print_raw) {
+ if (! xact.has_xdata() ||
+ ! xact.xdata().has_flags(XACT_EXT_DISPLAYED)) {
+ if (last_entry != xact.entry) {
+ if (last_entry) {
+ bind_scope_t entry_scope(report, *last_entry);
+ between_format.format(out, entry_scope);
+ }
+ print_item(out, *xact.entry);
+ out << '\n';
+ last_entry = xact.entry;
+ }
+ xact.xdata().add_flags(XACT_EXT_DISPLAYED);
+ last_xact = &xact;
+ }
+ }
+ else if (! xact.has_xdata() ||
+ ! xact.xdata().has_flags(XACT_EXT_DISPLAYED)) {
+ bind_scope_t bound_scope(report, xact);
if (last_entry != xact.entry) {
if (last_entry) {
- bind_scope_t bound_scope(report, *last_entry);
- between_format.format(out, bound_scope);
+ bind_scope_t entry_scope(report, *last_entry);
+ between_format.format(out, entry_scope);
}
- bind_scope_t bound_scope(report, xact);
first_line_format.format(out, bound_scope);
last_entry = xact.entry;
}
else if (last_xact && last_xact->date() != xact.date()) {
- bind_scope_t bound_scope(report, xact);
first_line_format.format(out, bound_scope);
}
else {
- bind_scope_t bound_scope(report, xact);
next_lines_format.format(out, bound_scope);
}
diff --git a/src/output.h b/src/output.h
index 6eaef081..fe007d42 100644
--- a/src/output.h
+++ b/src/output.h
@@ -65,9 +65,11 @@ protected:
format_t between_format;
entry_t * last_entry;
xact_t * last_xact;
+ bool print_raw;
public:
- format_xacts(report_t& _report, const string& format);
+ format_xacts(report_t& _report, const string& format,
+ bool _print_raw = false);
virtual ~format_xacts() {
TRACE_DTOR(format_xacts);
}
diff --git a/src/report.cc b/src/report.cc
index 95e5fa93..3112a98e 100644
--- a/src/report.cc
+++ b/src/report.cc
@@ -530,8 +530,8 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
if (*(q + 1) == '\0' || is_eq(q, "print"))
return WRAP_FUNCTOR
(reporter<>
- (new format_xacts(*this, report_format(HANDLER(print_format_))),
- *this));
+ (new format_xacts(*this, report_format(HANDLER(print_format_)),
+ HANDLED(raw)), *this));
else if (is_eq(q, "prices"))
return expr_t::op_t::wrap_functor
(reporter<xact_t, xact_handler_ptr, &report_t::commodities_report>