*** empty log message ***
This commit is contained in:
parent
3afa81857a
commit
2a10558902
8 changed files with 42 additions and 61 deletions
6
Makefile
6
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
|
||||
|
||||
|
|
|
|||
11
amount.cc
11
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)
|
||||
|
|
|
|||
|
|
@ -20,10 +20,10 @@ static bool account_matches(const account * acct,
|
|||
const std::list<mask>& 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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
17
gnucash.cc
17
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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
15
ledger.h
15
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<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,
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
38
main.cc
38
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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue