diff --git a/config.cc b/config.cc index 81c9dbd3..34802929 100644 --- a/config.cc +++ b/config.cc @@ -57,6 +57,7 @@ Basic options:\n\ -h, --help display this help text\n\ -v, --version show version information\n\ -i, --init FILE initialize ledger by loading FILE (def: ~/.ledgerrc)\n\ + --cache FILE use FILE as a binary cache when --file is not used\n\ -f, --file FILE read ledger data from FILE\n\ -o, --output FILE write output to FILE\n\ -p, --set-price CONV specify a commodity conversion: \"COMM=AMOUNT\"\n\ @@ -77,7 +78,7 @@ Output customization:\n\ -s, --subtotal balance: show sub-accounts; register: show subtotals\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\ - -w, --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\ -M, --monthly show monthly sub-totals\n\ -Y, --yearly show yearly sub-totals\n\ @@ -240,7 +241,7 @@ OPT_BEGIN(weekly, "W") { config->interval_text = "weekly"; } OPT_END(weekly); -OPT_BEGIN(dow, "w") { +OPT_BEGIN(dow, "") { config->days_of_the_week = true; } OPT_END(dow); diff --git a/ledger.texi b/ledger.texi index a1ada658..d2132c6f 100644 --- a/ledger.texi +++ b/ledger.texi @@ -1189,16 +1189,146 @@ ledger, with the attached prefix ``Billable'': * Plotting register data:: * Typical queries:: * File format:: -* Command summary:: * Using command options:: @end menu @node Commands, Options, Running Ledger, Running Ledger @section Commands +@subsection balance + +The ``balance'' command reports the current balance of all accounts. +It accepts a list of optional regexps, which confine the balance +report to the matching accounts. If an account contains multiple +types of commodities, each commodity's total is reported separately. + +@subsection register + +The ``register'' command displays all the transactions occurring in a +single account, line by line. The account regexp must be specified as +the only argument to this command. If any regexps occur after the +required account name, the register will contain only those +transactions that match. Very useful for hunting down a particular +transaction. + +The output from ``register'' is very close to what a typical checkbook, +or single account ledger, would look like. It also shows a running +balance. The final running balance of any register should always be +the same as the current balance of that account. + +@subsection print + +The ``print'' command prints out ledger entries just as they appear in +the original ledger. They will be properly formatted, and output in +the most economic form possible. The ``print'' command also takes a +list of optional regexps, which will cause only those transactions +which match in some way to be printed. + +The ``print'' command is a handy way to clean up a ledger file whose +formatting has gotten out of hand. + +@subsection equity + +Equity transactions are used to establish the starting value of an +account. You might think of equity as the ``ether'' from which initial +balances appear. + +@subsection entry + +The three most laborious tasks of keeping a ledger are: adding new +entries, reconciling accounts, and generating reports. To address the +first of these, there is a sub-command to ledger called ``entry''. It +works on the principle that 80% of all transactions are variants of +earlier transactions. Here's how it works: + +Let's say you have an old transaction of the following form: + +@example +2004/03/15 * Viva Italiano + Expenses:Food $12.45 + Expenses:Tips $2.55 + Liabilities:MasterCard $-15.00 +@end example + +Now it's 2004/4/9, and you've just eating at Viva Italiano again. The +exact amounts are different, but the overall form is the same. With +the ``entry'' command you can type: + +@example +ledger entry 2004/4/9 viva food 11.00 tips 2.50 +@end example + +This will produce the following output: + +@example +2004/04/09 Viva Italiano + Expenses:Food $11.00 + Expenses:Tips $2.50 + Liabilities:MasterCard $-13.50 +@end example + +This works by finding a transaction that matches the regexp ``viva'', +and then assuming that any accounts or amounts you specify will be the +same as that earlier transaction. If Ledger does not succeed in +generating a new entry for you, it will print an error and set the +exit code to 1. + +There is a shell script in the distribution called ``entry'', which +simplifies the task of adding a new entry to your ledger, and then +launches @samp{vi} to let you confirm that the entry looks appropriate. + @node Options, Format strings, Commands, Running Ledger @section Options +@subsection Basic options + +@samp{--help} (@samp{-h}) prints a summary of all the options, and +what they are used for. This can be a handy way to remember which +options do what. This help screen is also printed if ledger is run +without a command. + +@sp + +@samp{--version} (@samp{-v}) prints the current version of ledger and exits. +This is useful for sending bug reports (to @email{johnw@@newartisans.com}), to +let the author know which version of ledger you are using. + +@sp + +@samp{--init FILE} (@samp{-i FILE}) causes FILE to be read by ledger before any +other ledger file. This file may not contain any transactions, but it +may contain option settings. To specify options in the init file, use +the same syntax as the command-line. Here's an example init file: + +@example +--price-db ~/finance/.pricedb +@end example + +Option settings on the command-line or in the environment always take +precedence over settings in the init file. + +@sp + +@samp{--file FILE} (@samp{-f FILE}) reads FILE as a ledger file. This command +may be used multiple times. FILE may also be a list of file names +separated by colons. Typically, the environment variable +@samp{LEDGER_FILE} is set, rather than using this command-line option. + +@sp + +@samp{--cache FILE} identifies FILE as the default binary cache file. That +is, if the ledger files to be read are specified using the environment +variable @samp{LEDGER_FILE}, then whenever a command is finished a binary +copy will be written to the specified cache, to speed up the loading +time of subsequent queries. This filename can also be given using the +environment variable @samp{LEDGER_CACHE}, or by putting the option into +your init file. + +@sp + +@samp{--output FILE} (@samp{-o FILE}) redirects output from any command to +@samp{FILE}. By default, all output goes to standard output. + @subsection Environment variables Every option to ledger may be set using an environment variable. If @@ -1216,61 +1346,58 @@ environment variable settings. A value expression is a language used by ledger wherever a value is involved. Some examples are: -@itemize +@enumerate @item Values displayed in reports @item Predicates, or which transactions get calculated/displayed @item Sorting criteria, or how transactions are sorted -@end itemize +@item Matching criteria used by automated transactions +@end enumerate Value expressions support most simple math and logic operators, in addition to a set of one letter functions and variables. A function's -argument is whatever follows it. Here are some value expression -examples: - -@example -t = the transaction's value - -MT = the average total - -t*3+T = three times the amount plus the total - -At>@{$100@}?t:T = if the absolute value of the amount - is in dollars, and greater than $100, use the amount, - otherwise use the total. - -dvalue.cost; break; - case BALANCE: - if (details.xact) { - result = details.xact->total.quantity; - result -= details.xact->amount; - } - else if (details.account) { - result = details.account->total.quantity; - result -= details.account->value.quantity; - } - break; - - case COST_BALANCE: - if (details.xact) { - result = details.xact->total.cost; - result -= details.xact->cost; - } - else if (details.account) { - result = details.account->total.cost; - result -= details.account->value.cost; - } - break; - case TOTAL: if (details.xact) result = details.xact->total.quantity; @@ -411,7 +389,6 @@ value_expr_t * parse_value_term(std::istream& in) case 'R': node.reset(new value_expr_t(value_expr_t::REAL)); break; case 'n': node.reset(new value_expr_t(value_expr_t::INDEX)); break; case 'l': node.reset(new value_expr_t(value_expr_t::DEPTH)); break; - case 'B': node.reset(new value_expr_t(value_expr_t::BALANCE)); break; case 'O': node.reset(new value_expr_t(value_expr_t::TOTAL)); break; case 'C': node.reset(new value_expr_t(value_expr_t::COST_TOTAL)); break; @@ -739,8 +716,6 @@ void dump_value_expr(std::ostream& out, const value_expr_t * node) case value_expr_t::REAL: out << "REAL"; break; case value_expr_t::INDEX: out << "INDEX"; break; case value_expr_t::DEPTH: out << "DEPTH"; break; - case value_expr_t::BALANCE: out << "BALANCE"; break; - case value_expr_t::COST_BALANCE: out << "COST_BALANCE"; break; case value_expr_t::TOTAL: out << "TOTAL"; break; case value_expr_t::COST_TOTAL: out << "COST_TOTAL"; break; diff --git a/valexpr.h b/valexpr.h index d135a6b3..c7c158d1 100644 --- a/valexpr.h +++ b/valexpr.h @@ -57,8 +57,6 @@ struct value_expr_t DEPTH, // Item totals - BALANCE, - COST_BALANCE, TOTAL, COST_TOTAL,