diff options
author | John Wiegley <johnw@newartisans.com> | 2004-08-22 02:40:18 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2004-08-22 02:40:18 -0400 |
commit | 02168c782364a1a8641b4bed7ebf4a84cb6b3560 (patch) | |
tree | f3e31f99245871413587d3eb0ad1fa5974bf9558 | |
parent | 5619a1d5be144877df8cce01c40ff668bbb0c96a (diff) | |
download | fork-ledger-02168c782364a1a8641b4bed7ebf4a84cb6b3560.tar.gz fork-ledger-02168c782364a1a8641b4bed7ebf4a84cb6b3560.tar.bz2 fork-ledger-02168c782364a1a8641b4bed7ebf4a84cb6b3560.zip |
escape codes in format strings; can now redefine individual report formats
-rw-r--r-- | config.cc | 41 | ||||
-rw-r--r-- | config.h | 12 | ||||
-rw-r--r-- | format.cc | 16 | ||||
-rw-r--r-- | option.h | 8 | ||||
-rw-r--r-- | textual.cc | 7 |
5 files changed, 65 insertions, 19 deletions
@@ -5,15 +5,15 @@ namespace ledger { config_t * config = NULL; -const std::string bal_fmt = "%20T %2_%-n\n"; -const std::string reg_fmt +std::string bal_fmt = "%20T %2_%-n\n"; +std::string reg_fmt = "%D %-.20P %-.22N %12.66t %12.80T\n\ %/ %-.22N %12.66t %12.80T\n"; -const std::string plot_value_fmt = "%D %t\n"; -const std::string plot_total_fmt = "%D %T\n"; -const std::string print_fmt +std::string plot_value_fmt = "%D %t\n"; +std::string plot_total_fmt = "%D %T\n"; +std::string print_fmt = "\n%D %X%C%P\n %-34N %12o\n%/ %-34N %12o\n"; -const std::string equity_fmt +std::string equity_fmt = "\n%D %X%C%P\n%/ %-34N %12t\n"; config_t::config_t() @@ -71,7 +71,10 @@ Report filtering:\n\ -R, --real consider only non-virtual transactions\n\n\ -r, --related calculate report using related transactions\n\ Output customization:\n\ - -F, --format STR use STR as the report format\n\ + -F, --format STR use STR as the format; for each report type, use:\n\ + --balance-format --equity-format\n\ + --register-format --plot-value-format\n\ + --print-format --plot-total-format\n\ -y, --date-format STR use STR as the date format (def: %Y/%m/%d)\n\ -E, --empty balance: show accounts with zero balance\n\ -n, --collapse register: collapse entries with multiple transactions\n\ @@ -213,6 +216,30 @@ OPT_BEGIN(date_format, "y:") { config->date_format = optarg; } OPT_END(date_format); +OPT_BEGIN(balance_format, ":") { + bal_fmt = optarg; +} OPT_END(balance_format); + +OPT_BEGIN(register_format, ":") { + reg_fmt = optarg; +} OPT_END(register_format); + +OPT_BEGIN(plot_value_format, ":") { + plot_value_fmt = optarg; +} OPT_END(plot_value_format); + +OPT_BEGIN(plot_total_format, ":") { + plot_total_fmt = optarg; +} OPT_END(plot_total_format); + +OPT_BEGIN(print_format, ":") { + print_fmt = optarg; +} OPT_END(print_format); + +OPT_BEGIN(equity_format, ":") { + equity_fmt = optarg; +} OPT_END(equity_format); + OPT_BEGIN(empty, "E") { config->show_empty = true; } OPT_END(empty); @@ -8,12 +8,12 @@ namespace ledger { -extern const std::string bal_fmt; -extern const std::string reg_fmt; -extern const std::string plot_value_fmt; -extern const std::string plot_total_fmt; -extern const std::string print_fmt; -extern const std::string equity_fmt; +extern std::string bal_fmt; +extern std::string reg_fmt; +extern std::string plot_value_fmt; +extern std::string plot_total_fmt; +extern std::string print_fmt; +extern std::string equity_fmt; struct config_t { @@ -53,7 +53,7 @@ element_t * format_t::parse_elements(const std::string& fmt) char * q = buf; for (const char * p = fmt.c_str(); *p; p++) { - if (*p != '%') { + if (*p != '%' && *p != '\\') { *q++ = *p; continue; } @@ -75,6 +75,20 @@ element_t * format_t::parse_elements(const std::string& fmt) current = current->next; } + if (*p == '\\') { + p++; + current->type = element_t::STRING; + switch (*p) { + case 'b': current->chars = "\b"; break; + case 'f': current->chars = "\f"; break; + case 'n': current->chars = "\n"; break; + case 'r': current->chars = "\r"; break; + case 't': current->chars = "\t"; break; + case 'v': current->chars = "\v"; break; + } + continue; + } + ++p; if (*p == '-') { current->align_left = true; @@ -41,11 +41,11 @@ void process_environment(char ** envp, const std::string& tag); std::vector<option_t> option_handler::options; \ option_handler_map option_handler::handlers -#define OPT_BEGIN(tag, chars) \ - static struct tag ## _handler : public option_handler { \ - tag ## _handler() : option_handler(#tag, chars) {} \ +#define OPT_BEGIN(tag, chars) \ + static struct opt_ ## tag ## _handler : public option_handler { \ + opt_ ## tag ## _handler() : option_handler(#tag, chars) {} \ virtual void handle_option(const char * optarg) -#define OPT_END(tag) } tag ## _handler_obj +#define OPT_END(tag) } opt_ ## tag ## _handler_obj #endif // _OPTION_H @@ -71,14 +71,19 @@ transaction_t * parse_transaction_text(char * line, account_t * account, } char * price_str = std::strchr(cost_str, '@'); + bool per_unit = true; if (price_str) { *price_str++ = '\0'; + if (*price_str == '@') { + per_unit = false; + price_str++; + } xact->cost = new amount_t; xact->cost->parse(price_str); } xact->amount.parse(cost_str); - if (price_str) + if (price_str && per_unit) *xact->cost *= xact->amount; } |