summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/amount.cc55
-rw-r--r--src/convert.cc2
-rw-r--r--src/generate.cc17
-rw-r--r--src/generate.h7
-rw-r--r--src/journal.h4
-rw-r--r--src/print.cc7
-rw-r--r--src/print.h5
-rw-r--r--src/report.cc7
-rw-r--r--src/token.cc2
9 files changed, 72 insertions, 34 deletions
diff --git a/src/amount.cc b/src/amount.cc
index 13f30755..9b7c3676 100644
--- a/src/amount.cc
+++ b/src/amount.cc
@@ -47,6 +47,8 @@ static mpz_t temp;
static mpq_t tempq;
static mpfr_t tempf;
static mpfr_t tempfb;
+static mpfr_t tempfnum;
+static mpfr_t tempfden;
#endif
struct amount_t::bigint_t : public supports_flags<>
@@ -111,7 +113,7 @@ bool amount_t::is_initialized = false;
namespace {
void stream_out_mpq(std::ostream& out,
mpq_t quant,
- amount_t::precision_t prec,
+ amount_t::precision_t precision,
int zeros_prec = -1,
const optional<commodity_t&>& comm = none)
{
@@ -125,14 +127,39 @@ namespace {
// Convert the rational number to a floating-point, extending the
// floating-point to a large enough size to get a precise answer.
- const std::size_t bits = (mpz_sizeinbase(mpq_numref(quant), 2) +
- mpz_sizeinbase(mpq_denref(quant), 2));
- mpfr_set_prec(tempfb, bits + amount_t::extend_by_digits*8);
- mpfr_set_q(tempfb, quant, GMP_RNDN);
- mpfr_asprintf(&buf, "%.*Rf", prec, tempfb);
- DEBUG("amount.convert",
- "mpfr_print = " << buf << " (precision " << prec << ")");
+ mp_prec_t num_prec = mpz_sizeinbase(mpq_numref(quant), 2);
+ num_prec += amount_t::extend_by_digits*64;
+ if (num_prec < MPFR_PREC_MIN)
+ num_prec = MPFR_PREC_MIN;
+ DEBUG("amount.convert", "num prec = " << num_prec);
+
+ mpfr_set_prec(tempfnum, num_prec);
+ mpfr_set_z(tempfnum, mpq_numref(quant), GMP_RNDN);
+
+ mp_prec_t den_prec = mpz_sizeinbase(mpq_denref(quant), 2);
+ den_prec += amount_t::extend_by_digits*64;
+ if (den_prec < MPFR_PREC_MIN)
+ den_prec = MPFR_PREC_MIN;
+ DEBUG("amount.convert", "den prec = " << den_prec);
+
+ mpfr_set_prec(tempfden, den_prec);
+ mpfr_set_z(tempfden, mpq_denref(quant), GMP_RNDN);
+
+ mpfr_set_prec(tempfb, num_prec + den_prec);
+ mpfr_div(tempfb, tempfnum, tempfden, GMP_RNDN);
+
+ char bigbuf[4096];
+ mpfr_sprintf(bigbuf, "%.RNf", tempfb);
+ DEBUG("amount.convert", "num/den = " << bigbuf);
+
+ if (mpfr_asprintf(&buf, "%.*RNf", precision, tempfb) < 0)
+ throw_(amount_error,
+ _("Cannot output amount to a floating-point representation"));
+
+ DEBUG("amount.convert", "mpfr_print = " << buf
+ << " (precision " << precision
+ << ", zeros_prec " << zeros_prec << ")");
if (zeros_prec >= 0) {
string::size_type index = std::strlen(buf);
@@ -208,6 +235,8 @@ void amount_t::initialize()
mpq_init(tempq);
mpfr_init(tempf);
mpfr_init(tempfb);
+ mpfr_init(tempfnum);
+ mpfr_init(tempfden);
commodity_pool_t::current_pool.reset(new commodity_pool_t);
@@ -235,6 +264,8 @@ void amount_t::shutdown()
mpq_clear(tempq);
mpfr_clear(tempf);
mpfr_clear(tempfb);
+ mpfr_clear(tempfnum);
+ mpfr_clear(tempfden);
commodity_pool_t::current_pool.reset();
@@ -553,12 +584,10 @@ amount_t::precision_t amount_t::display_precision() const
commodity_t& comm(commodity());
- if (! comm || keep_precision())
- return quantity->prec;
- else if (comm.precision() != quantity->prec)
+ if (comm && ! keep_precision())
return comm.precision();
else
- return quantity->prec;
+ return comm ? std::max(quantity->prec, comm.precision()) : quantity->prec;
}
void amount_t::in_place_negate()
@@ -640,7 +669,7 @@ void amount_t::in_place_floor()
_dup();
std::ostringstream out;
- stream_out_mpq(out, MP(quantity), 0);
+ stream_out_mpq(out, MP(quantity), precision_t(0));
mpq_set_str(MP(quantity), out.str().c_str(), 10);
}
diff --git a/src/convert.cc b/src/convert.cc
index aa9bbb6f..adb82dd4 100644
--- a/src/convert.cc
+++ b/src/convert.cc
@@ -53,7 +53,7 @@ value_t convert_command(call_scope_t& scope)
if (report.HANDLED(account_))
bucket_name = report.HANDLER(account_).str();
else
- bucket_name = "Equity:Unknown";
+ bucket_name = _("Equity:Unknown");
account_t * bucket = journal.master->find_account(bucket_name);
account_t * unknown = journal.master->find_account(_("Expenses:Unknown"));
diff --git a/src/generate.cc b/src/generate.cc
index 9b4c2ee7..8ea1ab45 100644
--- a/src/generate.cc
+++ b/src/generate.cc
@@ -163,7 +163,8 @@ bool generate_posts_iterator::generate_account(std::ostream& out,
return must_balance;
}
-void generate_posts_iterator::generate_commodity(std::ostream& out)
+void generate_posts_iterator::generate_commodity(std::ostream& out,
+ const string& exclude)
{
string comm;
do {
@@ -171,8 +172,8 @@ void generate_posts_iterator::generate_commodity(std::ostream& out)
generate_string(buf, six_gen(), true);
comm = buf.str();
}
- while (comm == "h" || comm == "m" || comm == "s" || comm == "and" ||
- comm == "any" || comm == "all" || comm == "div" ||
+ while (comm == exclude || comm == "h" || comm == "m" || comm == "s" ||
+ comm == "and" || comm == "any" || comm == "all" || comm == "div" ||
comm == "false" || comm == "or" || comm == "not" ||
comm == "true" || comm == "if" || comm == "else");
@@ -181,12 +182,13 @@ void generate_posts_iterator::generate_commodity(std::ostream& out)
string generate_posts_iterator::generate_amount(std::ostream& out,
value_t not_this_amount,
- bool no_negative)
+ bool no_negative,
+ const string& exclude)
{
std::ostringstream buf;
if (truth_gen()) { // commodity goes in front
- generate_commodity(buf);
+ generate_commodity(buf, exclude);
if (truth_gen())
buf << ' ';
if (no_negative || truth_gen())
@@ -200,7 +202,7 @@ string generate_posts_iterator::generate_amount(std::ostream& out,
buf << neg_number_gen();
if (truth_gen())
buf << ' ';
- generate_commodity(buf);
+ generate_commodity(buf, exclude);
}
// Possibly generate an annotized commodity, but make it rarer
@@ -259,7 +261,8 @@ void generate_posts_iterator::generate_cost(std::ostream& out, value_t amount)
else
buf << " @@ ";
- if (! generate_amount(buf, amount, true).empty())
+ if (! generate_amount(buf, amount, true,
+ amount.as_amount().commodity().symbol()).empty())
out << buf.str();
}
diff --git a/src/generate.h b/src/generate.h
index 3d9965a5..f0f58064 100644
--- a/src/generate.h
+++ b/src/generate.h
@@ -110,10 +110,11 @@ public:
protected:
void generate_string(std::ostream& out, int len, bool only_alpha = false);
bool generate_account(std::ostream& out, bool no_virtual = false);
- void generate_commodity(std::ostream& out);
+ void generate_commodity(std::ostream& out, const string& exclude = "");
string generate_amount(std::ostream& out,
- value_t not_this_amount = NULL_VALUE,
- bool no_negative = false);
+ value_t not_this_amount = NULL_VALUE,
+ bool no_negative = false,
+ const string& exclude = "");
bool generate_post(std::ostream& out, bool no_amount = false);
void generate_cost(std::ostream& out, value_t amount);
void generate_date(std::ostream& out);
diff --git a/src/journal.h b/src/journal.h
index e54814aa..a407c02c 100644
--- a/src/journal.h
+++ b/src/journal.h
@@ -115,9 +115,9 @@ public:
auto_xacts_list auto_xacts;
period_xacts_list period_xacts;
std::list<fileinfo_t> sources;
- bool was_loaded;
payee_mappings_t payee_mappings;
account_mappings_t account_mappings;
+ bool was_loaded;
journal_t();
journal_t(const path& pathname);
@@ -196,6 +196,8 @@ private:
ar & auto_xacts;
ar & period_xacts;
ar & sources;
+ ar & payee_mappings;
+ ar & account_mappings;
}
#endif // HAVE_BOOST_SERIALIZATION
};
diff --git a/src/print.cc b/src/print.cc
index a8aa5872..f93f5fe8 100644
--- a/src/print.cc
+++ b/src/print.cc
@@ -40,13 +40,6 @@
namespace ledger {
-print_xacts::print_xacts(report_t& _report,
- bool _print_raw)
- : report(_report), print_raw(_print_raw), first_title(true)
-{
- TRACE_CTOR(print_xacts, "report&, bool");
-}
-
namespace {
void print_note(std::ostream& out,
const string& note,
diff --git a/src/print.h b/src/print.h
index 5263ec91..f6ef0868 100644
--- a/src/print.h
+++ b/src/print.h
@@ -65,7 +65,10 @@ protected:
bool first_title;
public:
- print_xacts(report_t& _report, bool _print_raw = false);
+ print_xacts(report_t& _report, bool _print_raw = false)
+ : report(_report), print_raw(_print_raw), first_title(true) {
+ TRACE_CTOR(print_xacts, "report&, bool");
+ }
virtual ~print_xacts() {
TRACE_DTOR(print_xacts);
}
diff --git a/src/report.cc b/src/report.cc
index 90de9a3f..cc652f8d 100644
--- a/src/report.cc
+++ b/src/report.cc
@@ -68,6 +68,13 @@ void report_t::normalize_options(const string& verb)
}
#endif
+ if (HANDLED(output_)) {
+ if (HANDLED(color) && ! HANDLED(force_color))
+ HANDLER(color).off();
+ if (HANDLED(pager_) && ! HANDLED(force_pager))
+ HANDLER(pager_).off();
+ }
+
item_t::use_effective_date = (HANDLED(effective) &&
! HANDLED(actual_dates));
diff --git a/src/token.cc b/src/token.cc
index add97b8b..905e13fe 100644
--- a/src/token.cc
+++ b/src/token.cc
@@ -476,7 +476,7 @@ void expr_t::token_t::unexpected(const char wanted)
switch (prev_kind) {
case TOK_EOF:
throw_(parse_error,
- _("Unexpected end of expression (wanted '%1')" << wanted));
+ _("Unexpected end of expression (wanted '%1')") << wanted);
case IDENT:
throw_(parse_error,
_("Unexpected symbol '%1' (wanted '%2')") << value << wanted);