diff options
author | John Wiegley <johnw@newartisans.com> | 2012-05-14 21:36:42 -0600 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2012-05-14 21:44:00 -0600 |
commit | f4f3058b8cd75c04080f9b68cb54b9584eafb39f (patch) | |
tree | eca9ca6ceca001209fb93c05b52e21031280d18c | |
parent | 96172669053bbba7263a370f109f70615049a0c6 (diff) | |
download | fork-ledger-f4f3058b8cd75c04080f9b68cb54b9584eafb39f.tar.gz fork-ledger-f4f3058b8cd75c04080f9b68cb54b9584eafb39f.tar.bz2 fork-ledger-f4f3058b8cd75c04080f9b68cb54b9584eafb39f.zip |
Switch to using Boost.Format
-rw-r--r-- | src/accum.cc | 77 | ||||
-rw-r--r-- | src/accum.h | 111 | ||||
-rw-r--r-- | src/amount.cc | 12 | ||||
-rw-r--r-- | src/balance.cc | 4 | ||||
-rw-r--r-- | src/context.h | 5 | ||||
-rw-r--r-- | src/convert.cc | 4 | ||||
-rw-r--r-- | src/draft.cc | 6 | ||||
-rw-r--r-- | src/error.cc | 2 | ||||
-rw-r--r-- | src/error.h | 20 | ||||
-rw-r--r-- | src/expr.cc | 4 | ||||
-rw-r--r-- | src/format.cc | 4 | ||||
-rw-r--r-- | src/generate.cc | 8 | ||||
-rw-r--r-- | src/global.cc | 6 | ||||
-rw-r--r-- | src/item.cc | 16 | ||||
-rw-r--r-- | src/journal.cc | 29 | ||||
-rw-r--r-- | src/main.cc | 2 | ||||
-rw-r--r-- | src/op.cc | 22 | ||||
-rw-r--r-- | src/option.cc | 18 | ||||
-rw-r--r-- | src/option.h | 12 | ||||
-rw-r--r-- | src/parser.cc | 20 | ||||
-rw-r--r-- | src/post.cc | 6 | ||||
-rw-r--r-- | src/post.h | 2 | ||||
-rw-r--r-- | src/pyinterp.cc | 10 | ||||
-rw-r--r-- | src/query.cc | 20 | ||||
-rw-r--r-- | src/report.cc | 12 | ||||
-rw-r--r-- | src/report.h | 12 | ||||
-rw-r--r-- | src/scope.cc | 6 | ||||
-rw-r--r-- | src/stats.cc | 15 | ||||
-rw-r--r-- | src/system.hh.in | 17 | ||||
-rw-r--r-- | src/textual.cc | 32 | ||||
-rw-r--r-- | src/times.cc | 14 | ||||
-rw-r--r-- | src/token.cc | 26 | ||||
-rw-r--r-- | src/utils.cc | 6 | ||||
-rw-r--r-- | src/value.cc | 110 | ||||
-rw-r--r-- | src/xact.cc | 9 | ||||
-rw-r--r-- | src/xact.h | 6 | ||||
-rw-r--r-- | tools/Makefile.am | 2 |
37 files changed, 245 insertions, 442 deletions
diff --git a/src/accum.cc b/src/accum.cc deleted file mode 100644 index 3add051b..00000000 --- a/src/accum.cc +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2003-2012, John Wiegley. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of New Artisans LLC nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <system.hh> - -#include "utils.h" - -namespace ledger { - -straccstream _accum; -std::ostringstream _accum_buffer; - -std::streamsize straccbuf::xsputn(const char * s, std::streamsize num) -{ - if (index == 0) { - // The first item received is the format string - str = std::string(s, static_cast<std::string::size_type>(num)); - } - else { - std::ostringstream buf; - - // Every item thereafter is an argument that substitutes for %# in the - // format string - bool matched = false; - for (const char * p = str.c_str(); *p; p++) { - if (*p == '%') { - const char * q = p + 1; - if (*q && *q != '%' && std::isdigit(*q) && - std::string::size_type(*q - '0') == index) { - p++; - buf << std::string(s, static_cast<std::string::size_type>(num)); - matched = true; - } else { - buf << *p; - } - } else { - buf << *p; - } - } - if (! matched) - buf << std::string(s, static_cast<std::string::size_type>(num)); - - str = buf.str(); - } - index++; - return num; -} - -} // namespace ledger diff --git a/src/accum.h b/src/accum.h deleted file mode 100644 index 628a6b36..00000000 --- a/src/accum.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2003-2012, John Wiegley. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of New Artisans LLC nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * @addtogroup util - */ - -/** - * @file accum.h - * @author John Wiegley - * - * @ingroup util - */ -#ifndef _ACCUM_H -#define _ACCUM_H - -namespace ledger { - -class straccbuf : public std::streambuf -{ -protected: - std::string str; // accumulator - std::string::size_type index; - -public: - straccbuf() : index(0) { - TRACE_CTOR(straccbuf, ""); - } - ~straccbuf() throw() { - TRACE_DTOR(straccbuf); - } - -protected: - virtual std::streamsize xsputn(const char * s, std::streamsize num); - - friend class straccstream; -}; - -class straccstream : public std::ostream -{ -protected: - straccbuf buf; - -public: - straccstream() : std::ostream(0) { - TRACE_CTOR(straccstream, ""); - rdbuf(&buf); - } - ~straccstream() throw() { - TRACE_DTOR(straccstream); - } - - void clear() { - std::ostream::clear(); - buf.pubseekoff(0, ios_base::beg); - buf.str.clear(); - buf.index = 0; - } - - std::string str() const { - return buf.str; - } -}; - -#define ACCUM(obj) (static_cast<const straccstream&>(obj).str()) - -extern straccstream _accum; -extern std::ostringstream _accum_buffer; - -inline string str_helper_func() { - string buf = _accum_buffer.str(); - _accum_buffer.clear(); - _accum_buffer.str(""); - return buf; -} - -#define STR(msg) \ - ((_accum_buffer << ACCUM(_accum << msg)), \ - _accum.clear(), str_helper_func()) - -} // namespace ledger - -#endif // _ACCUM_H diff --git a/src/amount.cc b/src/amount.cc index 5e933215..803787e8 100644 --- a/src/amount.cc +++ b/src/amount.cc @@ -397,8 +397,8 @@ int amount_t::compare(const amount_t& amt) const if (has_commodity() && amt.has_commodity() && commodity() != amt.commodity()) { throw_(amount_error, - _("Cannot compare amounts with different commodities: '%1' and '%2'") - << commodity() << amt.commodity()); + _f("Cannot compare amounts with different commodities: '%1%' and '%2%'") + % commodity() % amt.commodity()); } return mpq_cmp(MP(quantity), MP(amt.quantity)); @@ -432,8 +432,8 @@ amount_t& amount_t::operator+=(const amount_t& amt) if (has_commodity() && amt.has_commodity() && commodity() != amt.commodity()) { throw_(amount_error, - _("Adding amounts with different commodities: '%1' != '%2'") - << commodity() << amt.commodity()); + _f("Adding amounts with different commodities: '%1%' != '%2%'") + % commodity() % amt.commodity()); } _dup(); @@ -462,8 +462,8 @@ amount_t& amount_t::operator-=(const amount_t& amt) if (has_commodity() && amt.has_commodity() && commodity() != amt.commodity()) { throw_(amount_error, - _("Subtracting amounts with different commodities: '%1' != '%2'") - << commodity() << amt.commodity()); + _f("Subtracting amounts with different commodities: '%1%' != '%2%'") + % commodity() % amt.commodity()); } _dup(); diff --git a/src/balance.cc b/src/balance.cc index ded3d38a..42034ff8 100644 --- a/src/balance.cc +++ b/src/balance.cc @@ -216,8 +216,8 @@ balance_t::commodity_amount(const optional<const commodity_t&>& commodity) const return temp.commodity_amount(commodity); throw_(amount_error, - _("Requested amount of a balance with multiple commodities: %1") - << temp); + _f("Requested amount of a balance with multiple commodities: %1%") + % temp); } } else if (amounts.size() > 0) { diff --git a/src/context.h b/src/context.h index 45bb9990..09734b3e 100644 --- a/src/context.h +++ b/src/context.h @@ -103,6 +103,9 @@ public: void warning(const string& what) const { warning_func(location() + what); } + void warning(const boost::format& what) const { + warning_func(location() + string(what.str())); + } }; inline parse_context_t open_for_reading(const path& pathname, @@ -112,7 +115,7 @@ inline parse_context_t open_for_reading(const path& pathname, if (! exists(filename)) throw_(std::runtime_error, - _("Cannot read journal file %1") << filename); + _f("Cannot read journal file %1%") % filename); #if BOOST_VERSION >= 104600 && BOOST_FILESYSTEM_VERSION >= 3 path parent(filesystem::absolute(pathname, cwd).parent_path()); diff --git a/src/convert.cc b/src/convert.cc index e8ca241e..f0d8db06 100644 --- a/src/convert.cc +++ b/src/convert.cc @@ -119,8 +119,8 @@ value_t convert_command(call_scope_t& args) formatter.flush(); } catch (const std::exception&) { - add_error_context(_("While parsing file %1") - << file_context(reader.get_pathname(), + add_error_context(_f("While parsing file %1%") + % file_context(reader.get_pathname(), reader.get_linenum())); add_error_context(_("While parsing CSV line:")); add_error_context(line_context(reader.get_last_line())); diff --git a/src/draft.cc b/src/draft.cc index 43c214cb..c5f37f42 100644 --- a/src/draft.cc +++ b/src/draft.cc @@ -68,7 +68,7 @@ void draft_t::xact_template_t::dump(std::ostream& out) const } else { foreach (const post_template_t& post, posts) { out << std::endl - << STR(_("[Posting \"%1\"]") << (post.from ? _("from") : _("to"))) + << _f("[Posting \"%1\"]") % (post.from ? _("from") : _("to")) << std::endl; if (post.account_mask) @@ -307,8 +307,8 @@ xact_t * draft_t::insert(journal_t& journal) } } else { throw_(std::runtime_error, - _("No accounts, and no past transaction matching '%1'") - << tmpl->payee_mask); + _f("No accounts, and no past transaction matching '%1%'") + % tmpl->payee_mask); } } else { DEBUG("draft.xact", "Template had postings"); diff --git a/src/error.cc b/src/error.cc index 4a16f4e3..58339db7 100644 --- a/src/error.cc +++ b/src/error.cc @@ -35,9 +35,7 @@ namespace ledger { -straccstream _ctxt_accum; std::ostringstream _ctxt_buffer; -straccstream _desc_accum; std::ostringstream _desc_buffer; string error_context() diff --git a/src/error.h b/src/error.h index 86d9de76..9837fa4d 100644 --- a/src/error.h +++ b/src/error.h @@ -42,11 +42,8 @@ #ifndef _ERROR_H #define _ERROR_H -#include "accum.h" - namespace ledger { -extern straccstream _desc_accum; extern std::ostringstream _desc_buffer; template <typename T> @@ -57,8 +54,7 @@ inline void throw_func(const string& message) { } #define throw_(cls, msg) \ - ((_desc_buffer << ACCUM(_desc_accum << msg)), \ - _desc_accum.clear(), \ + ((_desc_buffer << (msg)), \ throw_func<cls>(_desc_buffer.str())) inline void warning_func(const string& message) { @@ -68,19 +64,15 @@ inline void warning_func(const string& message) { } #define warning_(msg) \ - ((_desc_buffer << ACCUM(_desc_accum << msg)), \ - _desc_accum.clear(), \ + ((_desc_buffer << (msg)), \ warning_func(_desc_buffer.str())) -extern straccstream _ctxt_accum; extern std::ostringstream _ctxt_buffer; -#define add_error_context(msg) \ - ((long(_ctxt_buffer.tellp()) == 0) ? \ - ((_ctxt_buffer << ACCUM(_ctxt_accum << msg)), \ - _ctxt_accum.clear()) : \ - ((_ctxt_buffer << std::endl << ACCUM(_ctxt_accum << msg)), \ - _ctxt_accum.clear())) +#define add_error_context(msg) \ + ((long(_ctxt_buffer.tellp()) == 0) ? \ + (_ctxt_buffer << (msg)) : \ + (_ctxt_buffer << std::endl << (msg))) string error_context(); diff --git a/src/expr.cc b/src/expr.cc index 25967207..dbe860bf 100644 --- a/src/expr.cc +++ b/src/expr.cc @@ -306,8 +306,8 @@ value_t source_command(call_scope_t& args) expr_t(p).calc(file_locals); } catch (const std::exception&) { - add_error_context(_("While parsing value expression on line %1:") - << linenum); + add_error_context(_f("While parsing value expression on line %1%:") + % linenum); add_error_context(source_context(pathname, pos, in->tellg(), "> ")); } } diff --git a/src/format.cc b/src/format.cc index 8c3cbc14..18c7696d 100644 --- a/src/format.cc +++ b/src/format.cc @@ -236,7 +236,7 @@ format_t::element_t * format_t::parse_elements(const string& fmt, } } if (! found) - throw_(format_error, _("Unrecognized formatting character: %1") << *p); + throw_(format_error, _f("Unrecognized formatting character: %1%") % *p); } else { switch (*p) { case '%': @@ -375,7 +375,7 @@ format_t::element_t * format_t::parse_elements(const string& fmt, } default: - throw_(format_error, _("Unrecognized formatting character: %1") << *p); + throw_(format_error, _f("Unrecognized formatting character: %1%") % *p); } } } diff --git a/src/generate.cc b/src/generate.cc index 8769c99c..bcbde9f1 100644 --- a/src/generate.cc +++ b/src/generate.cc @@ -374,14 +374,14 @@ void generate_posts_iterator::increment() } } catch (std::exception&) { - add_error_context(_("While parsing generated transaction (seed %1):") - << seed); + add_error_context(_f("While parsing generated transaction (seed %1%):") + % seed); add_error_context(buf.str()); throw; } catch (int) { - add_error_context(_("While parsing generated transaction (seed %1):") - << seed); + add_error_context(_f("While parsing generated transaction (seed %1%):") + % seed); add_error_context(buf.str()); throw; } diff --git a/src/global.cc b/src/global.cc index 6dc8d150..285fdea3 100644 --- a/src/global.cc +++ b/src/global.cc @@ -121,8 +121,8 @@ void global_scope_t::read_init() if (session().journal->read(parsing_context) > 0 || session().journal->auto_xacts.size() > 0 || session().journal->period_xacts.size() > 0) { - throw_(parse_error, _("Transactions found in initialization file '%1'") - << init_file); + throw_(parse_error, _f("Transactions found in initialization file '%1%'") + % init_file); } TRACE_FINISH(init, 1); @@ -203,7 +203,7 @@ void global_scope_t::execute_command(strings_list args, bool at_repl) report().normalize_options(verb); if (! bool(command = look_for_command(bound_scope, verb))) - throw_(std::logic_error, _("Unrecognized command '%1'") << verb); + throw_(std::logic_error, _f("Unrecognized command '%1%'") % verb); } // Create the output stream (it might be a file, the console or a PAGER diff --git a/src/item.cc b/src/item.cc index 17d46652..de5ffef2 100644 --- a/src/item.cc +++ b/src/item.cc @@ -270,16 +270,16 @@ namespace { return item.has_tag(args.get<mask_t>(0)); else throw_(std::runtime_error, - _("Expected string or mask for argument 1, but received %1") - << args[0].label()); + _f("Expected string or mask for argument 1, but received %1%") + % args[0].label()); } else if (args.size() == 2) { if (args[0].is_mask() && args[1].is_mask()) return item.has_tag(args.get<mask_t>(0), args.get<mask_t>(1)); else throw_(std::runtime_error, - _("Expected masks for arguments 1 and 2, but received %1 and %2") - << args[0].label() << args[1].label()); + _f("Expected masks for arguments 1 and 2, but received %1% and %2%") + % args[0].label() % args[1].label()); } else if (args.size() == 0) { throw_(std::runtime_error, _("Too few arguments to function")); @@ -302,16 +302,16 @@ namespace { val = item.get_tag(args.get<mask_t>(0)); else throw_(std::runtime_error, - _("Expected string or mask for argument 1, but received %1") - << args[0].label()); + _f("Expected string or mask for argument 1, but received %1%") + % args[0].label()); } else if (args.size() == 2) { if (args[0].is_mask() && args[1].is_mask()) val = item.get_tag(args.get<mask_t>(0), args.get<mask_t>(1)); else throw_(std::runtime_error, - _("Expected masks for arguments 1 and 2, but received %1 and %2") - << args[0].label() << args[1].label()); + _f("Expected masks for arguments 1 and 2, but received %1% and %2%") + % args[0].label() % args[1].label()); } else if (args.size() == 0) { throw_(std::runtime_error, _("Too few arguments to function")); diff --git a/src/journal.cc b/src/journal.cc index 49d86ff0..e6c09125 100644 --- a/src/journal.cc +++ b/src/journal.cc @@ -160,11 +160,10 @@ account_t * journal_t::register_account(const string& name, post_t * post, result->add_flags(ACCOUNT_KNOWN); } else if (checking_style == CHECK_WARNING) { - current_context->warning(STR(_("Unknown account '%1'") - << result->fullname())); + current_context->warning(_f("Unknown account '%1%'") % result->fullname()); } else if (checking_style == CHECK_ERROR) { - throw_(parse_error, _("Unknown account '%1'") << result->fullname()); + throw_(parse_error, _f("Unknown account '%1%'") % result->fullname()); } } } @@ -190,10 +189,10 @@ string journal_t::register_payee(const string& name, xact_t * xact) known_payees.insert(name); } else if (checking_style == CHECK_WARNING) { - current_context->warning(STR(_("Unknown payee '%1'") << name)); + current_context->warning(_f("Unknown payee '%1%'") % name); } else if (checking_style == CHECK_ERROR) { - throw_(parse_error, _("Unknown payee '%1'") << name); + throw_(parse_error, _f("Unknown payee '%1%'") % name); } } } @@ -226,10 +225,10 @@ void journal_t::register_commodity(commodity_t& comm, comm.add_flags(COMMODITY_KNOWN); } else if (checking_style == CHECK_WARNING) { - current_context->warning(STR(_("Unknown commodity '%1'") << comm)); + current_context->warning(_f("Unknown commodity '%1%'") % comm); } else if (checking_style == CHECK_ERROR) { - throw_(parse_error, _("Unknown commodity '%1'") << comm); + throw_(parse_error, _f("Unknown commodity '%1%'") % comm); } } } @@ -255,10 +254,10 @@ void journal_t::register_metadata(const string& key, const value_t& value, known_tags.insert(key); } else if (checking_style == CHECK_WARNING) { - current_context->warning(STR(_("Unknown metadata tag '%1'") << key)); + current_context->warning(_f("Unknown metadata tag '%1%'") % key); } else if (checking_style == CHECK_ERROR) { - throw_(parse_error, _("Unknown metadata tag '%1'") << key); + throw_(parse_error, _f("Unknown metadata tag '%1%'") % key); } } } @@ -281,12 +280,12 @@ void journal_t::register_metadata(const string& key, const value_t& value, if (! (*i).second.first.calc(val_scope).to_boolean()) { if ((*i).second.second == expr_t::EXPR_ASSERTION) throw_(parse_error, - _("Metadata assertion failed for (%1: %2): %3") - << key << value << (*i).second.first); + _f("Metadata assertion failed for (%1%: %2%): %3%") + % key % value % (*i).second.first); else current_context->warning - (STR(_("Metadata check failed for (%1: %2): %3") - << key << value << (*i).second.first)); + (_f("Metadata check failed for (%1%: %2%): %3%") + % key % value % (*i).second.first); } } } @@ -388,8 +387,8 @@ std::size_t journal_t::read(parse_context_stack_t& context) if (! current.scope) throw_(std::runtime_error, - _("No default scope in which to read journal file '%1'") - << current.pathname); + _f("No default scope in which to read journal file '%1%'") + % current.pathname); if (! current.master) current.master = master; diff --git a/src/main.cc b/src/main.cc index 0130d5c6..b309255b 100644 --- a/src/main.cc +++ b/src/main.cc @@ -146,7 +146,7 @@ int main(int argc, char * argv[], char * envp[]) std::free(expansion); std::free(p); throw_(std::logic_error, - _("Failed to expand history reference '%1'") << p); + _f("Failed to expand history reference '%1%'") % p); } else if (expansion) { add_history(expansion); @@ -79,9 +79,9 @@ namespace { scope.type_context() != value_t::VOID && result.type() != scope.type_context()) { throw_(calc_error, - _("Expected return of %1, but received %2") - << result.label(scope.type_context()) - << result.label()); + _f("Expected return of %1%, but received %2%") + % result.label(scope.type_context()) + % result.label()); } } } @@ -181,7 +181,7 @@ expr_t::ptr_op_t expr_t::op_t::compile(scope_t& scope, const int depth, std::ostringstream buf; varname->dump(buf, 0); throw_(calc_error, - _("Invalid function or lambda parameter: %1") << buf.str()); + _f("Invalid function or lambda parameter: %1%") % buf.str()); } else { DEBUG("expr.compile", "Defining function parameter " << varname->as_ident()); @@ -242,7 +242,7 @@ namespace { def = scope.lookup(symbol_t::FUNCTION, op->as_ident()); } if (! def) - throw_(calc_error, _("Unknown identifier '%1'") << op->as_ident()); + throw_(calc_error, _f("Unknown identifier '%1%'") % op->as_ident()); return def; } } @@ -412,7 +412,7 @@ value_t expr_t::op_t::calc(scope_t& scope, ptr_op_t * locus, const int depth) break; default: - throw_(calc_error, _("Unexpected expr node '%1'") << op_context(this)); + throw_(calc_error, _f("Unexpected expr node '%1%'") % op_context(this)); } #if defined(DEBUG_ON) @@ -462,7 +462,7 @@ namespace { return find_definition(as_expr(def), scope, locus, depth, recursion_depth + 1); else - throw_(value_error, _("Cannot call %1 as a function") << def.label()); + throw_(value_error, _f("Cannot call %1% as a function") % def.label()); } // Resolve ordinary expressions. @@ -504,8 +504,8 @@ namespace { if (args_index < args_count) throw_(calc_error, - _("Too few arguments in function call (saw %1, wanted %2)") - << args_count << args_index); + _f("Too few arguments in function call (saw %1%, wanted %2%)") + % args_count % args_index); if (func->right()->is_scope()) { bind_scope_t outer_scope(scope, *func->right()->as_scope()); @@ -555,8 +555,8 @@ value_t expr_t::op_t::calc_call(scope_t& scope, ptr_op_t * locus, } } catch (const std::exception&) { - add_error_context(_("While calling function '%1 %2':" << name - << call_args.args)); + add_error_context(_f("While calling function '%1% %2%':") % name + % call_args.args); throw; } } diff --git a/src/option.cc b/src/option.cc index 418980bd..7fcc9e4d 100644 --- a/src/option.cc +++ b/src/option.cc @@ -88,9 +88,9 @@ namespace { } catch (const std::exception&) { if (name[0] == '-') - add_error_context(_("While parsing option '%1'") << name); + add_error_context(_f("While parsing option '%1%'") % name); else - add_error_context(_("While parsing environent variable '%1'") << name); + add_error_context(_f("While parsing environent variable '%1%'") % name); throw; } } @@ -137,8 +137,8 @@ void process_environment(const char ** envp, const string& tag, process_option(string("$") + buf, string(buf), scope, q + 1, value); } catch (const std::exception&) { - add_error_context(_("While parsing environment variable option '%1':") - << *p); + add_error_context(_f("While parsing environment variable option '%1%':") + % *p); throw; } } @@ -198,20 +198,20 @@ strings_list process_arguments(strings_list args, scope_t& scope) op_bool_tuple opt(find_option(scope, opt_name)); if (! opt.first) - throw_(option_error, _("Illegal option --%1") << name); + throw_(option_error, _f("Illegal option --%1%") % name); if (opt.second && ! value && ++i != args.end() && value == NULL) { value = (*i).c_str(); DEBUG("option.args", " read option value from arg: " << value); if (value == NULL) - throw_(option_error, _("Missing option argument for --%1") << name); + throw_(option_error, _f("Missing option argument for --%1%") % name); } process_option(string("--") + name, opt.first->as_function(), scope, value, string("--") + name); } else if ((*i)[1] == '\0') { - throw_(option_error, _("illegal option -%1") << (*i)[0]); + throw_(option_error, _f("illegal option -%1%") % (*i)[0]); } else { DEBUG("option.args", " single-char option"); @@ -222,7 +222,7 @@ strings_list process_arguments(strings_list args, scope_t& scope) for (char c = (*i)[x]; c != '\0'; x++, c = (*i)[x]) { op_bool_tuple opt(find_option(scope, c)); if (! opt.first) - throw_(option_error, _("Illegal option -%1") << c); + throw_(option_error, _f("Illegal option -%1%") % c); option_queue.push_back(op_bool_char_tuple(opt.first, opt.second, c)); } @@ -234,7 +234,7 @@ strings_list process_arguments(strings_list args, scope_t& scope) DEBUG("option.args", " read option value from arg: " << value); if (value == NULL) throw_(option_error, - _("Missing option argument for -%1") << o.ch); + _f("Missing option argument for -%1%") % o.ch); } process_option(string("-") + o.ch, o.op->as_function(), scope, value, string("-") + o.ch); diff --git a/src/option.h b/src/option.h index b0d4e0f0..80be69c4 100644 --- a/src/option.h +++ b/src/option.h @@ -127,7 +127,7 @@ public: string str() const { assert(handled); if (value.empty()) - throw_(std::runtime_error, _("No argument provided for %1") << desc()); + throw_(std::runtime_error, _f("No argument provided for %1%") % desc()); return value; } @@ -168,18 +168,18 @@ public: value_t handler(call_scope_t& args) { if (wants_arg) { if (args.size() < 2) - throw_(std::runtime_error, _("No argument provided for %1") << desc()); + throw_(std::runtime_error, _f("No argument provided for %1%") % desc()); else if (args.size() > 2) - throw_(std::runtime_error, _("To many arguments provided for %1") << desc()); + throw_(std::runtime_error, _f("To many arguments provided for %1%") % desc()); else if (! args[0].is_string()) - throw_(std::runtime_error, _("Context argument for %1 not a string") << desc()); + throw_(std::runtime_error, _f("Context argument for %1% not a string") % desc()); on(args.get<string>(0), args.get<string>(1)); } else if (args.size() < 1) { - throw_(std::runtime_error, _("No argument provided for %1") << desc()); + throw_(std::runtime_error, _f("No argument provided for %1%") % desc()); } else if (! args[0].is_string()) { - throw_(std::runtime_error, _("Context argument for %1 not a string") << desc()); + throw_(std::runtime_error, _f("Context argument for %1% not a string") % desc()); } else { on(args.get<string>(0)); diff --git a/src/parser.cc b/src/parser.cc index 360ac93d..a17ad271 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -113,7 +113,7 @@ expr_t::parser_t::parse_dot_expr(std::istream& in, node->set_right(parse_call_expr(in, tflags)); if (! node->right()) throw_(parse_error, - _("%1 operator not followed by argument") << tok.symbol); + _f("%1% operator not followed by argument") % tok.symbol); } else { push_token(tok); break; @@ -137,7 +137,7 @@ expr_t::parser_t::parse_unary_expr(std::istream& in, ptr_op_t term(parse_dot_expr(in, tflags)); if (! term) throw_(parse_error, - _("%1 operator not followed by argument") << tok.symbol); + _f("%1% operator not followed by argument") % tok.symbol); // A very quick optimization if (term->kind == op_t::VALUE) { @@ -154,7 +154,7 @@ expr_t::parser_t::parse_unary_expr(std::istream& in, ptr_op_t term(parse_dot_expr(in, tflags)); if (! term) throw_(parse_error, - _("%1 operator not followed by argument") << tok.symbol); + _f("%1% operator not followed by argument") % tok.symbol); // A very quick optimization if (term->kind == op_t::VALUE) { @@ -195,7 +195,7 @@ expr_t::parser_t::parse_mul_expr(std::istream& in, node->set_right(parse_unary_expr(in, tflags)); if (! node->right()) throw_(parse_error, - _("%1 operator not followed by argument") << tok.symbol); + _f("%1% operator not followed by argument") % tok.symbol); } else { push_token(tok); break; @@ -225,7 +225,7 @@ expr_t::parser_t::parse_add_expr(std::istream& in, node->set_right(parse_mul_expr(in, tflags)); if (! node->right()) throw_(parse_error, - _("%1 operator not followed by argument") << tok.symbol); + _f("%1% operator not followed by argument") % tok.symbol); } else { push_token(tok); break; @@ -292,7 +292,7 @@ expr_t::parser_t::parse_logic_expr(std::istream& in, if (! node->right()) throw_(parse_error, - _("%1 operator not followed by argument") << tok.symbol); + _f("%1% operator not followed by argument") % tok.symbol); if (negate) { prev = node; @@ -324,7 +324,7 @@ expr_t::parser_t::parse_and_expr(std::istream& in, node->set_right(parse_logic_expr(in, tflags)); if (! node->right()) throw_(parse_error, - _("%1 operator not followed by argument") << tok.symbol); + _f("%1% operator not followed by argument") % tok.symbol); } else { push_token(tok); break; @@ -351,7 +351,7 @@ expr_t::parser_t::parse_or_expr(std::istream& in, node->set_right(parse_and_expr(in, tflags)); if (! node->right()) throw_(parse_error, - _("%1 operator not followed by argument") << tok.symbol); + _f("%1% operator not followed by argument") % tok.symbol); } else { push_token(tok); break; @@ -377,7 +377,7 @@ expr_t::parser_t::parse_querycolon_expr(std::istream& in, node->set_right(parse_or_expr(in, tflags)); if (! node->right()) throw_(parse_error, - _("%1 operator not followed by argument") << tok.symbol); + _f("%1% operator not followed by argument") % tok.symbol); next_token(in, tflags.plus_flags(PARSE_OP_CONTEXT), token_t::COLON); prev = node->right(); @@ -386,7 +386,7 @@ expr_t::parser_t::parse_querycolon_expr(std::istream& in, subnode->set_right(parse_or_expr(in, tflags)); if (! subnode->right()) throw_(parse_error, - _("%1 operator not followed by argument") << tok.symbol); + _f("%1% operator not followed by argument") % tok.symbol); node->set_right(subnode); } diff --git a/src/post.cc b/src/post.cc index 0564eaca..e89c0e7c 100644 --- a/src/post.cc +++ b/src/post.cc @@ -292,13 +292,13 @@ namespace { } else { throw_(std::runtime_error, - _("Expected string or mask for argument 1, but received %1") - << args[0].label()); + _f("Expected string or mask for argument 1, but received %1%") + % args[0].label()); } if (! acct) throw_(std::runtime_error, - _("Could not find an account matching ") << args[0]); + _f("Could not find an account matching '%1%'") % args[0]); return value_t(static_cast<scope_t *>(acct)); } @@ -106,7 +106,7 @@ public: virtual string description() { if (pos) { std::ostringstream buf; - buf << _("posting at line %1") << pos->beg_line; + buf << _f("posting at line %1") << pos->beg_line; return buf.str(); } else { return string(_("generated posting")); diff --git a/src/pyinterp.cc b/src/pyinterp.cc index 8d9c8c84..3c864910 100644 --- a/src/pyinterp.cc +++ b/src/pyinterp.cc @@ -113,12 +113,12 @@ void python_module_t::import_module(const string& name, bool import_direct) object mod = python::import(name.c_str()); if (! mod) throw_(std::runtime_error, - _("Module import failed (couldn't find %1)") << name); + _f("Module import failed (couldn't find %1%)") % name); dict globals = extract<dict>(mod.attr("__dict__")); if (! globals) throw_(std::runtime_error, - _("Module import failed (couldn't find %1)") << name); + _f("Module import failed (couldn't find %1%)") % name); if (! import_direct) { module_object = mod; @@ -246,7 +246,7 @@ object python_interpreter_t::import_option(const string& str) } catch (const error_already_set&) { PyErr_Print(); - throw_(std::runtime_error, _("Python failed to import: %1") << str); + throw_(std::runtime_error, _f("Python failed to import: %1%") % str); } catch (...) { throw; @@ -582,7 +582,7 @@ value_t python_interpreter_t::functor_t::operator()(call_scope_t& args) } else if (PyErr_Occurred()) { PyErr_Print(); - throw_(calc_error, _("Failed call to Python function '%1'") << name); + throw_(calc_error, _f("Failed call to Python function '%1%'") % name); } else { assert(false); } @@ -595,7 +595,7 @@ value_t python_interpreter_t::functor_t::operator()(call_scope_t& args) catch (const error_already_set&) { std::signal(SIGINT, sigint_handler); PyErr_Print(); - throw_(calc_error, _("Failed call to Python function '%1'") << name); + throw_(calc_error, _f("Failed call to Python function '%1%'") % name); } catch (...) { std::signal(SIGINT, sigint_handler); diff --git a/src/query.cc b/src/query.cc index 3fec708a..07f724fd 100644 --- a/src/query.cc +++ b/src/query.cc @@ -79,7 +79,7 @@ query_t::lexer_t::next_token(query_t::lexer_t::token_t::kind_t tok_context) pat.push_back(*arg_i); } if (! found_closing) - throw_(parse_error, _("Expected '%1' at end of pattern") << closing); + throw_(parse_error, _f("Expected '%1%' at end of pattern") % closing); if (pat.empty()) throw_(parse_error, _("Match pattern is empty")); @@ -229,9 +229,9 @@ void query_t::lexer_t::token_t::unexpected() case END_REACHED: throw_(parse_error, _("Unexpected end of expression")); case TERM: - throw_(parse_error, _("Unexpected string '%1'") << *value); + throw_(parse_error, _f("Unexpected string '%1%'") % *value); default: - throw_(parse_error, _("Unexpected token '%1'") << symbol()); + throw_(parse_error, _f("Unexpected token '%1%'") % symbol()); } } @@ -243,12 +243,12 @@ void query_t::lexer_t::token_t::expected(char wanted, char c) if (wanted == '\0' || wanted == -1) throw_(parse_error, _("Unexpected end")); else - throw_(parse_error, _("Missing '%1'") << wanted); + throw_(parse_error, _f("Missing '%1%'") % wanted); } else { if (wanted == '\0' || wanted == -1) - throw_(parse_error, _("Invalid char '%1'") << c); + throw_(parse_error, _f("Invalid char '%1%'") % c); else - throw_(parse_error, _("Invalid char '%1' (wanted '%2')") << c << wanted); + throw_(parse_error, _f("Invalid char '%1%' (wanted '%2%')") % c % wanted); } } @@ -278,7 +278,7 @@ query_t::parser_t::parse_query_term(query_t::lexer_t::token_t::kind_t tok_contex node = parse_query_term(tok.kind); if (! node) throw_(parse_error, - _("%1 operator not followed by argument") << tok.symbol()); + _f("%1% operator not followed by argument") % tok.symbol()); break; case lexer_t::token_t::TERM: @@ -374,7 +374,7 @@ query_t::parser_t::parse_unary_expr(lexer_t::token_t::kind_t tok_context) expr_t::ptr_op_t term(parse_query_term(tok_context)); if (! term) throw_(parse_error, - _("%1 operator not followed by argument") << tok.symbol()); + _f("%1% operator not followed by argument") % tok.symbol()); node = new expr_t::op_t(expr_t::op_t::O_NOT); node->set_left(term); @@ -403,7 +403,7 @@ query_t::parser_t::parse_and_expr(lexer_t::token_t::kind_t tok_context) node->set_right(parse_unary_expr(tok_context)); if (! node->right()) throw_(parse_error, - _("%1 operator not followed by argument") << tok.symbol()); + _f("%1% operator not followed by argument") % tok.symbol()); } else { lexer.push_token(tok); break; @@ -427,7 +427,7 @@ query_t::parser_t::parse_or_expr(lexer_t::token_t::kind_t tok_context) node->set_right(parse_and_expr(tok_context)); if (! node->right()) throw_(parse_error, - _("%1 operator not followed by argument") << tok.symbol()); + _f("%1% operator not followed by argument") % tok.symbol()); } else { lexer.push_token(tok); break; diff --git a/src/report.cc b/src/report.cc index c7559cf7..c80a2f0f 100644 --- a/src/report.cc +++ b/src/report.cc @@ -591,15 +591,15 @@ value_t report_t::fn_get_at(call_scope_t& args) } else if (! args[0].is_sequence()) { throw_(std::runtime_error, - _("Attempting to get argument at index %1 from %2") - << index << args[0].label()); + _f("Attempting to get argument at index %1% from %2%") + % index % args[0].label()); } value_t::sequence_t& seq(args[0].as_sequence_lval()); if (index >= seq.size()) throw_(std::runtime_error, - _("Attempting to get index %1 from %2 with %3 elements") - << index << args[0].label() << seq.size()); + _f("Attempting to get index %1% from %2% with %3% elements") + % index % args[0].label() % seq.size()); return seq[index]; } @@ -852,8 +852,8 @@ value_t report_t::fn_nail_down(call_scope_t& args) } default: - throw_(std::runtime_error, _("Attempting to nail down %1") - << args[0].label()); + throw_(std::runtime_error, _f("Attempting to nail down %1%") + % args[0].label()); } return arg0; } diff --git a/src/report.h b/src/report.h index d04b3e15..085cfa48 100644 --- a/src/report.h +++ b/src/report.h @@ -434,7 +434,7 @@ public: OTHER(limit_).on(whence, predicate); } else { throw_(std::invalid_argument, - _("Could not determine beginning of period '%1'") << str); + _f("Could not determine beginning of period '%1%'") % str); } }); @@ -651,8 +651,8 @@ public: parent->terminus = datetime_t(*end); } else { throw_(std::invalid_argument, - _("Could not determine end of period '%1'") - << str); + _f("Could not determine end of period '%1%'") + % str); } }); @@ -770,8 +770,8 @@ public: ledger::epoch = parent->terminus = datetime_t(*begin); } else { throw_(std::invalid_argument, - _("Could not determine beginning of period '%1'") - << str); + _f("Could not determine beginning of period '%1%'") + % str); } }); @@ -1002,7 +1002,7 @@ public: format_t::default_style = format_t::TRUNCATE_TRAILING; else throw_(std::invalid_argument, - _("Unrecognized truncation style: '%1'") << style); + _f("Unrecognized truncation style: '%1%'") % style); format_t::default_style_changed = true; }); diff --git a/src/scope.cc b/src/scope.cc index 00327159..9112040c 100644 --- a/src/scope.cc +++ b/src/scope.cc @@ -58,7 +58,7 @@ void symbol_scope_t::define(const symbol_t::kind_t kind, (symbol_t(kind, name, def), def)); if (! result.second) throw_(compile_error, - _("Redefinition of '%1' in the same scope") << name); + _f("Redefinition of '%1%' in the same scope") % name); } } @@ -88,8 +88,8 @@ value_t& call_scope_t::resolve(const std::size_t index, context_scope_t scope(*this, context, required); value = as_expr(value)->calc(scope, locus, depth); if (required && ! value.is_type(context)) - throw_(calc_error, _("Expected %1 for argument %2, but received %3") - << value.label(context) << index << value.label()); + throw_(calc_error, _f("Expected %1% for argument %2%, but received %3%") + % value.label(context) % index % value.label()); } return value; } diff --git a/src/stats.cc b/src/stats.cc index 0966fee2..a12420b6 100644 --- a/src/stats.cc +++ b/src/stats.cc @@ -55,15 +55,12 @@ value_t report_statistics(call_scope_t& args) assert(is_valid(statistics.earliest_post)); assert(is_valid(statistics.latest_post)); - { - straccstream accum; - out << ACCUM(accum << _("Time period: %1 to %2 (%3 days)") - << format_date(statistics.earliest_post) - << format_date(statistics.latest_post) - << (statistics.latest_post - - statistics.earliest_post).days()) - << std::endl << std::endl; - } + out << format(_f("Time period: %1% to %2% (%3% days)") + % format_date(statistics.earliest_post) + % format_date(statistics.latest_post) + % (statistics.latest_post - + statistics.earliest_post).days()) + << std::endl << std::endl; out << _(" Files these postings came from:") << std::endl; diff --git a/src/system.hh.in b/src/system.hh.in index 552a591a..8b8fef7f 100644 --- a/src/system.hh.in +++ b/src/system.hh.in @@ -117,12 +117,6 @@ typedef std::ostream::pos_type ostream_pos_type; #include <sys/types.h> #include <sys/wait.h> #endif -#if defined(HAVE_GETTEXT) -#include "gettext.h" -#define _(str) gettext(str) -#else -#define _(str) str -#endif #include <gmp.h> #include <mpfr.h> @@ -152,6 +146,8 @@ typedef std::ostream::pos_type ostream_pos_type; #if !(defined(__GXX_EXPERIMENTAL_CXX0X__) && __GXX_EXPERIMENTAL_CXX0X__) #include <boost/foreach.hpp> #endif + +#include <boost/format.hpp> #include <boost/function.hpp> #include <boost/graph/adjacency_list.hpp> @@ -193,6 +189,15 @@ typedef std::ostream::pos_type ostream_pos_type; #include <boost/variant.hpp> #include <boost/version.hpp> +#if defined(HAVE_GETTEXT) +#include "gettext.h" +#define _(str) gettext(str) +#define _f(str) boost::format(gettext(str)) +#else +#define _(str) str +#define _f(str) boost::format(str) +#endif + #if defined(HAVE_BOOST_SERIALIZATION) #include <boost/archive/binary_iarchive.hpp> diff --git a/src/textual.cc b/src/textual.cc index 011e45b7..1665d4dd 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -271,10 +271,10 @@ void instance_t::parse() instances.push_front(instance); foreach (instance_t * instance, instances) - add_error_context(_("In file included from %1") - << instance->context.location()); + add_error_context(_f("In file included from %1%") + % instance->context.location()); } - add_error_context(_("While parsing file %1") << context.location()); + add_error_context(_f("While parsing file %1%") % context.location()); if (caught_signal != NONE_CAUGHT) throw; @@ -544,7 +544,7 @@ void instance_t::option_directive(char * line) path abs_path(filesystem::absolute(context.pathname, context.current_directory)); if (! process_option(abs_path.string(), line + 2, *context.scope, p, line)) - throw_(option_error, _("Illegal option --%1") << line + 2); + throw_(option_error, _f("Illegal option --%1%") % (line + 2)); } void instance_t::automated_xact_directive(char * line) @@ -813,7 +813,7 @@ void instance_t::include_directive(char * line) if (! files_found) throw_(std::runtime_error, - _("File to include was not found: %1") << filename); + _f("File to include was not found: %1%") % filename); } @@ -886,15 +886,15 @@ void instance_t::end_apply_directive(char * kind) _("'end' or 'end apply' found, but no enclosing 'apply' directive")); } else { throw_(std::runtime_error, - _("'end apply %1' found, but no enclosing 'apply' directive") - << name); + _f("'end apply %1%' found, but no enclosing 'apply' directive") + % name); } } if (! name.empty() && name != apply_stack.front().label) throw_(std::runtime_error, - _("'end apply %1' directive does not match 'apply %2' directive") - << name << apply_stack.front().label); + _f("'end apply %1%' directive does not match 'apply %2%' directive") + % name % apply_stack.front().label); if (apply_stack.front().value.type() == typeid(optional<datetime_t>)) epoch = boost::get<optional<datetime_t> >(apply_stack.front().value); @@ -1142,14 +1142,14 @@ void instance_t::assert_directive(char * line) { expr_t expr(line); if (! expr.calc(*context.scope).to_boolean()) - throw_(parse_error, _("Assertion failed: %1") << line); + throw_(parse_error, _f("Assertion failed: %1%") % line); } void instance_t::check_directive(char * line) { expr_t expr(line); if (! expr.calc(*context.scope).to_boolean()) - context.warning(STR(_("Check failed: %1") << line)); + context.warning(_f("Check failed: %1%") % line); } void instance_t::value_directive(char * line) @@ -1624,7 +1624,7 @@ post_t * instance_t::parse_post(char * line, if (! post->amount.is_null()) { diff -= post->amount; if (! diff.is_zero()) - throw_(parse_error, _("Balance assertion off by %1") << diff); + throw_(parse_error, _f("Balance assertion off by %1%") % diff); } else { post->amount = diff; DEBUG("textual.parse", "line " << context.linenum << ": " @@ -1654,8 +1654,8 @@ post_t * instance_t::parse_post(char * line, if (next && *next) throw_(parse_error, - _("Unexpected char '%1' (Note: inline math requires parentheses)") - << *next); + _f("Unexpected char '%1%' (Note: inline math requires parentheses)") + % *next); post->pos->end_pos = context.curr_pos; post->pos->end_line = context.linenum; @@ -1838,9 +1838,9 @@ xact_t * instance_t::parse_xact(char * line, } else if (! expr.calc(bound_scope).to_boolean()) { if (c == 'a') { - throw_(parse_error, _("Transaction assertion failed: %1") << p); + throw_(parse_error, _f("Transaction assertion failed: %1%") % p); } else { - context.warning(STR(_("Transaction check failed: %1") << p)); + context.warning(_f("Transaction check failed: %1%") % p); } } } diff --git a/src/times.cc b/src/times.cc index 30da301f..6bf2af82 100644 --- a/src/times.cc +++ b/src/times.cc @@ -230,7 +230,7 @@ namespace { if (! *p || *p != *q) break; } if (*p != '\0' || *q != '\0') - throw_(date_error, _("Invalid date: %1") << date_str); + throw_(date_error, _f("Invalid date: %1%") % date_str); if (traits) *traits = io.traits; @@ -260,7 +260,7 @@ namespace { return when; } - throw_(date_error, _("Invalid date: %1") << date_str); + throw_(date_error, _f("Invalid date: %1%") % date_str); return date_t(); } } @@ -329,7 +329,7 @@ datetime_t parse_datetime(const char * str) if (when.is_not_a_date_time()) { when = timelog_datetime_io->parse(buf); if (when.is_not_a_date_time()) { - throw_(date_error, _("Invalid date/time: %1") << str); + throw_(date_error, _f("Invalid date/time: %1%") % str); } } return when; @@ -1682,7 +1682,7 @@ void date_parser_t::lexer_t::token_t::unexpected() default: { string desc = to_string(); kind = UNKNOWN; - throw_(date_error, _("Unexpected date period token '%1'") << desc); + throw_(date_error, _f("Unexpected date period token '%1%'") % desc); } } } @@ -1693,12 +1693,12 @@ void date_parser_t::lexer_t::token_t::expected(char wanted, char c) if (wanted == '\0' || wanted == -1) throw_(date_error, _("Unexpected end")); else - throw_(date_error, _("Missing '%1'") << wanted); + throw_(date_error, _f("Missing '%1%'") % wanted); } else { if (wanted == '\0' || wanted == -1) - throw_(date_error, _("Invalid char '%1'") << c); + throw_(date_error, _f("Invalid char '%1%'") % c); else - throw_(date_error, _("Invalid char '%1' (wanted '%2')") << c << wanted); + throw_(date_error, _f("Invalid char '%1%' (wanted '%2%')") % c % wanted); } } diff --git a/src/token.cc b/src/token.cc index 1392c29f..1c43af32 100644 --- a/src/token.cc +++ b/src/token.cc @@ -479,26 +479,26 @@ void expr_t::token_t::unexpected(const char wanted) case TOK_EOF: throw_(parse_error, _("Unexpected end of expression")); case IDENT: - throw_(parse_error, _("Unexpected symbol '%1'") << value); + throw_(parse_error, _f("Unexpected symbol '%1%'") % value); case VALUE: - throw_(parse_error, _("Unexpected value '%1'") << value); + throw_(parse_error, _f("Unexpected value '%1%'") % value); default: - throw_(parse_error, _("Unexpected expression token '%1'") << symbol); + throw_(parse_error, _f("Unexpected expression token '%1%'") % symbol); } } else { switch (prev_kind) { case TOK_EOF: throw_(parse_error, - _("Unexpected end of expression (wanted '%1')") << wanted); + _f("Unexpected end of expression (wanted '%1%')") % wanted); case IDENT: throw_(parse_error, - _("Unexpected symbol '%1' (wanted '%2')") << value << wanted); + _f("Unexpected symbol '%1%' (wanted '%2%')") % value % wanted); case VALUE: throw_(parse_error, - _("Unexpected value '%1' (wanted '%2')") << value << wanted); + _f("Unexpected value '%1%' (wanted '%2%')") % value % wanted); default: - throw_(parse_error, _("Unexpected expression token '%1' (wanted '%2')") - << symbol << wanted); + throw_(parse_error, _f("Unexpected expression token '%1%' (wanted '%2%')") + % symbol % wanted); } } } @@ -509,13 +509,13 @@ void expr_t::token_t::expected(const char wanted, char c) if (wanted == '\0' || wanted == -1) throw_(parse_error, _("Unexpected end")); else - throw_(parse_error, _("Missing '%1'") << wanted); + throw_(parse_error, _f("Missing '%1%'") % wanted); } else { if (wanted == '\0' || wanted == -1) - throw_(parse_error, _("Invalid char '%1'") << c); + throw_(parse_error, _f("Invalid char '%1%'") % c); else throw_(parse_error, - _("Invalid char '%1' (wanted '%2')") << c << wanted); + _f("Invalid char '%1%' (wanted '%2%')") % c % wanted); } } @@ -523,10 +523,10 @@ void expr_t::token_t::expected(const kind_t wanted) { try { if (wanted == '\0' || wanted == -1) - throw_(parse_error, _("Invalid token '%1'") << *this); + throw_(parse_error, _f("Invalid token '%1%'") % *this); else throw_(parse_error, - _("Invalid token '%1' (wanted '%2')") << *this << wanted); + _f("Invalid token '%1%' (wanted '%2%')") % *this % wanted); } catch (...) { kind = ERROR; diff --git a/src/utils.cc b/src/utils.cc index ada6b600..d8cba61e 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -393,7 +393,7 @@ void trace_dtor_func(void * ptr, const char * cls_name, std::size_t cls_size) objects_map::iterator i = live_objects->find(ptr); if (i == live_objects->end()) { - warning_(_("Attempting to delete %1 a non-living %2") << ptr << cls_name); + warning_(_f("Attempting to delete %1% a non-living %2%") % ptr % cls_name); memory_tracing_active = true; return; } @@ -408,7 +408,7 @@ void trace_dtor_func(void * ptr, const char * cls_name, std::size_t cls_size) object_count_map::iterator k = live_object_count->find(cls_name); if (k == live_object_count->end()) { - warning_(_("Failed to find %1 in live object counts") << cls_name); + warning_(_f("Failed to find %1% in live object counts") % cls_name); memory_tracing_active = true; return; } @@ -572,7 +572,7 @@ strings_list split_arguments(const char * line) if (in_quoted_string) throw_(std::logic_error, - _("Unterminated string, expected '%1'") << in_quoted_string); + _f("Unterminated string, expected '%1%'") % in_quoted_string); if (q != buf) { *q = '\0'; diff --git a/src/value.cc b/src/value.cc index 2b1b561f..b475b6a2 100644 --- a/src/value.cc +++ b/src/value.cc @@ -103,8 +103,8 @@ value_t::operator bool() const std::ostringstream out; out << *this; throw_(value_error, - _("Cannot determine truth of %1 (did you mean 'account =~ %2'?)") - << label() << out.str()); + _f("Cannot determine truth of %1% (did you mean 'account =~ %2%'?)") + % label() % out.str()); } case SEQUENCE: if (! as_sequence().empty()) { @@ -120,8 +120,8 @@ value_t::operator bool() const return ! as_any().empty(); } - add_error_context(_("While taking boolean value of %1:") << *this); - throw_(value_error, _("Cannot determine truth of %1") << label()); + add_error_context(_f("While taking boolean value of %1%:") % *this); + throw_(value_error, _f("Cannot determine truth of %1%") % label()); return false; } @@ -307,8 +307,8 @@ value_t value_t::number() const break; } - add_error_context(_("While calling number() on %1:") << *this); - throw_(value_error, _("Cannot determine numeric value of %1") << label()); + add_error_context(_f("While calling number() on %1%:") % *this); + throw_(value_error, _f("Cannot determine numeric value of %1%") % label()); return false; } @@ -331,7 +331,7 @@ value_t& value_t::operator+=(const value_t& val) for (; i != end(); i++, j++) *i += *j; } else { - add_error_context(_("While adding %1 to %2:") << val << *this); + add_error_context(_f("While adding %1% to %2%:") % val % *this); throw_(value_error, _("Cannot add sequences of different lengths")); } } else { @@ -442,8 +442,8 @@ value_t& value_t::operator+=(const value_t& val) break; } - add_error_context(_("While adding %1 to %2:") << val << *this); - throw_(value_error, _("Cannot add %1 to %2") << val.label() << label()); + add_error_context(_f("While adding %1% to %2%:") % val % *this); + throw_(value_error, _f("Cannot add %1% to %2%") % val.label() % label()); return *this; } @@ -461,7 +461,7 @@ value_t& value_t::operator-=(const value_t& val) for (; i != end(); i++, j++) *i -= *j; } else { - add_error_context(_("While subtracting %1 from %2:") << val << *this); + add_error_context(_f("While subtracting %1% from %2%:") % val % *this); throw_(value_error, _("Cannot subtract sequences of different lengths")); } } else { @@ -582,8 +582,8 @@ value_t& value_t::operator-=(const value_t& val) break; } - add_error_context(_("While subtracting %1 from %2:") << val << *this); - throw_(value_error, _("Cannot subtract %1 from %2") << val.label() << label()); + add_error_context(_f("While subtracting %1% from %2%:") % val % *this); + throw_(value_error, _f("Cannot subtract %1% from %2%") % val.label() % label()); return *this; } @@ -664,8 +664,8 @@ value_t& value_t::operator*=(const value_t& val) break; } - add_error_context(_("While multiplying %1 with %2:") << val << *this); - throw_(value_error, _("Cannot multiply %1 with %2") << label() << val.label()); + add_error_context(_f("While multiplying %1% with %2%:") % val % *this); + throw_(value_error, _f("Cannot multiply %1% with %2%") % label() % val.label()); return *this; } @@ -742,8 +742,8 @@ value_t& value_t::operator/=(const value_t& val) break; } - add_error_context(_("While dividing %1 by %2:") << *this << val); - throw_(value_error, _("Cannot divide %1 by %2") << label() << val.label()); + add_error_context(_f("While dividing %1% by %2%:") % *this % val); + throw_(value_error, _f("Cannot divide %1% by %2%") % label() % val.label()); return *this; } @@ -828,8 +828,8 @@ bool value_t::is_equal_to(const value_t& val) const break; } - add_error_context(_("While comparing equality of %1 and %2:") << *this << val); - throw_(value_error, _("Cannot compare %1 to %2") << label() << val.label()); + add_error_context(_f("While comparing equality of %1% and %2%:") % *this % val); + throw_(value_error, _f("Cannot compare %1% to %2%") % label() % val.label()); return *this; } @@ -948,8 +948,8 @@ bool value_t::is_less_than(const value_t& val) const break; } - add_error_context(_("While comparing if %1 is less than %2:") << *this << val); - throw_(value_error, _("Cannot compare %1 to %2") << label() << val.label()); + add_error_context(_f("While comparing if %1% is less than %2%:") % *this % val); + throw_(value_error, _f("Cannot compare %1% to %2%") % label() % val.label()); return *this; } @@ -1063,8 +1063,8 @@ bool value_t::is_greater_than(const value_t& val) const break; } - add_error_context(_("While comparing if %1 is greater than %2:") << *this << val); - throw_(value_error, _("Cannot compare %1 to %2") << label() << val.label()); + add_error_context(_f("While comparing if %1% is greater than %2%:") % *this % val); + throw_(value_error, _f("Cannot compare %1% to %2%") % label() % val.label()); return *this; } @@ -1205,9 +1205,9 @@ void value_t::in_place_cast(type_t cast_type) return; } else { - add_error_context(_("While converting %1 to an amount:") << *this); - throw_(value_error, _("Cannot convert %1 with multiple commodities to %2") - << label() << label(cast_type)); + add_error_context(_f("While converting %1% to an amount:") % *this); + throw_(value_error, _f("Cannot convert %1% with multiple commodities to %2%") + % label() % label(cast_type)); } break; } @@ -1263,9 +1263,9 @@ void value_t::in_place_cast(type_t cast_type) break; } - add_error_context(_("While converting %1:") << *this); + add_error_context(_f("While converting %1%:") % *this); throw_(value_error, - _("Cannot convert %1 to %2") << label() << label(cast_type)); + _f("Cannot convert %1% to %2%") % label() % label(cast_type)); } void value_t::in_place_negate() @@ -1295,8 +1295,8 @@ void value_t::in_place_negate() break; } - add_error_context(_("While negating %1:") << *this); - throw_(value_error, _("Cannot negate %1") << label()); + add_error_context(_f("While negating %1%:") % *this); + throw_(value_error, _f("Cannot negate %1%") % label()); } void value_t::in_place_not() @@ -1329,8 +1329,8 @@ void value_t::in_place_not() break; } - add_error_context(_("While applying not to %1:") << *this); - throw_(value_error, _("Cannot 'not' %1") << label()); + add_error_context(_f("While applying not to %1%:") % *this); + throw_(value_error, _f("Cannot 'not' %1%") % label()); } bool value_t::is_realzero() const @@ -1359,8 +1359,8 @@ bool value_t::is_realzero() const return as_any().empty(); default: - add_error_context(_("While applying is_realzero to %1:") << *this); - throw_(value_error, _("Cannot determine if %1 is really zero") << label()); + add_error_context(_f("While applying is_realzero to %1%:") % *this); + throw_(value_error, _f("Cannot determine if %1% is really zero") % label()); } return false; } @@ -1391,8 +1391,8 @@ bool value_t::is_zero() const return as_any().empty(); default: - add_error_context(_("While applying is_zero to %1:") << *this); - throw_(value_error, _("Cannot determine if %1 is zero") << label()); + add_error_context(_f("While applying is_zero to %1%:") % *this); + throw_(value_error, _f("Cannot determine if %1% is zero") % label()); } return false; } @@ -1425,8 +1425,8 @@ value_t value_t::value(const datetime_t& moment, break; } - add_error_context(_("While finding valuation of %1:") << *this); - throw_(value_error, _("Cannot find the value of %1") << label()); + add_error_context(_f("While finding valuation of %1%:") % *this); + throw_(value_error, _f("Cannot find the value of %1%") % label()); return NULL_VALUE; } @@ -1544,7 +1544,7 @@ void value_t::in_place_reduce() return; } - //throw_(value_error, "Cannot reduce " << label()); + //throw_(value_error, _f("Cannot reduce %1%") % label()); } void value_t::in_place_unreduce() @@ -1564,7 +1564,7 @@ void value_t::in_place_unreduce() return; } - //throw_(value_error, "Cannot reduce " << label()); + //throw_(value_error, _f("Cannot reduce %1%") % label()); } value_t value_t::abs() const @@ -1584,8 +1584,8 @@ value_t value_t::abs() const break; } - add_error_context(_("While taking abs of %1:") << *this); - throw_(value_error, _("Cannot abs %1") << label()); + add_error_context(_f("While taking abs of %1%:") % *this); + throw_(value_error, _f("Cannot abs %1%") % label()); return NULL_VALUE; } @@ -1608,8 +1608,8 @@ void value_t::in_place_round() break; } - add_error_context(_("While rounding %1:") << *this); - throw_(value_error, _("Cannot set rounding for %1") << label()); + add_error_context(_f("While rounding %1%:") % *this); + throw_(value_error, _f("Cannot set rounding for %1%") % label()); } void value_t::in_place_truncate() @@ -1631,8 +1631,8 @@ void value_t::in_place_truncate() break; } - add_error_context(_("While truncating %1:") << *this); - throw_(value_error, _("Cannot truncate %1") << label()); + add_error_context(_f("While truncating %1%:") % *this); + throw_(value_error, _f("Cannot truncate %1%") % label()); } void value_t::in_place_floor() @@ -1654,8 +1654,8 @@ void value_t::in_place_floor() break; } - add_error_context(_("While flooring %1:") << *this); - throw_(value_error, _("Cannot floor %1") << label()); + add_error_context(_f("While flooring %1%:") % *this); + throw_(value_error, _f("Cannot floor %1%") % label()); } void value_t::in_place_unround() @@ -1677,8 +1677,8 @@ void value_t::in_place_unround() break; } - add_error_context(_("While unrounding %1:") << *this); - throw_(value_error, _("Cannot unround %1") << label()); + add_error_context(_f("While unrounding %1%:") % *this); + throw_(value_error, _f("Cannot unround %1%") % label()); } void value_t::annotate(const annotation_t& details) @@ -1686,8 +1686,8 @@ void value_t::annotate(const annotation_t& details) if (is_amount()) { as_amount_lval().annotate(details); } else { - add_error_context(_("While attempting to annotate %1:") << *this); - throw_(value_error, _("Cannot annotate %1") << label()); + add_error_context(_f("While attempting to annotate %1%:") % *this); + throw_(value_error, _f("Cannot annotate %1%") % label()); } } @@ -1696,9 +1696,9 @@ bool value_t::has_annotation() const if (is_amount()) { return as_amount().has_annotation(); } else { - add_error_context(_("While checking if %1 has annotations:") << *this); + add_error_context(_f("While checking if %1% has annotations:") % *this); throw_(value_error, - _("Cannot determine whether %1 is annotated") << label()); + _f("Cannot determine whether %1% is annotated") % label()); } return false; } @@ -1708,8 +1708,8 @@ annotation_t& value_t::annotation() if (is_amount()) { return as_amount_lval().annotation(); } else { - add_error_context(_("While requesting the annotations of %1:") << *this); - throw_(value_error, _("Cannot request annotation of %1") << label()); + add_error_context(_f("While requesting the annotations of %1%:") % *this); + throw_(value_error, _f("Cannot request annotation of %1%") % label()); return as_amount_lval().annotation(); // quiet g++ warning } } diff --git a/src/xact.cc b/src/xact.cc index 226fd5ab..07ca7911 100644 --- a/src/xact.cc +++ b/src/xact.cc @@ -184,8 +184,8 @@ bool xact_base_t::finalize() if (post_account_bad || null_post_account_bad) throw_(std::logic_error, - _("Posting with null amount's account may be mispelled:\n \"%1\"") - << (post_account_bad ? post->account->fullname() : + _f("Posting with null amount's account may be mispelled:\n \"%1%\"") + % (post_account_bad ? post->account->fullname() : null_post->account->fullname())); else throw_(std::logic_error, @@ -706,10 +706,9 @@ void auto_xact_t::extend_xact(xact_base_t& xact, parse_context_t& context) else if (! pair.first.calc(bound_scope).to_boolean()) { if (pair.second == expr_t::EXPR_ASSERTION) throw_(parse_error, - _("Transaction assertion failed: %1") << pair.first); + _f("Transaction assertion failed: %1%") % pair.first); else - context.warning(STR(_("Transaction check failed: %1") - << pair.first)); + context.warning(_f("Transaction check failed: %1%") % pair.first); } } } @@ -129,7 +129,7 @@ public: virtual string description() { if (pos) { std::ostringstream buf; - buf << _("transaction at line %1") << pos->beg_line; + buf << _f("transaction at line %1") << pos->beg_line; return buf.str(); } else { return string(_("generated transaction")); @@ -220,7 +220,7 @@ private: virtual string description() { if (pos) { std::ostringstream buf; - buf << _("automated transaction at line %1") << pos->beg_line; + buf << _f("automated transaction at line %1") << pos->beg_line; return buf.str(); } else { return string(_("generated automated transaction")); @@ -278,7 +278,7 @@ class period_xact_t : public xact_base_t virtual string description() { if (pos) { std::ostringstream buf; - buf << _("periodic transaction at line %1") << pos->beg_line; + buf << _f("periodic transaction at line %1") << pos->beg_line; return buf.str(); } else { return string(_("generated periodic transaction")); diff --git a/tools/Makefile.am b/tools/Makefile.am index 04f64530..507607fc 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -20,7 +20,6 @@ libledger_util_la_SOURCES = \ src/times.cc \ src/error.cc \ src/utils.cc \ - src/accum.cc \ lib/sha1.cpp libledger_util_la_CPPFLAGS = $(lib_cppflags) @@ -95,7 +94,6 @@ pkginclude_HEADERS = \ src/stream.h \ src/pstream.h \ src/unistring.h \ - src/accum.h \ \ src/amount.h \ src/commodity.h \ |