summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/emacs.cc10
-rw-r--r--src/entry.cc5
-rw-r--r--src/entry.h4
-rw-r--r--src/item.cc62
-rw-r--r--src/item.h18
-rw-r--r--src/textual.cc7
-rw-r--r--src/textual.h1
7 files changed, 44 insertions, 63 deletions
diff --git a/src/emacs.cc b/src/emacs.cc
index b63375b2..714302c5 100644
--- a/src/emacs.cc
+++ b/src/emacs.cc
@@ -36,14 +36,8 @@ namespace ledger {
void format_emacs_xacts::write_entry(entry_t& entry)
{
- int idx = entry.src_idx;
- foreach (const path& path, entry.journal->sources)
- if (! idx--) {
- out << "\"" << path << "\" ";
- break;
- }
-
- out << (static_cast<std::size_t>(entry.beg_line) + 1) << " ";
+ out << "\"" << entry.pathname << "\" "
+ << (static_cast<std::size_t>(entry.beg_line) + 1) << " ";
tm when = gregorian::to_tm(*entry.date());
std::time_t date = std::mktime(&when); // jww (2008-04-20): Is this GMT or local?
diff --git a/src/entry.cc b/src/entry.cc
index 4f5c5d6f..27968614 100644
--- a/src/entry.cc
+++ b/src/entry.cc
@@ -37,7 +37,8 @@
namespace ledger {
-entry_base_t::entry_base_t(const entry_base_t& e) : item_t()
+entry_base_t::entry_base_t(const entry_base_t& e)
+ : item_t(), journal(NULL)
{
TRACE_CTOR(entry_base_t, "copy");
#if 0
@@ -79,14 +80,12 @@ item_t::state_t entry_base_t::state() const
void entry_base_t::add_xact(xact_t * xact)
{
xacts.push_back(xact);
- xact->journal = journal;
}
bool entry_base_t::remove_xact(xact_t * xact)
{
xacts.remove(xact);
xact->entry = NULL;
- xact->journal = NULL;
return true;
}
diff --git a/src/entry.h b/src/entry.h
index 5dab48f7..37456199 100644
--- a/src/entry.h
+++ b/src/entry.h
@@ -61,9 +61,11 @@ class journal_t;
class entry_base_t : public item_t
{
public:
+ journal_t * journal;
+
xacts_list xacts;
- entry_base_t() {
+ entry_base_t() : item_t(), journal(NULL) {
TRACE_CTOR(entry_base_t, "");
}
entry_base_t(const entry_base_t& e);
diff --git a/src/item.cc b/src/item.cc
index 175797ff..02983ba1 100644
--- a/src/item.cc
+++ b/src/item.cc
@@ -310,44 +310,38 @@ bool item_t::valid() const
string item_context(const item_t& item)
{
- unsigned short x = 0;
- foreach (const path& path, item.journal->sources) {
- if (x++ == item.src_idx) {
- std::size_t len = item.end_pos - item.beg_pos;
- assert(len > 0);
- assert(len < 2048);
- ifstream in(path);
- in.seekg(item.beg_pos, std::ios::beg);
+ std::size_t len = item.end_pos - item.beg_pos;
+ assert(len > 0);
+ assert(len < 2048);
+
+ 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);
+ scoped_array<char> buf(new char[len + 1]);
+ in.read(buf.get(), len);
- std::ostringstream out;
+ std::ostringstream out;
- out << "While balancing item from \"" << path.string()
- << "\"";
-
- if (item.beg_line != (item.end_line - 1))
- out << ", lines " << item.beg_line << "-"
- << (item.end_line - 1) << ":\n";
- 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;
- }
- return out.str();
- }
+ out << "While balancing item from \"" << item.pathname.string()
+ << "\"";
+
+ if (item.beg_line != (item.end_line - 1))
+ out << ", lines " << item.beg_line << "-"
+ << (item.end_line - 1) << ":\n";
+ 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;
}
- assert(false);
- return empty_string;
+ return out.str();
}
} // namespace ledger
diff --git a/src/item.h b/src/item.h
index 1136ac2b..13a315d2 100644
--- a/src/item.h
+++ b/src/item.h
@@ -51,8 +51,6 @@
namespace ledger {
-class journal_t;
-
/**
* @brief Brief
*
@@ -62,9 +60,9 @@ class item_t : public supports_flags<>, public scope_t
{
public:
#define ITEM_NORMAL 0x00 // no flags at all, a basic transaction
-#define ITEM_IN_CACHE 0x01 // transaction allocated by the binary cache
-#define ITEM_GENERATED 0x02 // transaction was not found in a journal
-#define ITEM_TEMP 0x04 // transaction is a temporary object
+#define ITEM_IN_CACHE 0x01 // transaction allocated by the binary cache
+#define ITEM_GENERATED 0x02 // transaction was not found in a journal
+#define ITEM_TEMP 0x04 // transaction is a temporary object
enum state_t { UNCLEARED = 0, CLEARED, PENDING };
@@ -77,9 +75,7 @@ public:
typedef std::map<string, optional<string> > string_map;
optional<string_map> metadata;
- journal_t * journal;
-
- unsigned short src_idx;
+ path pathname;
istream_pos_type beg_pos;
std::size_t beg_line;
istream_pos_type end_pos;
@@ -88,8 +84,7 @@ public:
static bool use_effective_date;
item_t(flags_t _flags = ITEM_NORMAL, const optional<string>& _note = none)
- : supports_flags<>(_flags),
- _state(UNCLEARED), note(_note), journal(NULL), src_idx(0),
+ : supports_flags<>(_flags), _state(UNCLEARED), note(_note),
beg_pos(0), beg_line(0), end_pos(0), end_line(0)
{
TRACE_CTOR(item_t, "flags_t, const string&");
@@ -113,8 +108,7 @@ public:
note = item.note;
- journal = item.journal;
- src_idx = item.src_idx;
+ pathname = item.pathname;
beg_pos = item.beg_pos;
beg_line = item.beg_line;
end_pos = item.end_pos;
diff --git a/src/textual.cc b/src/textual.cc
index 018806f7..620085b0 100644
--- a/src/textual.cc
+++ b/src/textual.cc
@@ -155,7 +155,6 @@ textual_parser_t::instance_t::instance_t
account_stack.push_front(master);
pathname = journal.sources.back();
- src_idx = journal.sources.size() - 1;
linenum = 1;
beg_pos = in.tellg();
beg_line = linenum;
@@ -472,7 +471,7 @@ void textual_parser_t::instance_t::automated_entry_directive(char * line)
if (parse_xacts(in, account_stack.front(), *ae, "automated",
end_pos)) {
journal.auto_entries.push_back(ae);
- ae->src_idx = src_idx;
+ ae->pathname = pathname;
ae->beg_pos = beg_pos;
ae->beg_line = beg_line;
ae->end_pos = end_pos;
@@ -491,7 +490,7 @@ void textual_parser_t::instance_t::period_entry_directive(char * line)
if (pe->finalize()) {
extend_entry_base(&journal, *pe, true);
journal.period_entries.push_back(pe);
- pe->src_idx = src_idx;
+ pe->pathname = pathname;
pe->beg_pos = beg_pos;
pe->beg_line = beg_line;
pe->end_pos = end_pos;
@@ -514,7 +513,7 @@ void textual_parser_t::instance_t::entry_directive(char * line)
// would cause us to leak without this guard.
std::auto_ptr<entry_t> entry_ptr(entry);
- entry->src_idx = src_idx;
+ entry->pathname = pathname;
entry->beg_pos = beg_pos;
entry->beg_line = beg_line;
entry->end_pos = pos;
diff --git a/src/textual.h b/src/textual.h
index 2ca5967d..244041fb 100644
--- a/src/textual.h
+++ b/src/textual.h
@@ -94,7 +94,6 @@ protected:
path pathname;
std::size_t linenum;
- std::size_t src_idx;
istream_pos_type beg_pos;
std::size_t beg_line;
istream_pos_type end_pos;