a little cleanup; reversed the meaning of -z and -p (to be more mnemonic)

This commit is contained in:
John Wiegley 2004-08-23 18:23:31 -04:00
parent 632a37034a
commit 73e2abd1b2
8 changed files with 39 additions and 32 deletions

View file

@ -585,15 +585,17 @@ amount_t amount_t::round(unsigned int prec) const
} }
} }
std::ostream& operator<<(std::ostream& out, const amount_t& amt) std::ostream& operator<<(std::ostream& _out, const amount_t& amt)
{ {
if (! amt.quantity)
return _out;
std::ostringstream out;
mpz_t quotient; mpz_t quotient;
mpz_t rquotient; mpz_t rquotient;
mpz_t remainder; mpz_t remainder;
if (! amt.quantity)
return out;
mpz_init(quotient); mpz_init(quotient);
mpz_init(rquotient); mpz_init(rquotient);
mpz_init(remainder); mpz_init(remainder);
@ -710,14 +712,9 @@ std::ostream& operator<<(std::ostream& out, const amount_t& amt)
mpz_clear(rquotient); mpz_clear(rquotient);
mpz_clear(remainder); mpz_clear(remainder);
return out; _out << out.str();
}
amount_t::operator std::string() const return _out;
{
std::ostringstream s;
s << *this;
return s.str();
} }
void parse_quantity(std::istream& in, std::string& value) void parse_quantity(std::istream& in, std::string& value)

View file

@ -162,8 +162,6 @@ class amount_t
negate(); negate();
} }
operator std::string() const;
void parse(std::istream& in); void parse(std::istream& in);
void parse(const std::string& str) { void parse(const std::string& str) {
std::istringstream stream(str); std::istringstream stream(str);

View file

@ -75,7 +75,7 @@ void balance_t::write(std::ostream& out,
out.width(width); out.width(width);
out.fill(' '); out.fill(' ');
out << std::right << std::string(**i); out << std::right << **i;
} }
if (first) { if (first) {

View file

@ -60,7 +60,7 @@ Basic options:\n\
--cache FILE use FILE as a binary cache when --file is not used\n\ --cache FILE use FILE as a binary cache when --file is not used\n\
-f, --file FILE read ledger data from FILE\n\ -f, --file FILE read ledger data from FILE\n\
-o, --output FILE write output to FILE\n\ -o, --output FILE write output to FILE\n\
-p, --set-price CONV specify a commodity conversion: \"COMM=AMOUNT\"\n\ -z, --set-price CONV specify a commodity conversion: \"COMM=AMOUNT\"\n\
-a, --account NAME specify the default account (useful with QIF files)\n\n\ -a, --account NAME specify the default account (useful with QIF files)\n\n\
Report filtering:\n\ Report filtering:\n\
-b, --begin-date DATE set report begin date\n\ -b, --begin-date DATE set report begin date\n\
@ -80,7 +80,7 @@ Output customization:\n\
-n, --collapse register: collapse entries with multiple transactions\n\ -n, --collapse register: collapse entries with multiple transactions\n\
-s, --subtotal balance: show sub-accounts; register: show subtotals\n\ -s, --subtotal balance: show sub-accounts; register: show subtotals\n\
-S, --sort EXPR sort report according to the value expression EXPR\n\ -S, --sort EXPR sort report according to the value expression EXPR\n\
-z, --interval STR report by interval, based on interval expression STR\n\ -p, --interval STR report by interval (period), based on STR\n\
--dow show a days-of-the-week report\n\ --dow show a days-of-the-week report\n\
-W, --weekly show weekly sub-totals\n\ -W, --weekly show weekly sub-totals\n\
-M, --monthly show monthly sub-totals\n\ -M, --monthly show monthly sub-totals\n\
@ -149,7 +149,7 @@ OPT_BEGIN(output, "o:") {
config->output_file = optarg; config->output_file = optarg;
} OPT_END(output); } OPT_END(output);
OPT_BEGIN(set_price, "p:") { OPT_BEGIN(set_price, "z:") {
if (std::strchr(optarg, '=')) if (std::strchr(optarg, '='))
config->price_settings.push_back(optarg); config->price_settings.push_back(optarg);
else else
@ -260,7 +260,7 @@ OPT_BEGIN(related, "r") {
config->show_related = true; config->show_related = true;
} OPT_END(related); } OPT_END(related);
OPT_BEGIN(interval, "z:") { OPT_BEGIN(interval, "p:") {
config->interval_text = optarg; config->interval_text = optarg;
} OPT_END(interval); } OPT_END(interval);

View file

@ -13,8 +13,8 @@ AC_PROG_MAKE_SET
AC_PROG_RANLIB AC_PROG_RANLIB
# Checks for libraries. # Checks for libraries.
AC_CHECK_LIB([gmp], [__gmpz_add]) AC_CHECK_LIB([gmp], [__gmpz_add],, [AC_MSG_FAILURE("Could not find libgmp!")])
AC_CHECK_LIB([pcre], [pcre_compile]) AC_CHECK_LIB([pcre], [pcre_compile],, [AC_MSG_FAILURE("Could not find libpcre!")])
AC_CHECK_LIB([xmlparse], [XML_ParserCreate]) AC_CHECK_LIB([xmlparse], [XML_ParserCreate])
# Checks for header files. # Checks for header files.

View file

@ -223,7 +223,7 @@ void format_t::format_elements(std::ostream& out,
out << *((unsigned int *) value.data); out << *((unsigned int *) value.data);
break; break;
case value_t::AMOUNT: case value_t::AMOUNT:
out << std::string(*((amount_t *) value.data)); out << *((amount_t *) value.data);
break; break;
case value_t::BALANCE: case value_t::BALANCE:
((balance_t *) value.data)->write(out, elem->min_width, ((balance_t *) value.data)->write(out, elem->min_width,
@ -337,7 +337,8 @@ void format_t::format_elements(std::ostream& out,
} }
if (! use_disp) if (! use_disp)
disp = std::string(details.xact->amount); out << details.xact->amount;
else
out << disp; out << disp;
// jww (2004-07-31): this should be handled differently // jww (2004-07-31): this should be handled differently

View file

@ -336,9 +336,8 @@ your init file.
entries on or after @samp{DATE}. Only entries after that date will be entries on or after @samp{DATE}. Only entries after that date will be
calculated, which means that the running total in the balance report calculated, which means that the running total in the balance report
will always start at zero with the first matching entry. (Note: This will always start at zero with the first matching entry. (Note: This
is different from using @samp{--display} to constrain the entries is different from using @samp{--display} to constrain what is
displayed, in which case the running total includes the undisplayed displayed).
entries).
@sp 1 @sp 1
@ -446,9 +445,19 @@ transaction that matched.
@sp 1 @sp 1
@samp{--limit EXPR} (@samp{-l EXPR}) @samp{--limit EXPR} (@samp{-l EXPR}) limits which transactions take
part in the calculations of a report.
@samp{--display EXPR} (@samp{-d EXPR}) @samp{--display EXPR} (@samp{-d EXPR}) limits which transactions or
accounts or actually displayed in a report. They might still be
calculated, and be part of the running total of a register report, for
example, but they will not be displayed. This is useful for seeing
last month's checking transactions, against a running balance that
includes all past transactions:
@example
ledger -d "d>=[2004/8]" reg checking
@end example
@sp 1 @sp 1

View file

@ -500,6 +500,7 @@ int main(int argc, char * argv[], char * envp[])
// filter_transactions will only pass through transactions // filter_transactions will only pass through transactions
// matching the `display_predicate'. // matching the `display_predicate'.
if (! config->display_predicate.empty())
formatter.reset(new filter_transactions(formatter.release(), formatter.reset(new filter_transactions(formatter.release(),
config->display_predicate)); config->display_predicate));
@ -560,6 +561,7 @@ int main(int argc, char * argv[], char * envp[])
// This filter_transactions will only pass through transactions // This filter_transactions will only pass through transactions
// matching the `predicate'. // matching the `predicate'.
if (! config->predicate.empty())
formatter.reset(new filter_transactions(formatter.release(), formatter.reset(new filter_transactions(formatter.release(),
config->predicate)); config->predicate));