summaryrefslogtreecommitdiff
path: root/src/textual.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/textual.cc')
-rw-r--r--src/textual.cc74
1 files changed, 18 insertions, 56 deletions
diff --git a/src/textual.cc b/src/textual.cc
index 0c92f7bb..35fa0028 100644
--- a/src/textual.cc
+++ b/src/textual.cc
@@ -37,6 +37,7 @@
#include "account.h"
#include "option.h"
#include "pstream.h"
+#include "pool.h"
#define TIMELOG_SUPPORT 1
#if defined(TIMELOG_SUPPORT)
@@ -455,67 +456,18 @@ void instance_t::price_conversion_directive(char * line)
}
}
-namespace {
- void parse_symbol(char *& p, string& symbol)
- {
- if (*p == '"') {
- char * q = std::strchr(p + 1, '"');
- if (! q)
- throw parse_error(_("Quoted commodity symbol lacks closing quote"));
- symbol = string(p + 1, 0, q - p - 1);
- p = q + 2;
- } else {
- char * q = next_element(p);
- symbol = p;
- if (q)
- p = q;
- else
- p += symbol.length();
- }
- if (symbol.empty())
- throw parse_error(_("Failed to parse commodity"));
- }
-}
-
void instance_t::price_xact_directive(char * line)
{
- char * date_field_ptr = skip_ws(line + 1);
- char * time_field_ptr = next_element(date_field_ptr);
- if (! time_field_ptr) return;
- string date_field = date_field_ptr;
-
- char * symbol_and_price;
- datetime_t datetime;
-
- if (std::isdigit(time_field_ptr[0])) {
- symbol_and_price = next_element(time_field_ptr);
- if (! symbol_and_price) return;
- datetime = parse_datetime(date_field + " " + time_field_ptr,
- current_year);
- } else {
- symbol_and_price = time_field_ptr;
- datetime = parse_datetime(date_field, current_year);
- }
-
- string symbol;
- parse_symbol(symbol_and_price, symbol);
- amount_t price(symbol_and_price);
- VERIFY(price.valid());
-
- if (commodity_t * commodity =
- amount_t::current_pool->find_or_create(symbol)) {
- commodity->add_price(datetime, price, true);
- commodity->add_flags(COMMODITY_KNOWN);
- } else {
- assert(false);
- }
+ optional<price_point_t> point =
+ amount_t::current_pool->parse_price_directive(skip_ws(line + 1));
+ assert(point);
}
void instance_t::nomarket_directive(char * line)
{
char * p = skip_ws(line + 1);
string symbol;
- parse_symbol(p, symbol);
+ commodity_t::parse_symbol(p, symbol);
if (commodity_t * commodity =
amount_t::current_pool->find_or_create(symbol))
@@ -535,7 +487,7 @@ void instance_t::option_directive(char * line)
if (p)
*p++ = '\0';
}
- process_option(line + 2, session_scope, p, line);
+ process_option(pathname.string(), line + 2, session_scope, p, line);
}
void instance_t::automated_xact_directive(char * line)
@@ -863,6 +815,9 @@ post_t * instance_t::parse_post(char * line,
char * next = next_element(p, true);
char * e = p + std::strlen(p);
+ while (e > p && std::isspace(*(e - 1)))
+ e--;
+
if ((*p == '[' && *(e - 1) == ']') || (*p == '(' && *(e - 1) == ')')) {
post->add_flags(POST_VIRTUAL);
DEBUG("textual.parse", "line " << linenum << ": "
@@ -966,8 +921,14 @@ post_t * instance_t::parse_post(char * line,
post->cost->in_place_unround();
- if (per_unit)
+ if (per_unit) {
+ // For the sole case where the cost might be uncommoditized,
+ // guarantee that the commodity of the cost after multiplication
+ // is the same as it was before.
+ commodity_t& cost_commodity(post->cost->commodity());
*post->cost *= post->amount;
+ post->cost->set_commodity(cost_commodity);
+ }
DEBUG("textual.parse", "line " << linenum << ": "
<< "Total cost is " << *post->cost);
@@ -1014,7 +975,8 @@ post_t * instance_t::parse_post(char * line,
<< "POST assign: parsed amt = " << *post->assigned_amount);
amount_t& amt(*post->assigned_amount);
- value_t account_total(post->account->self_total(false));
+ value_t account_total(post->account->self_total(false)
+ .strip_annotations(keep_details_t()));
DEBUG("post.assign", "line " << linenum << ": "
"account balance = " << account_total);