summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2004-08-22 02:40:18 -0400
committerJohn Wiegley <johnw@newartisans.com>2004-08-22 02:40:18 -0400
commit02168c782364a1a8641b4bed7ebf4a84cb6b3560 (patch)
treef3e31f99245871413587d3eb0ad1fa5974bf9558
parent5619a1d5be144877df8cce01c40ff668bbb0c96a (diff)
downloadfork-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.cc41
-rw-r--r--config.h12
-rw-r--r--format.cc16
-rw-r--r--option.h8
-rw-r--r--textual.cc7
5 files changed, 65 insertions, 19 deletions
diff --git a/config.cc b/config.cc
index e1f52a61..12f8b240 100644
--- a/config.cc
+++ b/config.cc
@@ -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);
diff --git a/config.h b/config.h
index 799e1d30..b8677b1a 100644
--- a/config.h
+++ b/config.h
@@ -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
{
diff --git a/format.cc b/format.cc
index a26ce631..90fbf388 100644
--- a/format.cc
+++ b/format.cc
@@ -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;
diff --git a/option.h b/option.h
index c930fc09..9952d7d5 100644
--- a/option.h
+++ b/option.h
@@ -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
diff --git a/textual.cc b/textual.cc
index df45d2ce..fa7f28d0 100644
--- a/textual.cc
+++ b/textual.cc
@@ -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;
}