*** empty log message ***

This commit is contained in:
John Wiegley 2003-10-02 00:07:14 +00:00
parent 3afa81857a
commit 2a10558902
8 changed files with 42 additions and 61 deletions

View file

@ -16,9 +16,8 @@ CODE = amount.cc \
OBJS = $(patsubst %.cc,%.o,$(CODE)) OBJS = $(patsubst %.cc,%.o,$(CODE))
CFLAGS = -Wall -ansi -pedantic CFLAGS = -Wall -ansi -pedantic
#DFLAGS = -O3 -fomit-frame-pointer DFLAGS = -g -O2 # -O3 -fomit-frame-pointer -mcpu=pentium
DFLAGS = -g -O2 # -pg INCS =
INCS = -I/usr/include/xmltok
LIBS = -lgmpxx -lgmp -lpcre LIBS = -lgmpxx -lgmp -lpcre
ifdef HUQUQ ifdef HUQUQ
@ -28,6 +27,7 @@ endif
ifdef GNUCASH ifdef GNUCASH
CODE := $(CODE) gnucash.cc CODE := $(CODE) gnucash.cc
CFLAGS := $(CFLAGS) -DREAD_GNUCASH=1 CFLAGS := $(CFLAGS) -DREAD_GNUCASH=1
INCS := $(INCS) -I/usr/include/xmltok
LIBS := $(LIBS) -lxmlparse LIBS := $(LIBS) -lxmlparse
endif endif

View file

@ -64,14 +64,8 @@ class gmp_amount : public amount
} }
virtual void credit(const amount * other); virtual void credit(const amount * other);
virtual void parse(const char * num) { virtual void parse(const char * num);
*this = num;
}
virtual amount& operator=(const char * num);
virtual std::string as_str(bool full_prec) const; 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); 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; return comm;
} }
amount& gmp_amount::operator=(const char * num) void gmp_amount::parse(const char * num)
{ {
// Compile the regular expression used for parsing amounts // Compile the regular expression used for parsing amounts
static pcre * re = NULL; static pcre * re = NULL;
@ -594,7 +588,6 @@ amount& gmp_amount::operator=(const char * num)
} else { } else {
std::cerr << "Failed to parse amount: " << num << std::endl; std::cerr << "Failed to parse amount: " << num << std::endl;
} }
return *this;
} }
void gmp_amount::credit(const amount * value) void gmp_amount::credit(const amount * value)

View file

@ -20,10 +20,10 @@ static bool account_matches(const account * acct,
const std::list<mask>& regexps, const std::list<mask>& regexps,
bool * true_match) bool * true_match)
{ {
bool match = true; bool match = false;
*true_match = false;
if (show_children) { if (show_children) {
match = false;
for (const account * a = acct; a; a = a->parent) { for (const account * a = acct; a; a = a->parent) {
bool exclude = false; bool exclude = false;
if (matches(regexps, a->name, &exclude)) { if (matches(regexps, a->name, &exclude)) {
@ -36,6 +36,7 @@ static bool account_matches(const account * acct,
} }
} else { } else {
match = matches(regexps, acct->as_str()); match = matches(regexps, acct->as_str());
if (match)
*true_match = matches(regexps, acct->name); *true_match = matches(regexps, acct->name);
} }
return match; return match;
@ -134,7 +135,6 @@ void report_balances(int argc, char **argv, std::ostream& out)
else if (acct->checked == 3) else if (acct->checked == 3)
continue; continue;
acct->checked = 1;
acct->balance.credit((*x)->cost->street()); acct->balance.credit((*x)->cost->street());
} }
} }

View file

@ -44,7 +44,7 @@ static void startElement(void *userData, const char *name, const char **atts)
{ {
if (std::strcmp(name, "gnc:account") == 0) { if (std::strcmp(name, "gnc:account") == 0) {
assert(! curr_account); assert(! curr_account);
curr_account = new account(name); curr_account = new account;
} }
else if (std::strcmp(name, "act:name") == 0) else if (std::strcmp(name, "act:name") == 0)
action = ACCOUNT_NAME; action = ACCOUNT_NAME;
@ -111,14 +111,8 @@ static void endElement(void *userData, const char *name)
} }
else if (std::strcmp(name, "gnc:transaction") == 0) { else if (std::strcmp(name, "gnc:transaction") == 0) {
assert(curr_entry); assert(curr_entry);
if (! curr_entry->validate()) { assert(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); main_ledger.entries.push_back(curr_entry);
}
curr_entry = NULL; curr_entry = NULL;
} }
action = NO_ACTION; 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)); accounts_iterator i = accounts_by_id.find(std::string(s, len));
if (i == accounts_by_id.end()) { if (i == accounts_by_id.end()) {
std::cerr << "Could not find account " << std::string(s, len) std::cerr << "Could not find account " << std::string(s, len)
<< " at line " << XML_GetCurrentLineNumber(current_parser)
<< std::endl; << std::endl;
std::exit(1); std::exit(1);
} }
@ -203,9 +196,9 @@ static void dataHandler(void *userData, const char *s, int len)
transaction * xact = curr_entry->xacts.back(); transaction * xact = curr_entry->xacts.back();
xact->acct = (*i).second; 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. // assert: value must be equal to curr_value.
delete curr_value; delete curr_value;
curr_value = NULL; curr_value = NULL;

View file

@ -136,7 +136,7 @@ void totals::print(std::ostream& out, int width) const
out << std::endl; out << std::endl;
out.width(width); out.width(width);
out << std::right << *((*i).second); out << std::right << (*i).second->as_str();
} }
} }

View file

@ -1,5 +1,5 @@
#ifndef _LEDGER_H #ifndef _LEDGER_H
#define _LEDGER_H "$Revision: 1.15 $" #define _LEDGER_H "$Revision: 1.16 $"
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// //
@ -139,17 +139,9 @@ class amount
// String conversion routines // String conversion routines
virtual void parse(const char * num) = 0; 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 std::string as_str(bool full_prec = false) const = 0;
virtual operator std::string() const = 0;
}; };
template<class Traits>
std::basic_ostream<char, Traits> &
operator<<(std::basic_ostream<char, Traits>& out, const amount& a) {
return (out << std::string(a));
}
extern amount * create_amount(const char * value, extern amount * create_amount(const char * value,
const amount * cost = NULL); const amount * cost = NULL);
@ -294,6 +286,11 @@ struct account
accounts_t children; accounts_t children;
account() : parent(NULL), checked(0) {
#ifdef HUQUQULLAH
exempt_or_necessary = false;
#endif
}
account(const std::string& _name, struct account * _parent = NULL) account(const std::string& _name, struct account * _parent = NULL)
: parent(_parent), name(_name), checked(0) { : parent(_parent), name(_name), checked(0) {
#ifdef HUQUQULLAH #ifdef HUQUQULLAH

View file

@ -1,5 +1,5 @@
\input texinfo @c -*-texinfo-*- \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 @comment %**start of header
@setfilename ledger.info @setfilename ledger.info
@ -329,10 +329,6 @@ would look like:
Now you've turned 2 steaks into 15 gold, courtesy of your customer, Now you've turned 2 steaks into 15 gold, courtesy of your customer,
Sturm Brightblade. 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 Using @code{ledger}
@chapter Computing Huqúqu'lláh @chapter Computing Huqúqu'lláh

26
main.cc
View file

@ -127,7 +127,7 @@ int main(int argc, char *argv[])
show_cleared = false; show_cleared = false;
int c; 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)) { switch (char(c)) {
case 'b': case 'b':
case 'e': { case 'e': {
@ -289,6 +289,18 @@ int main(int argc, char *argv[])
const std::string command = argv[optind]; const std::string command = argv[optind];
// Parse the ledger
#ifdef READ_GNUCASH
char buf[32];
file->get(buf, 31);
file->seekg(0);
if (std::strncmp(buf, "<?xml version=\"1.0\"?>", 21) == 0)
parse_gnucash(*file, command == "equity");
else
#endif
{
#ifdef HUQUQULLAH #ifdef HUQUQULLAH
if (command == "register" && argv[optind + 1] && if (command == "register" && argv[optind + 1] &&
std::string(argv[optind + 1]) != "Huququ'llah" && std::string(argv[optind + 1]) != "Huququ'llah" &&
@ -306,18 +318,8 @@ int main(int argc, char *argv[])
} }
#endif #endif
// Parse the ledger
#ifdef READ_GNUCASH
char buf[32];
file->get(buf, 31);
file->seekg(0);
if (std::strncmp(buf, "<?xml version=\"1.0\"?>", 21) == 0)
parse_gnucash(*file, command == "equity");
else
#endif
parse_ledger(*file, command == "equity"); parse_ledger(*file, command == "equity");
}
#ifdef DO_CLEANUP #ifdef DO_CLEANUP
delete file; delete file;