diff options
author | John Wiegley <johnw@newartisans.com> | 2010-06-02 23:11:09 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-06-02 23:11:09 -0400 |
commit | 626b6a17eb71d4f5308dbedaa53e890c74c1acd1 (patch) | |
tree | b530c8cf1679a4b241c040df195e1b251dfa3062 | |
parent | cda19829bd1100d6563b48ddb121f2afc1c55d95 (diff) | |
parent | 6ceda8320fcd81376c3b8a8bc81e48b9e87f1926 (diff) | |
download | fork-ledger-626b6a17eb71d4f5308dbedaa53e890c74c1acd1.tar.gz fork-ledger-626b6a17eb71d4f5308dbedaa53e890c74c1acd1.tar.bz2 fork-ledger-626b6a17eb71d4f5308dbedaa53e890c74c1acd1.zip |
Merge branch 'next'
-rwxr-xr-x | acprep | 12 | ||||
-rw-r--r-- | src/amount.cc | 55 | ||||
-rw-r--r-- | src/convert.cc | 2 | ||||
-rw-r--r-- | src/generate.cc | 17 | ||||
-rw-r--r-- | src/generate.h | 7 | ||||
-rw-r--r-- | src/journal.h | 4 | ||||
-rw-r--r-- | src/print.cc | 7 | ||||
-rw-r--r-- | src/print.h | 5 | ||||
-rw-r--r-- | src/report.cc | 7 | ||||
-rw-r--r-- | src/token.cc | 2 | ||||
-rwxr-xr-x | test/LedgerHarness.py | 2 | ||||
-rw-r--r-- | test/regress/1D275740.test | 177 | ||||
-rw-r--r-- | test/regress/2E3496BD.test | 2 | ||||
-rwxr-xr-x | tools/proof | 3 |
14 files changed, 260 insertions, 42 deletions
@@ -454,6 +454,9 @@ class PrepareBuild(CommandLineApp): op.add_option('', '--no-python', action='store_true', dest='no_python', default=False, help='Do not enable Python support by default') + op.add_option('', '--universal', action='store_true', + dest='universal', default=False, + help='Attempt to build universal binaries') op.add_option('', '--output', metavar='DIR', action="callback", callback=self.option_output, help='Build in the specified directory') @@ -1165,10 +1168,11 @@ class PrepareBuild(CommandLineApp): self.CXXFLAGS.append(i) self.CFLAGS.append(i) self.LDFLAGS.append(i) - for i in ['-arch', 'i386', '-arch', 'x86_64']: - self.CXXFLAGS.append(i) - self.CFLAGS.append(i) - self.LDFLAGS.append(i) + if self.options.universal: + for i in ['-arch', 'i386', '-arch', 'x86_64']: + self.CXXFLAGS.append(i) + self.CFLAGS.append(i) + self.LDFLAGS.append(i) else: for i in ['-O3', '-fomit-frame-pointer']: self.CXXFLAGS.append(i) 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); diff --git a/test/LedgerHarness.py b/test/LedgerHarness.py index 8a5af123..ea8290d4 100755 --- a/test/LedgerHarness.py +++ b/test/LedgerHarness.py @@ -66,8 +66,6 @@ class LedgerHarness: if text_data: text += text_data text_data = os.read(fd.fileno(), 8192) - if text_data: - text += text_data return text def readlines(self, fd): diff --git a/test/regress/1D275740.test b/test/regress/1D275740.test new file mode 100644 index 00000000..72eb1769 --- /dev/null +++ b/test/regress/1D275740.test @@ -0,0 +1,177 @@ +print +<<< +D 1.200,40 € + +1999/11/01 * Achat + Actif:SSB 125 STK + Actif:SSB -1672,42 $ + +1999/11/04 * Vente + Actif:SSB -125 STK + Dépense:SSB:Commissions 55,07 $ + Actif:SSB 1821,54 $ + +2001/05/01 * Vente + Actif:SSEA -188,7974 STK @ 14,200 $ + Dépense:SSEA:Commissions 19,60 $ + Actif:SSEA 2661,32 $ + +2001/12/21 * Achat + Actif:LPG 7,34316 AMD @ 200,340 € + Actif:LPG -1471,13 € + +2002/12/31 * Réinv. des dividendes + Actif:LPG 0,03032 AMD @ 135,060 € + Revenu:Dividende:AMD -4,10 € + +2003/12/31 * Réinv. des dividendes + Actif:LPG 0,02356 AMD @ 147,830 € + Revenu:Dividende:AMD -3,48 € + +2004/02/17 * Vente + Actif:LPG -7,39704 AMD @ 148,860 € + Actif:LPG 1101,12 € + +2005/12/31 * Réinv. des dividendes + Actif:LPG 0,87704 LAPD @ 22,680 € + Revenu:Dividende:LAPD -19,89 € + +2006/06/30 * Achat + Actif:CPE 54,7328 PM @ 33,200 € + Actif:CPE -1817,13 € + +2006/06/30 * Achat + Actif:CPE 13,8913 PM @ 33,200 € + Actif:CPE -461,19 € + +2007/04/01 Achat + Actif:SV 0,2087 CE @ 622,900 € + Actif:BC -130,00 € + +2007/12/27 Vente + Actif:SV -0,2086 EA @ 183,800 € + Actif:SV 38,34 € + +2008/01/01 Achat + Actif:SV 0,1757 CE @ 739,900 € + Actif:BC -130,00 € + +2008/02/01 Achat + Actif:SV 3,1863 EA @ 163,200 € + Actif:BC -520,00 € + +2008/05/01 Achat + Actif:SV 0,2599 CE @ 654,100 € + Actif:BC -170,00 € + +2008/10/30 Vente + Actif:SV -0,0405 CD @ 155,800 € + Actif:SV 6,31 € + +2008/12/31 Vente + Actif:SV -0,0357 MFE @ 259,100 € + Actif:SV 9,25 € + +2009/06/29 Vente + Actif:SV -0,0786 CD @ 155,600 € + Actif:SV 12,23 € + +2009/07/30 Vente + Actif:SV -0,0417 MFE @ 321,100 € + Actif:SV 13,39 € + +2009/08/01 Achat + Actif:SV 1,0204 MFE @ 333,200 € + Actif:BC -340,00 € + +2009/09/29 Vente + Actif:SV -0,0415 MFE @ 358,800 € + Actif:SV 14,89 € +>>>1 +1999/11/01 * Achat + Actif:SSB 125,0000 STK @ 13,37936 $ + Actif:SSB -1672,42 $ + +1999/11/04 * Vente + Actif:SSB -125,0000 STK @ 15,01288 $ + Dépense:SSB:Commissions 55,07 $ + Actif:SSB 1821,54 $ + +2001/05/01 * Vente + Actif:SSEA -188,7974 STK @ 14,20 $ + Dépense:SSEA:Commissions 19,60 $ + Actif:SSEA 2661,32 $ + +2001/12/21 * Achat + Actif:LPG 7,34316 AMD @ 200,34 € + Actif:LPG -1.471,13 € + +2002/12/31 * Réinv. des dividendes + Actif:LPG 0,03032 AMD @ 135,06 € + Revenu:Dividende:AMD -4,10 € + +2003/12/31 * Réinv. des dividendes + Actif:LPG 0,02356 AMD @ 147,83 € + Revenu:Dividende:AMD -3,48 € + +2004/02/17 * Vente + Actif:LPG -7,39704 AMD @ 148,86 € + Actif:LPG 1.101,12 € + +2005/12/31 * Réinv. des dividendes + Actif:LPG 0,87704 LAPD @ 22,68 € + Revenu:Dividende:LAPD -19,89 € + +2006/06/30 * Achat + Actif:CPE 54,7328 PM @ 33,20 € + Actif:CPE -1.817,13 € + +2006/06/30 * Achat + Actif:CPE 13,8913 PM @ 33,20 € + Actif:CPE -461,19 € + +2007/04/01 Achat + Actif:SV 0,2087 CE @ 622,90 € + Actif:BC -130,00 € + +2007/12/27 Vente + Actif:SV -0,2086 EA @ 183,80 € + Actif:SV 38,34 € + +2008/01/01 Achat + Actif:SV 0,1757 CE @ 739,90 € + Actif:BC -130,00 € + +2008/02/01 Achat + Actif:SV 3,1863 EA @ 163,20 € + Actif:BC -520,00 € + +2008/05/01 Achat + Actif:SV 0,2599 CE @ 654,10 € + Actif:BC -170,00 € + +2008/10/30 Vente + Actif:SV -0,0405 CD @ 155,80 € + Actif:SV 6,31 € + +2008/12/31 Vente + Actif:SV -0,0357 MFE @ 259,10 € + Actif:SV 9,25 € + +2009/06/29 Vente + Actif:SV -0,0786 CD @ 155,60 € + Actif:SV 12,23 € + +2009/07/30 Vente + Actif:SV -0,0417 MFE @ 321,10 € + Actif:SV 13,39 € + +2009/08/01 Achat + Actif:SV 1,0204 MFE @ 333,20 € + Actif:BC -340,00 € + +2009/09/29 Vente + Actif:SV -0,0415 MFE @ 358,80 € + Actif:SV 14,89 € +>>>2 +=== 0 diff --git a/test/regress/2E3496BD.test b/test/regress/2E3496BD.test index cb105f08..466464b3 100644 --- a/test/regress/2E3496BD.test +++ b/test/regress/2E3496BD.test @@ -15,6 +15,6 @@ While balancing transaction from "$FILE", lines 3-5: Unbalanced remainder is: 100.00 USD Amount to balance against: - 1,600.0 USD + 1,600.00 USD Error: Transaction does not balance === 1 diff --git a/tools/proof b/tools/proof index c41745b6..5a329a50 100755 --- a/tools/proof +++ b/tools/proof @@ -14,7 +14,8 @@ fi rm -fr ~/Products/ledger* -time ./acprep -j16 --warn proof 2>&1 | tee ~/Desktop/proof.log +time ./acprep --universal -j16 --warn proof 2>&1 | \ + tee ~/Desktop/proof.log if egrep -q '(ERROR|CRITICAL)' ~/Desktop/proof.log; then if [[ "$1" = "--alert" ]]; then |