diff --git a/Makefile b/Makefile index d6a971f4..0ececcd5 100644 --- a/Makefile +++ b/Makefile @@ -16,9 +16,8 @@ CODE = amount.cc \ OBJS = $(patsubst %.cc,%.o,$(CODE)) CFLAGS = -Wall -ansi -pedantic -#DFLAGS = -O3 -fomit-frame-pointer -DFLAGS = -g -O2 # -pg -INCS = -I/usr/include/xmltok +DFLAGS = -g -O2 # -O3 -fomit-frame-pointer -mcpu=pentium +INCS = LIBS = -lgmpxx -lgmp -lpcre ifdef HUQUQ @@ -28,6 +27,7 @@ endif ifdef GNUCASH CODE := $(CODE) gnucash.cc CFLAGS := $(CFLAGS) -DREAD_GNUCASH=1 +INCS := $(INCS) -I/usr/include/xmltok LIBS := $(LIBS) -lxmlparse endif diff --git a/amount.cc b/amount.cc index 695c4226..6098ebde 100644 --- a/amount.cc +++ b/amount.cc @@ -64,14 +64,8 @@ class gmp_amount : public amount } virtual void credit(const amount * other); - virtual void parse(const char * num) { - *this = num; - } - virtual amount& operator=(const char * num); + virtual void parse(const char * num); virtual std::string as_str(bool full_prec) const; - virtual operator std::string() const { - return as_str(false); - } friend amount * create_amount(const char * value, const amount * cost); }; @@ -565,7 +559,7 @@ static commodity * parse_amount(mpz_t out, const char * num, return comm; } -amount& gmp_amount::operator=(const char * num) +void gmp_amount::parse(const char * num) { // Compile the regular expression used for parsing amounts static pcre * re = NULL; @@ -594,7 +588,6 @@ amount& gmp_amount::operator=(const char * num) } else { std::cerr << "Failed to parse amount: " << num << std::endl; } - return *this; } void gmp_amount::credit(const amount * value) diff --git a/balance.cc b/balance.cc index df8e2172..dedfa5bb 100644 --- a/balance.cc +++ b/balance.cc @@ -20,10 +20,10 @@ static bool account_matches(const account * acct, const std::list& regexps, bool * true_match) { - bool match = true; + bool match = false; + *true_match = false; if (show_children) { - match = false; for (const account * a = acct; a; a = a->parent) { bool exclude = false; if (matches(regexps, a->name, &exclude)) { @@ -36,7 +36,8 @@ static bool account_matches(const account * acct, } } else { match = matches(regexps, acct->as_str()); - *true_match = matches(regexps, acct->name); + if (match) + *true_match = matches(regexps, acct->name); } return match; } @@ -134,7 +135,6 @@ void report_balances(int argc, char **argv, std::ostream& out) else if (acct->checked == 3) continue; - acct->checked = 1; acct->balance.credit((*x)->cost->street()); } } diff --git a/gnucash.cc b/gnucash.cc index 357ba97d..a056b352 100644 --- a/gnucash.cc +++ b/gnucash.cc @@ -44,7 +44,7 @@ static void startElement(void *userData, const char *name, const char **atts) { if (std::strcmp(name, "gnc:account") == 0) { assert(! curr_account); - curr_account = new account(name); + curr_account = new account; } else if (std::strcmp(name, "act:name") == 0) action = ACCOUNT_NAME; @@ -111,14 +111,8 @@ static void endElement(void *userData, const char *name) } else if (std::strcmp(name, "gnc:transaction") == 0) { assert(curr_entry); - if (! curr_entry->validate()) { - std::cerr << "Failed to balance the following transaction, " - << "ending on line " - << XML_GetCurrentLineNumber(current_parser) << std::endl; - curr_entry->print(std::cerr); - } else { - main_ledger.entries.push_back(curr_entry); - } + assert(curr_entry->validate()); + main_ledger.entries.push_back(curr_entry); curr_entry = NULL; } action = NO_ACTION; @@ -195,7 +189,6 @@ static void dataHandler(void *userData, const char *s, int len) accounts_iterator i = accounts_by_id.find(std::string(s, len)); if (i == accounts_by_id.end()) { std::cerr << "Could not find account " << std::string(s, len) - << " at line " << XML_GetCurrentLineNumber(current_parser) << std::endl; std::exit(1); } @@ -203,9 +196,9 @@ static void dataHandler(void *userData, const char *s, int len) transaction * xact = curr_entry->xacts.back(); xact->acct = (*i).second; - std::string value = curr_quant + " " + (*i).second->comm->symbol; + std::string value = curr_quant + " " + xact->acct->comm->symbol; - if (curr_value->comm() == (*i).second->comm) { + if (curr_value->comm() == xact->acct->comm) { // assert: value must be equal to curr_value. delete curr_value; curr_value = NULL; diff --git a/ledger.cc b/ledger.cc index 91f2a273..ef7a9d94 100644 --- a/ledger.cc +++ b/ledger.cc @@ -136,7 +136,7 @@ void totals::print(std::ostream& out, int width) const out << std::endl; out.width(width); - out << std::right << *((*i).second); + out << std::right << (*i).second->as_str(); } } diff --git a/ledger.h b/ledger.h index 5cb5e3f7..e074f82e 100644 --- a/ledger.h +++ b/ledger.h @@ -1,5 +1,5 @@ #ifndef _LEDGER_H -#define _LEDGER_H "$Revision: 1.15 $" +#define _LEDGER_H "$Revision: 1.16 $" ////////////////////////////////////////////////////////////////////// // @@ -139,17 +139,9 @@ class amount // String conversion routines virtual void parse(const char * num) = 0; - virtual amount& operator=(const char * num) = 0; virtual std::string as_str(bool full_prec = false) const = 0; - virtual operator std::string() const = 0; }; -template -std::basic_ostream & -operator<<(std::basic_ostream& out, const amount& a) { - return (out << std::string(a)); -} - extern amount * create_amount(const char * value, const amount * cost = NULL); @@ -294,6 +286,11 @@ struct account accounts_t children; + account() : parent(NULL), checked(0) { +#ifdef HUQUQULLAH + exempt_or_necessary = false; +#endif + } account(const std::string& _name, struct account * _parent = NULL) : parent(_parent), name(_name), checked(0) { #ifdef HUQUQULLAH diff --git a/ledger.texi b/ledger.texi index 437a54da..722c63d1 100644 --- a/ledger.texi +++ b/ledger.texi @@ -1,5 +1,5 @@ \input texinfo @c -*-texinfo-*- -@comment $Id: ledger.texi,v 1.6 2003/10/01 22:11:23 johnw Exp $ +@comment $Id: ledger.texi,v 1.7 2003/10/02 00:07:14 johnw Exp $ @comment %**start of header @setfilename ledger.info @@ -329,10 +329,6 @@ would look like: Now you've turned 2 steaks into 15 gold, courtesy of your customer, Sturm Brightblade. -Note that if you're playing on a system where ``Gold'' is the standard -currency, you should use the @samp{-D} flag to tell @code{ledger} that -that is the default commodity. - @chapter Using @code{ledger} @chapter Computing Huqúqu'lláh diff --git a/main.cc b/main.cc index 07471cec..2ecaaecb 100644 --- a/main.cc +++ b/main.cc @@ -127,7 +127,7 @@ int main(int argc, char *argv[]) show_cleared = false; int c; - while (-1 != (c = getopt(argc, argv, "+b:e:d:D:cChHwf:i:p:Pv"))) { + while (-1 != (c = getopt(argc, argv, "+b:e:d:cChHwf:i:p:Pv"))) { switch (char(c)) { case 'b': case 'e': { @@ -289,23 +289,6 @@ int main(int argc, char *argv[]) const std::string command = argv[optind]; -#ifdef HUQUQULLAH - if (command == "register" && argv[optind + 1] && - std::string(argv[optind + 1]) != "Huququ'llah" && - std::string(argv[optind + 1]) != "Expenses:Huququ'llah") - compute_huquq = false; - - if (compute_huquq) { - main_ledger.compute_huquq = true; - - read_regexps(".huquq", main_ledger.huquq_categories); - - main_ledger.huquq_account = main_ledger.find_account("Huququ'llah"); - main_ledger.huquq_expenses_account = - main_ledger.find_account("Expenses:Huququ'llah"); - } -#endif - // Parse the ledger #ifdef READ_GNUCASH @@ -317,7 +300,26 @@ int main(int argc, char *argv[]) parse_gnucash(*file, command == "equity"); else #endif + { +#ifdef HUQUQULLAH + if (command == "register" && argv[optind + 1] && + std::string(argv[optind + 1]) != "Huququ'llah" && + std::string(argv[optind + 1]) != "Expenses:Huququ'llah") + compute_huquq = false; + + if (compute_huquq) { + main_ledger.compute_huquq = true; + + read_regexps(".huquq", main_ledger.huquq_categories); + + main_ledger.huquq_account = main_ledger.find_account("Huququ'llah"); + main_ledger.huquq_expenses_account = + main_ledger.find_account("Expenses:Huququ'llah"); + } +#endif + parse_ledger(*file, command == "equity"); + } #ifdef DO_CLEANUP delete file;