summaryrefslogtreecommitdiff
path: root/src/textual.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/textual.cc')
-rw-r--r--src/textual.cc26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/textual.cc b/src/textual.cc
index 4549581b..456ff8af 100644
--- a/src/textual.cc
+++ b/src/textual.cc
@@ -721,15 +721,12 @@ void instance_t::include_directive(char * line)
if (line[0] != '/' && line[0] != '\\' && line[0] != '~') {
DEBUG("textual.include", "received a relative path");
DEBUG("textual.include", "parent file path: " << context.pathname);
- string pathstr(context.pathname.string());
- string::size_type pos = pathstr.rfind('/');
- if (pos == string::npos)
- pos = pathstr.rfind('\\');
- if (pos != string::npos) {
- filename = path(string(pathstr, 0, pos + 1)) / line;
- DEBUG("textual.include", "normalized path: " << filename.string());
- } else {
+ path parent_path = context.pathname.parent_path();
+ if (parent_path.empty()) {
filename = path(string(".")) / line;
+ } else {
+ filename = parent_path / line;
+ DEBUG("textual.include", "normalized path: " << filename.string());
}
} else {
filename = line;
@@ -1658,7 +1655,8 @@ post_t * instance_t::parse_post(char * line,
switch (account_total.type()) {
case value_t::AMOUNT:
- diff -= account_total.as_amount();
+ if (account_total.as_amount().commodity_ptr() == diff.commodity_ptr())
+ diff -= account_total.as_amount();
break;
case value_t::BALANCE:
@@ -1676,6 +1674,16 @@ post_t * instance_t::parse_post(char * line,
DEBUG("textual.parse", "line " << context.linenum << ": "
<< "POST assign: diff = " << diff);
+ // Subtract amounts from previous posts to this account in the xact.
+ for (post_t* p : xact->posts) {
+ if (p->account == post->account &&
+ p->amount.commodity_ptr() == diff.commodity_ptr()) {
+ diff -= p->amount;
+ DEBUG("textual.parse", "line " << context.linenum << ": "
+ << "Subtract " << p->amount << ", diff = " << diff);
+ }
+ }
+
if (post->amount.is_null()) {
// balance assignment
if (! diff.is_zero()) {