diff options
author | John Wiegley <johnw@newartisans.com> | 2008-08-05 05:00:31 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-08-05 05:00:31 -0400 |
commit | 7455495d14c6e97e860cb8b0a6f1cd552e8cd791 (patch) | |
tree | ee23a7cf33fd2b3494fecb522c76350489e54626 | |
parent | 806be999ef1f86020b355e4832ea1ac6e5f9adfa (diff) | |
download | fork-ledger-7455495d14c6e97e860cb8b0a6f1cd552e8cd791.tar.gz fork-ledger-7455495d14c6e97e860cb8b0a6f1cd552e8cd791.tar.bz2 fork-ledger-7455495d14c6e97e860cb8b0a6f1cd552e8cd791.zip |
Moved the option code for 2.6.1 from option.cc into report.h. It's still
commented out, but now it's nearer the right place for conversion.
-rw-r--r-- | option.cc | 543 | ||||
-rw-r--r-- | report.cc | 4 | ||||
-rw-r--r-- | report.h | 557 |
3 files changed, 548 insertions, 556 deletions
@@ -210,546 +210,3 @@ void process_arguments(int, char ** argv, const bool anywhere, } } // namespace ledger - -#if 0 -////////////////////////////////////////////////////////////////////// -// -// Basic options - -OPT_BEGIN(full_help, "H") { - option_full_help(std::cout); - throw 0; -} OPT_END(full_help); - -OPT_BEGIN(help, "h") { - option_help(std::cout); - throw 0; -} OPT_END(help); - -OPT_BEGIN(help_calc, "") { - option_calc_help(std::cout); - throw 0; -} OPT_END(help_calc); - -OPT_BEGIN(help_disp, "") { - option_disp_help(std::cout); - throw 0; -} OPT_END(help_disp); - -OPT_BEGIN(help_comm, "") { - option_comm_help(std::cout); - throw 0; -} OPT_END(help_comm); - -OPT_BEGIN(version, "v") { - show_version(std::cout); - throw 0; -} OPT_END(version); - -OPT_BEGIN(init_file, "i:") { - std::string path = resolve_path(optarg); - if (access(path.c_str(), R_OK) != -1) - config->init_file = path; - else - throw_(std::invalid_argument, - "The init file '" << path << "' does not exist or is not readable"); -} OPT_END(init_file); - -OPT_BEGIN(file, "f:") { - if (std::string(optarg) == "-") { - config->data_file = optarg; - } else { - std::string path = resolve_path(optarg); - if (access(path.c_str(), R_OK) != -1) - config->data_file = path; - else - throw_(std::invalid_argument, - "The ledger file '" << path << "' does not exist or is not readable"); - } -} OPT_END(file); - -OPT_BEGIN(cache, ":") { - config->cache_file = resolve_path(optarg); -} OPT_END(cache); - -OPT_BEGIN(no_cache, "") { - config->cache_file = "<none>"; -} OPT_END(no_cache); - -OPT_BEGIN(output, "o:") { - if (std::string(optarg) != "-") { - std::string path = resolve_path(optarg); - report->output_file = path; - } -} OPT_END(output); - -OPT_BEGIN(account, "a:") { - config->account = optarg; -} OPT_END(account); - -OPT_BEGIN(debug, ":") { - config->debug_mode = true; - ::setenv("DEBUG_CLASS", optarg, 1); -} OPT_END(debug); - -OPT_BEGIN(verbose, "") { - config->verbose_mode = true; -} OPT_END(verbose); - -OPT_BEGIN(trace, "") { - config->trace_mode = true; -} OPT_END(trace); - -////////////////////////////////////////////////////////////////////// -// -// Report filtering - -OPT_BEGIN(effective, "") { - xact_t::use_effective_date = true; -} OPT_END(effective); - -OPT_BEGIN(begin, "b:") { - char buf[128]; - interval_t interval(optarg); - if (! interval.begin) - throw_(std::invalid_argument, - "Could not determine beginning of period '" << optarg << "'"); - - if (! report->predicate.empty()) - report->predicate += "&"; - report->predicate += "d>=["; - report->predicate += interval.begin.to_string(); - report->predicate += "]"; -} OPT_END(begin); - -OPT_BEGIN(end, "e:") { - char buf[128]; - interval_t interval(optarg); - if (! interval.begin) - throw_(std::invalid_argument, - "Could not determine end of period '" << optarg << "'"); - - if (! report->predicate.empty()) - report->predicate += "&"; - report->predicate += "d<["; - report->predicate += interval.begin.to_string(); - report->predicate += "]"; - - terminus = interval.begin; -} OPT_END(end); - -OPT_BEGIN(current, "c") { - if (! report->predicate.empty()) - report->predicate += "&"; - report->predicate += "d<=m"; -} OPT_END(current); - -OPT_BEGIN(cleared, "C") { - if (! report->predicate.empty()) - report->predicate += "&"; - report->predicate += "X"; -} OPT_END(cleared); - -OPT_BEGIN(uncleared, "U") { - if (! report->predicate.empty()) - report->predicate += "&"; - report->predicate += "!X"; -} OPT_END(uncleared); - -OPT_BEGIN(real, "R") { - if (! report->predicate.empty()) - report->predicate += "&"; - report->predicate += "R"; -} OPT_END(real); - -OPT_BEGIN(actual, "L") { - if (! report->predicate.empty()) - report->predicate += "&"; - report->predicate += "L"; -} OPT_END(actual); - -OPT_BEGIN(lots, "") { - report->keep_price = - report->keep_date = - report->keep_tag = true; -} OPT_END(lots); - -OPT_BEGIN(lot_prices, "") { - report->keep_price = true; -} OPT_END(lots_prices); - -OPT_BEGIN(lot_dates, "") { - report->keep_date = true; -} OPT_END(lots_dates); - -OPT_BEGIN(lot_tags, "") { - report->keep_tag = true; -} OPT_END(lots_tags); - -////////////////////////////////////////////////////////////////////// -// -// Output customization - -OPT_BEGIN(format, "F:") { - report->format_string = optarg; -} OPT_END(format); - -OPT_BEGIN(date_format, "y:") { - report->date_output_format = optarg; -} OPT_END(date_format); - -OPT_BEGIN(input_date_format, ":") { - config->date_input_format = optarg; -} OPT_END(input_date_format); - -OPT_BEGIN(balance_format, ":") { - config->balance_format = optarg; -} OPT_END(balance_format); - -OPT_BEGIN(register_format, ":") { - config->register_format = optarg; -} OPT_END(register_format); - -OPT_BEGIN(wide_register_format, ":") { - config->wide_register_format = optarg; -} OPT_END(wide_register_format); - -OPT_BEGIN(plot_amount_format, ":") { - config->plot_amount_format = optarg; -} OPT_END(plot_amount_format); - -OPT_BEGIN(plot_total_format, ":") { - config->plot_total_format = optarg; -} OPT_END(plot_total_format); - -OPT_BEGIN(print_format, ":") { - config->print_format = optarg; -} OPT_END(print_format); - -OPT_BEGIN(write_hdr_format, ":") { - config->write_hdr_format = optarg; -} OPT_END(write_hdr_format); - -OPT_BEGIN(write_xact_format, ":") { - config->write_xact_format = optarg; -} OPT_END(write_xact_format); - -OPT_BEGIN(equity_format, ":") { - config->equity_format = optarg; -} OPT_END(equity_format); - -OPT_BEGIN(prices_format, ":") { - config->prices_format = optarg; -} OPT_END(prices_format); - -OPT_BEGIN(wide, "w") { - config->register_format = config->wide_register_format; -} OPT_END(wide); - -OPT_BEGIN(head, ":") { - report->head_entries = std::atoi(optarg); -} OPT_END(head); - -OPT_BEGIN(tail, ":") { - report->tail_entries = std::atoi(optarg); -} OPT_END(tail); - -OPT_BEGIN(pager, ":") { - config->pager = optarg; -} OPT_END(pager); - -OPT_BEGIN(truncate, ":") { - std::string style(optarg); - if (style == "leading") - format_t::elision_style = format_t::TRUNCATE_LEADING; - else if (style == "middle") - format_t::elision_style = format_t::TRUNCATE_MIDDLE; - else if (style == "trailing") - format_t::elision_style = format_t::TRUNCATE_TRAILING; - else if (style == "abbrev") - format_t::elision_style = format_t::ABBREVIATE; -} OPT_END(truncate); - -OPT_BEGIN(abbrev_len, ":") { - format_t::abbrev_length = std::atoi(optarg); -} OPT_END(abbrev_len); - -OPT_BEGIN(empty, "E") { - report->show_empty = true; -} OPT_END(empty); - -OPT_BEGIN(collapse, "n") { - report->show_collapsed = true; -} OPT_END(collapse); - -OPT_BEGIN(subtotal, "s") { - report->show_subtotal = true; -} OPT_END(subtotal); - -OPT_BEGIN(totals, "") { - report->show_totals = true; -} OPT_END(totals); - -OPT_BEGIN(sort, "S:") { - report->sort_string = optarg; -} OPT_END(sort); - -OPT_BEGIN(sort_entries, "") { - report->sort_string = optarg; - report->entry_sort = true; -} OPT_END(sort_entries); - -OPT_BEGIN(sort_all, "") { - report->sort_string = optarg; - report->entry_sort = false; - report->sort_all = true; -} OPT_END(sort_all); - -OPT_BEGIN(period_sort, ":") { - report->sort_string = optarg; - report->entry_sort = true; -} OPT_END(period_sort); - -OPT_BEGIN(related, "r") { - report->show_related = true; -} OPT_END(related); - -OPT_BEGIN(descend, "") { - std::string arg(optarg); - std::string::size_type beg = 0; - report->descend_expr = ""; - for (std::string::size_type pos = arg.find(';'); - pos != std::string::npos; - beg = pos + 1, pos = arg.find(';', beg)) - report->descend_expr += (std::string("t=={") + - std::string(arg, beg, pos - beg) + "};"); - report->descend_expr += (std::string("t=={") + - std::string(arg, beg) + "}"); -} OPT_END(descend); - -OPT_BEGIN(descend_if, "") { - report->descend_expr = optarg; -} OPT_END(descend_if); - -OPT_BEGIN(period, "p:") { - if (report->report_period.empty()) { - report->report_period = optarg; - } else { - report->report_period += " "; - report->report_period += optarg; - } - - // If the period gives a beginning and/or ending date, make sure to - // modify the calculation predicate (via the --begin and --end - // options) to take this into account. - - interval_t interval(report->report_period); - - if (interval.begin) { - if (! report->predicate.empty()) - report->predicate += "&"; - report->predicate += "d>=["; - report->predicate += interval.begin.to_string(); - report->predicate += "]"; - } - - if (interval.end) { - if (! report->predicate.empty()) - report->predicate += "&"; - report->predicate += "d<["; - report->predicate += interval.end.to_string(); - report->predicate += "]"; - - terminus = interval.end; - } -} OPT_END(period); - -OPT_BEGIN(daily, "") { - if (report->report_period.empty()) - report->report_period = "daily"; - else - report->report_period = std::string("daily ") + report->report_period; -} OPT_END(daily); - -OPT_BEGIN(weekly, "W") { - if (report->report_period.empty()) - report->report_period = "weekly"; - else - report->report_period = std::string("weekly ") + report->report_period; -} OPT_END(weekly); - -OPT_BEGIN(monthly, "M") { - if (report->report_period.empty()) - report->report_period = "monthly"; - else - report->report_period = std::string("monthly ") + report->report_period; -} OPT_END(monthly); - -OPT_BEGIN(quarterly, "") { - if (report->report_period.empty()) - report->report_period = "quarterly"; - else - report->report_period = std::string("quarterly ") + report->report_period; -} OPT_END(quarterly); - -OPT_BEGIN(yearly, "Y") { - if (report->report_period.empty()) - report->report_period = "yearly"; - else - report->report_period = std::string("yearly ") + report->report_period; -} OPT_END(yearly); - -OPT_BEGIN(dow, "") { - report->days_of_the_week = true; -} OPT_END(dow); - -OPT_BEGIN(by_payee, "P") { - report->by_payee = true; -} OPT_END(by_payee); - -OPT_BEGIN(comm_as_payee, "x") { - report->comm_as_payee = true; -} OPT_END(comm_as_payee); - -OPT_BEGIN(code_as_payee, "") { - report->code_as_payee = true; -} OPT_END(code_as_payee); - -OPT_BEGIN(budget, "") { - report->budget_flags = BUDGET_BUDGETED; -} OPT_END(budget); - -OPT_BEGIN(add_budget, "") { - report->budget_flags = BUDGET_BUDGETED | BUDGET_UNBUDGETED; -} OPT_END(add_budget); - -OPT_BEGIN(unbudgeted, "") { - report->budget_flags = BUDGET_UNBUDGETED; -} OPT_END(unbudgeted); - -OPT_BEGIN(forecast, ":") { - report->forecast_limit = optarg; -} OPT_END(forecast); - -OPT_BEGIN(reconcile, ":") { - report->reconcile_balance = optarg; -} OPT_END(reconcile); - -OPT_BEGIN(reconcile_date, ":") { - report->reconcile_date = optarg; -} OPT_END(reconcile_date); - -OPT_BEGIN(limit, "l:") { - if (! report->predicate.empty()) - report->predicate += "&"; - report->predicate += "("; - report->predicate += optarg; - report->predicate += ")"; -} OPT_END(limit); - -OPT_BEGIN(only, ":") { - if (! report->secondary_predicate.empty()) - report->secondary_predicate += "&"; - report->secondary_predicate += "("; - report->secondary_predicate += optarg; - report->secondary_predicate += ")"; -} OPT_END(only); - -OPT_BEGIN(display, "d:") { - if (! report->display_predicate.empty()) - report->display_predicate += "&"; - report->display_predicate += "("; - report->display_predicate += optarg; - report->display_predicate += ")"; -} OPT_END(display); - -OPT_BEGIN(amount, "t:") { - ledger::amount_expr = optarg; -} OPT_END(amount); - -OPT_BEGIN(total, "T:") { - ledger::total_expr = optarg; -} OPT_END(total); - -OPT_BEGIN(amount_data, "j") { - report->format_string = config->plot_amount_format; -} OPT_END(amount_data); - -OPT_BEGIN(total_data, "J") { - report->format_string = config->plot_total_format; -} OPT_END(total_data); - -OPT_BEGIN(ansi, "") { - format_t::ansi_codes = true; - format_t::ansi_invert = false; -} OPT_END(ansi); - -OPT_BEGIN(ansi_invert, "") { - format_t::ansi_codes = - format_t::ansi_invert = true; -} OPT_END(ansi); - -////////////////////////////////////////////////////////////////////// -// -// Commodity reporting - -OPT_BEGIN(base, ":") { - amount_t::keep_base = true; -} OPT_END(base); - -OPT_BEGIN(price_db, ":") { - config->price_db = optarg; -} OPT_END(price_db); - -OPT_BEGIN(price_exp, "Z:") { - config->pricing_leeway = std::atol(optarg) * 60; -} OPT_END(price_exp); - -OPT_BEGIN(download, "Q") { - config->download_quotes = true; -} OPT_END(download); - -OPT_BEGIN(quantity, "O") { - ledger::amount_expr = "a"; - ledger::total_expr = "O"; -} OPT_END(quantity); - -OPT_BEGIN(basis, "B") { - ledger::amount_expr = "b"; - ledger::total_expr = "B"; -} OPT_END(basis); - -OPT_BEGIN(price, "I") { - ledger::amount_expr = "i"; - ledger::total_expr = "I"; -} OPT_END(price); - -OPT_BEGIN(market, "V") { - report->show_revalued = true; - - ledger::amount_expr = "v"; - ledger::total_expr = "V"; -} OPT_END(market); - -namespace { - void parse_price_setting(const char * optarg) - { - char * equals = std::strchr(optarg, '='); - if (! equals) - return; - - while (std::isspace(*optarg)) - optarg++; - while (equals > optarg && std::isspace(*(equals - 1))) - equals--; - - std::string symbol(optarg, 0, equals - optarg); - amount_t price(equals + 1); - - if (commodity_t * commodity = commodity_t::find_or_create(symbol)) { - commodity->add_price(datetime_t::now, price); - commodity->history()->bogus_time = datetime_t::now; - } - } -} -#endif @@ -354,10 +354,6 @@ void report_t::commodities_report(const string& format) { } -void report_t::entry_report(const entry_t& entry, const string& format) -{ -} - value_t report_t::get_amount_expr(call_scope_t& scope) { return amount_expr.calc(scope); @@ -177,21 +177,15 @@ public: // Actual report generation; this is why we're here... // - xact_handler_ptr - chain_xact_handlers(xact_handler_ptr handler, - const bool handle_individual_transactions = true); - void xacts_report(xact_handler_ptr handler); - void entry_report(xact_handler_ptr handler, entry_t& entry); - void sum_all_accounts(); - void accounts_report(acct_handler_ptr handler); - void commodities_report(const string& format); - void entry_report(const entry_t& entry, const string& format); + xact_handler_ptr + chain_xact_handlers(xact_handler_ptr handler, + const bool handle_individual_transactions = true); // // Config options @@ -242,6 +236,551 @@ public: return true; } +#if 0 + ////////////////////////////////////////////////////////////////////// + // + // Basic options + + value_t option_full_help(call_scope_t& args) { // H + option_full_help(std::cout); + throw 0; + } + + value_t option_help(call_scope_t& args) { // h + option_help(std::cout); + throw 0; + } + + value_t option_help_calc(call_scope_t& args) { // + option_calc_help(std::cout); + throw 0; + } + + value_t option_help_disp(call_scope_t& args) { // + option_disp_help(std::cout); + throw 0; + } + + value_t option_help_comm(call_scope_t& args) { // + option_comm_help(std::cout); + throw 0; + } + + value_t option_version(call_scope_t& args) { // v + show_version(std::cout); + throw 0; + } + + value_t option_init_file(call_scope_t& args) { // i: + std::string path = resolve_path(optarg); + if (access(path.c_str(), R_OK) != -1) + config->init_file = path; + else + throw_(std::invalid_argument, + "The init file '" << path << "' does not exist or is not readable"); + } + + value_t option_file(call_scope_t& args) { // f: + if (std::string(optarg) == "-") { + config->data_file = optarg; + } else { + std::string path = resolve_path(optarg); + if (access(path.c_str(), R_OK) != -1) + config->data_file = path; + else + throw_(std::invalid_argument, + "The ledger file '" << path << "' does not exist or is not readable"); + } + } + + value_t option_cache(call_scope_t& args) { // : + config->cache_file = resolve_path(optarg); + } + + value_t option_no_cache(call_scope_t& args) { // + config->cache_file = "<none>"; + } + + value_t option_output(call_scope_t& args) { // o: + if (std::string(optarg) != "-") { + std::string path = resolve_path(optarg); + report->output_file = path; + } + } + + value_t option_account(call_scope_t& args) { // a: + config->account = optarg; + } + + value_t option_debug(call_scope_t& args) { // : + config->debug_mode = true; + ::setenv("DEBUG_CLASS", optarg, 1); + } + + value_t option_verbose(call_scope_t& args) { // + config->verbose_mode = true; + } + + value_t option_trace(call_scope_t& args) { // + config->trace_mode = true; + } + + ////////////////////////////////////////////////////////////////////// + // + // Report filtering + + value_t option_effective(call_scope_t& args) { // + xact_t::use_effective_date = true; + } + + value_t option_begin(call_scope_t& args) { // b: + char buf[128]; + interval_t interval(optarg); + if (! interval.begin) + throw_(std::invalid_argument, + "Could not determine beginning of period '" << optarg << "'"); + + if (! report->predicate.empty()) + report->predicate += "&"; + report->predicate += "d>=["; + report->predicate += interval.begin.to_string(); + report->predicate += "]"; + } + + value_t option_end(call_scope_t& args) { // e: + char buf[128]; + interval_t interval(optarg); + if (! interval.begin) + throw_(std::invalid_argument, + "Could not determine end of period '" << optarg << "'"); + + if (! report->predicate.empty()) + report->predicate += "&"; + report->predicate += "d<["; + report->predicate += interval.begin.to_string(); + report->predicate += "]"; + + terminus = interval.begin; + } + + value_t option_current(call_scope_t& args) { // c + if (! report->predicate.empty()) + report->predicate += "&"; + report->predicate += "d<=m"; + } + + value_t option_cleared(call_scope_t& args) { // C + if (! report->predicate.empty()) + report->predicate += "&"; + report->predicate += "X"; + } + + value_t option_uncleared(call_scope_t& args) { // U + if (! report->predicate.empty()) + report->predicate += "&"; + report->predicate += "!X"; + } + + value_t option_real(call_scope_t& args) { // R + if (! report->predicate.empty()) + report->predicate += "&"; + report->predicate += "R"; + } + + value_t option_actual(call_scope_t& args) { // L + if (! report->predicate.empty()) + report->predicate += "&"; + report->predicate += "L"; + } + + value_t option_lots(call_scope_t& args) { // + report->keep_price = + report->keep_date = + report->keep_tag = true; + } + + value_t option_lot_prices(call_scope_t& args) { // + report->keep_price = true; + } + + value_t option_lot_dates(call_scope_t& args) { // + report->keep_date = true; + } + + value_t option_lot_tags(call_scope_t& args) { // + report->keep_tag = true; + } + + ////////////////////////////////////////////////////////////////////// + // + // Output customization + + value_t option_format(call_scope_t& args) { // F: + report->format_string = optarg; + } + + value_t option_date_format(call_scope_t& args) { // y: + report->date_output_format = optarg; + } + + value_t option_input_date_format(call_scope_t& args) { // : + config->date_input_format = optarg; + } + + value_t option_balance_format(call_scope_t& args) { // : + config->balance_format = optarg; + } + + value_t option_register_format(call_scope_t& args) { // : + config->register_format = optarg; + } + + value_t option_wide_register_format(call_scope_t& args) { // : + config->wide_register_format = optarg; + } + + value_t option_plot_amount_format(call_scope_t& args) { // : + config->plot_amount_format = optarg; + } + + value_t option_plot_total_format(call_scope_t& args) { // : + config->plot_total_format = optarg; + } + + value_t option_print_format(call_scope_t& args) { // : + config->print_format = optarg; + } + + value_t option_write_hdr_format(call_scope_t& args) { // : + config->write_hdr_format = optarg; + } + + value_t option_write_xact_format(call_scope_t& args) { // : + config->write_xact_format = optarg; + } + + value_t option_equity_format(call_scope_t& args) { // : + config->equity_format = optarg; + } + + value_t option_prices_format(call_scope_t& args) { // : + config->prices_format = optarg; + } + + value_t option_wide(call_scope_t& args) { // w + config->register_format = config->wide_register_format; + } + + value_t option_head(call_scope_t& args) { // : + report->head_entries = std::atoi(optarg); + } + + value_t option_tail(call_scope_t& args) { // : + report->tail_entries = std::atoi(optarg); + } + + value_t option_pager(call_scope_t& args) { // : + config->pager = optarg; + } + + value_t option_truncate(call_scope_t& args) { // : + std::string style(optarg); + if (style == "leading") + format_t::elision_style = format_t::TRUNCATE_LEADING; + else if (style == "middle") + format_t::elision_style = format_t::TRUNCATE_MIDDLE; + else if (style == "trailing") + format_t::elision_style = format_t::TRUNCATE_TRAILING; + else if (style == "abbrev") + format_t::elision_style = format_t::ABBREVIATE; + } + + value_t option_abbrev_len(call_scope_t& args) { // : + format_t::abbrev_length = std::atoi(optarg); + } + + value_t option_empty(call_scope_t& args) { // E + report->show_empty = true; + } + + value_t option_collapse(call_scope_t& args) { // n + report->show_collapsed = true; + } + + value_t option_subtotal(call_scope_t& args) { // s + report->show_subtotal = true; + } + + value_t option_totals(call_scope_t& args) { // + report->show_totals = true; + } + + value_t option_sort(call_scope_t& args) { // S: + report->sort_string = optarg; + } + + value_t option_sort_entries(call_scope_t& args) { // + report->sort_string = optarg; + report->entry_sort = true; + } + + value_t option_sort_all(call_scope_t& args) { // + report->sort_string = optarg; + report->entry_sort = false; + report->sort_all = true; + } + + value_t option_period_sort(call_scope_t& args) { // : + report->sort_string = optarg; + report->entry_sort = true; + } + + value_t option_related(call_scope_t& args) { // r + report->show_related = true; + } + + value_t option_descend(call_scope_t& args) { // + std::string arg(optarg); + std::string::size_type beg = 0; + report->descend_expr = ""; + for (std::string::size_type pos = arg.find(';'); + pos != std::string::npos; + beg = pos + 1, pos = arg.find(';', beg)) + report->descend_expr += (std::string("t=={") + + std::string(arg, beg, pos - beg) + "};"); + report->descend_expr += (std::string("t=={") + + std::string(arg, beg) + "}"); + } + + value_t option_descend_if(call_scope_t& args) { // + report->descend_expr = optarg; + } + + value_t option_period(call_scope_t& args) { // p: + if (report->report_period.empty()) { + report->report_period = optarg; + } else { + report->report_period += " "; + report->report_period += optarg; + } + + // If the period gives a beginning and/or ending date, make sure to + // modify the calculation predicate (via the --begin and --end + // options) to take this into account. + + interval_t interval(report->report_period); + + if (interval.begin) { + if (! report->predicate.empty()) + report->predicate += "&"; + report->predicate += "d>=["; + report->predicate += interval.begin.to_string(); + report->predicate += "]"; + } + + if (interval.end) { + if (! report->predicate.empty()) + report->predicate += "&"; + report->predicate += "d<["; + report->predicate += interval.end.to_string(); + report->predicate += "]"; + + terminus = interval.end; + } + } + + value_t option_daily(call_scope_t& args) { // + if (report->report_period.empty()) + report->report_period = "daily"; + else + report->report_period = std::string("daily ") + report->report_period; + } + + value_t option_weekly(call_scope_t& args) { // W + if (report->report_period.empty()) + report->report_period = "weekly"; + else + report->report_period = std::string("weekly ") + report->report_period; + } + + value_t option_monthly(call_scope_t& args) { // M + if (report->report_period.empty()) + report->report_period = "monthly"; + else + report->report_period = std::string("monthly ") + report->report_period; + } + + value_t option_quarterly(call_scope_t& args) { // + if (report->report_period.empty()) + report->report_period = "quarterly"; + else + report->report_period = std::string("quarterly ") + report->report_period; + } + + value_t option_yearly(call_scope_t& args) { // Y + if (report->report_period.empty()) + report->report_period = "yearly"; + else + report->report_period = std::string("yearly ") + report->report_period; + } + + value_t option_dow(call_scope_t& args) { // + report->days_of_the_week = true; + } + + value_t option_by_payee(call_scope_t& args) { // P + report->by_payee = true; + } + + value_t option_comm_as_payee(call_scope_t& args) { // x + report->comm_as_payee = true; + } + + value_t option_code_as_payee(call_scope_t& args) { // + report->code_as_payee = true; + } + + value_t option_budget(call_scope_t& args) { // + report->budget_flags = BUDGET_BUDGETED; + } + + value_t option_add_budget(call_scope_t& args) { // + report->budget_flags = BUDGET_BUDGETED | BUDGET_UNBUDGETED; + } + + value_t option_unbudgeted(call_scope_t& args) { // + report->budget_flags = BUDGET_UNBUDGETED; + } + + value_t option_forecast(call_scope_t& args) { // : + report->forecast_limit = optarg; + } + + value_t option_reconcile(call_scope_t& args) { // : + report->reconcile_balance = optarg; + } + + value_t option_reconcile_date(call_scope_t& args) { // : + report->reconcile_date = optarg; + } + + value_t option_limit(call_scope_t& args) { // l: + if (! report->predicate.empty()) + report->predicate += "&"; + report->predicate += "("; + report->predicate += optarg; + report->predicate += ")"; + } + + value_t option_only(call_scope_t& args) { // : + if (! report->secondary_predicate.empty()) + report->secondary_predicate += "&"; + report->secondary_predicate += "("; + report->secondary_predicate += optarg; + report->secondary_predicate += ")"; + } + + value_t option_display(call_scope_t& args) { // d: + if (! report->display_predicate.empty()) + report->display_predicate += "&"; + report->display_predicate += "("; + report->display_predicate += optarg; + report->display_predicate += ")"; + } + + value_t option_amount(call_scope_t& args) { // t: + ledger::amount_expr = optarg; + } + + value_t option_total(call_scope_t& args) { // T: + ledger::total_expr = optarg; + } + + value_t option_amount_data(call_scope_t& args) { // j + report->format_string = config->plot_amount_format; + } + + value_t option_total_data(call_scope_t& args) { // J + report->format_string = config->plot_total_format; + } + + value_t option_ansi(call_scope_t& args) { // + format_t::ansi_codes = true; + format_t::ansi_invert = false; + } + + value_t option_ansi_invert(call_scope_t& args) { // + format_t::ansi_codes = + format_t::ansi_invert = true; + } + + ////////////////////////////////////////////////////////////////////// + // + // Commodity reporting + + value_t option_base(call_scope_t& args) { // : + amount_t::keep_base = true; + } + + value_t option_price_db(call_scope_t& args) { // : + config->price_db = optarg; + } + + value_t option_price_exp(call_scope_t& args) { // Z: + config->pricing_leeway = std::atol(optarg) * 60; + } + + value_t option_download(call_scope_t& args) { // Q + config->download_quotes = true; + } + + value_t option_quantity(call_scope_t& args) { // O + ledger::amount_expr = "a"; + ledger::total_expr = "O"; + } + + value_t option_basis(call_scope_t& args) { // B + ledger::amount_expr = "b"; + ledger::total_expr = "B"; + } + + value_t option_price(call_scope_t& args) { // I + ledger::amount_expr = "i"; + ledger::total_expr = "I"; + } + + value_t option_market(call_scope_t& args) { // V + report->show_revalued = true; + + ledger::amount_expr = "v"; + ledger::total_expr = "V"; + } + +#if 0 + namespace { + void parse_price_setting(const char * optarg) + { + char * equals = std::strchr(optarg, '='); + if (! equals) + return; + + while (std::isspace(*optarg)) + optarg++; + while (equals > optarg && std::isspace(*(equals - 1))) + equals--; + + std::string symbol(optarg, 0, equals - optarg); + amount_t price(equals + 1); + + if (commodity_t * commodity = commodity_t::find_or_create(symbol)) { + commodity->add_price(datetime_t::now, price); + commodity->history()->bogus_time = datetime_t::now; + } + } + } +#endif +#endif + // // Formatting functions // |