*** no comment ***
This commit is contained in:
parent
88a895a494
commit
70b3eda8d1
7 changed files with 73 additions and 28 deletions
|
|
@ -77,6 +77,9 @@ bin_PROGRAMS = ledger
|
||||||
ledger_CXXFLAGS =
|
ledger_CXXFLAGS =
|
||||||
ledger_SOURCES = main.cc
|
ledger_SOURCES = main.cc
|
||||||
ledger_LDADD = $(LIBOBJS) libledger.la
|
ledger_LDADD = $(LIBOBJS) libledger.la
|
||||||
|
if USE_EDITOR
|
||||||
|
ledger_CXXFLAGS += -DUSE_EDITOR=1
|
||||||
|
endif
|
||||||
if HAVE_EXPAT
|
if HAVE_EXPAT
|
||||||
ledger_CXXFLAGS += -DHAVE_EXPAT=1
|
ledger_CXXFLAGS += -DHAVE_EXPAT=1
|
||||||
ledger_LDADD += -lexpat
|
ledger_LDADD += -lexpat
|
||||||
|
|
|
||||||
4
acprep
4
acprep
|
|
@ -23,13 +23,13 @@ LIBDIRS="-L/sw/lib -L/usr/local/lib"
|
||||||
|
|
||||||
if [ "$1" = "--debug" ]; then
|
if [ "$1" = "--debug" ]; then
|
||||||
./configure CPPFLAGS="$INCDIRS" LDFLAGS="$LIBDIRS" CXXFLAGS="-g" \
|
./configure CPPFLAGS="$INCDIRS" LDFLAGS="$LIBDIRS" CXXFLAGS="-g" \
|
||||||
--enable-debug --disable-emacs
|
--enable-debug
|
||||||
elif [ "$1" = "--opt" ]; then
|
elif [ "$1" = "--opt" ]; then
|
||||||
./configure CPPFLAGS="$INCDIRS" LDFLAGS="$LIBDIRS" \
|
./configure CPPFLAGS="$INCDIRS" LDFLAGS="$LIBDIRS" \
|
||||||
CXXFLAGS="-fomit-frame-pointer -O3 -mcpu=7450 -fPIC"
|
CXXFLAGS="-fomit-frame-pointer -O3 -mcpu=7450 -fPIC"
|
||||||
elif [ "$1" = "--flat-opt" ]; then
|
elif [ "$1" = "--flat-opt" ]; then
|
||||||
./configure CPPFLAGS="$INCDIRS" LDFLAGS="$LIBDIRS" \
|
./configure CPPFLAGS="$INCDIRS" LDFLAGS="$LIBDIRS" \
|
||||||
CXXFLAGS="-fomit-frame-pointer -O3 -mcpu=7450" --disable-emacs
|
CXXFLAGS="-fomit-frame-pointer -O3 -mcpu=7450"
|
||||||
elif [ "$1" = "--safe-opt" ]; then
|
elif [ "$1" = "--safe-opt" ]; then
|
||||||
./configure CPPFLAGS="$INCDIRS" LDFLAGS="$LIBDIRS" \
|
./configure CPPFLAGS="$INCDIRS" LDFLAGS="$LIBDIRS" \
|
||||||
CXXFLAGS="-fomit-frame-pointer -O3 -mcpu=7450 -fPIC -DDEBUG_LEVEL=1"
|
CXXFLAGS="-fomit-frame-pointer -O3 -mcpu=7450 -fPIC -DDEBUG_LEVEL=1"
|
||||||
|
|
|
||||||
65
binary.cc
65
binary.cc
|
|
@ -13,15 +13,15 @@ namespace ledger {
|
||||||
static unsigned long binary_magic_number = 0xFFEED765;
|
static unsigned long binary_magic_number = 0xFFEED765;
|
||||||
#ifdef USE_EDITOR
|
#ifdef USE_EDITOR
|
||||||
#ifdef DEBUG_ENABLED
|
#ifdef DEBUG_ENABLED
|
||||||
static unsigned long format_version = 0x00020587;
|
static unsigned long format_version = 0x00020589;
|
||||||
#else
|
#else
|
||||||
static unsigned long format_version = 0x00020586;
|
static unsigned long format_version = 0x00020588;
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#ifdef DEBUG_ENABLED
|
#ifdef DEBUG_ENABLED
|
||||||
static unsigned long format_version = 0x00020507;
|
static unsigned long format_version = 0x00020509;
|
||||||
#else
|
#else
|
||||||
static unsigned long format_version = 0x00020506;
|
static unsigned long format_version = 0x00020508;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -338,7 +338,7 @@ inline void read_binary_transaction(char *& data, transaction_t * xact)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void read_binary_entry_base(char *& data, entry_base_t * entry,
|
inline void read_binary_entry_base(char *& data, entry_base_t * entry,
|
||||||
transaction_t *& xact_pool)
|
transaction_t *& xact_pool, bool& finalize)
|
||||||
{
|
{
|
||||||
#ifdef USE_EDITOR
|
#ifdef USE_EDITOR
|
||||||
read_binary_long(data, entry->src_idx);
|
read_binary_long(data, entry->src_idx);
|
||||||
|
|
@ -348,19 +348,23 @@ inline void read_binary_entry_base(char *& data, entry_base_t * entry,
|
||||||
read_binary_long(data, entry->end_line);
|
read_binary_long(data, entry->end_line);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool ignore_calculated = read_binary_number<char>(data) == 1;
|
||||||
|
|
||||||
for (unsigned long i = 0, count = read_binary_long<unsigned long>(data);
|
for (unsigned long i = 0, count = read_binary_long<unsigned long>(data);
|
||||||
i < count;
|
i < count;
|
||||||
i++) {
|
i++) {
|
||||||
DEBUG_PRINT("ledger.memory.ctors", "ctor transaction_t");
|
DEBUG_PRINT("ledger.memory.ctors", "ctor transaction_t");
|
||||||
read_binary_transaction(data, xact_pool);
|
read_binary_transaction(data, xact_pool);
|
||||||
|
if (ignore_calculated && xact_pool->flags & TRANSACTION_CALCULATED)
|
||||||
|
finalize = true;
|
||||||
entry->add_transaction(xact_pool++);
|
entry->add_transaction(xact_pool++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void read_binary_entry(char *& data, entry_t * entry,
|
inline void read_binary_entry(char *& data, entry_t * entry,
|
||||||
transaction_t *& xact_pool)
|
transaction_t *& xact_pool, bool& finalize)
|
||||||
{
|
{
|
||||||
read_binary_entry_base(data, entry, xact_pool);
|
read_binary_entry_base(data, entry, xact_pool, finalize);
|
||||||
read_binary_long(data, entry->_date);
|
read_binary_long(data, entry->_date);
|
||||||
read_binary_long(data, entry->_date_eff);
|
read_binary_long(data, entry->_date_eff);
|
||||||
read_binary_string(data, &entry->code);
|
read_binary_string(data, &entry->code);
|
||||||
|
|
@ -370,15 +374,16 @@ inline void read_binary_entry(char *& data, entry_t * entry,
|
||||||
inline void read_binary_auto_entry(char *& data, auto_entry_t * entry,
|
inline void read_binary_auto_entry(char *& data, auto_entry_t * entry,
|
||||||
transaction_t *& xact_pool)
|
transaction_t *& xact_pool)
|
||||||
{
|
{
|
||||||
read_binary_entry_base(data, entry, xact_pool);
|
bool ignore;
|
||||||
|
read_binary_entry_base(data, entry, xact_pool, ignore);
|
||||||
read_binary_string(data, &entry->predicate_string);
|
read_binary_string(data, &entry->predicate_string);
|
||||||
entry->predicate = new item_predicate<transaction_t>(entry->predicate_string);
|
entry->predicate = new item_predicate<transaction_t>(entry->predicate_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void read_binary_period_entry(char *& data, period_entry_t * entry,
|
inline void read_binary_period_entry(char *& data, period_entry_t * entry,
|
||||||
transaction_t *& xact_pool)
|
transaction_t *& xact_pool, bool& finalize)
|
||||||
{
|
{
|
||||||
read_binary_entry_base(data, entry, xact_pool);
|
read_binary_entry_base(data, entry, xact_pool, finalize);
|
||||||
read_binary_string(data, &entry->period_string);
|
read_binary_string(data, &entry->period_string);
|
||||||
std::istringstream stream(entry->period_string);
|
std::istringstream stream(entry->period_string);
|
||||||
entry->period.parse(stream);
|
entry->period.parse(stream);
|
||||||
|
|
@ -595,8 +600,11 @@ unsigned int read_binary_journal(std::istream& in,
|
||||||
|
|
||||||
for (unsigned long i = 0; i < count; i++) {
|
for (unsigned long i = 0; i < count; i++) {
|
||||||
new(entry_pool) entry_t;
|
new(entry_pool) entry_t;
|
||||||
read_binary_entry(data, entry_pool, xact_pool);
|
bool finalize = false;
|
||||||
|
read_binary_entry(data, entry_pool, xact_pool, finalize);
|
||||||
entry_pool->journal = journal;
|
entry_pool->journal = journal;
|
||||||
|
if (finalize && ! entry_pool->finalize())
|
||||||
|
continue;
|
||||||
journal->entries.push_back(entry_pool++);
|
journal->entries.push_back(entry_pool++);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -609,8 +617,11 @@ unsigned int read_binary_journal(std::istream& in,
|
||||||
|
|
||||||
for (unsigned long i = 0; i < period_count; i++) {
|
for (unsigned long i = 0; i < period_count; i++) {
|
||||||
period_entry_t * period_entry = new period_entry_t;
|
period_entry_t * period_entry = new period_entry_t;
|
||||||
read_binary_period_entry(data, period_entry, xact_pool);
|
bool finalize = false;
|
||||||
|
read_binary_period_entry(data, period_entry, xact_pool, finalize);
|
||||||
period_entry->journal = journal;
|
period_entry->journal = journal;
|
||||||
|
if (finalize && ! period_entry->finalize())
|
||||||
|
continue;
|
||||||
journal->period_entries.push_back(period_entry);
|
journal->period_entries.push_back(period_entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -623,13 +634,15 @@ unsigned int read_binary_journal(std::istream& in,
|
||||||
delete[] commodities;
|
delete[] commodities;
|
||||||
delete[] data_pool;
|
delete[] data_pool;
|
||||||
|
|
||||||
|
VALIDATE(journal->valid());
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool binary_parser_t::test(std::istream& in) const
|
bool binary_parser_t::test(std::istream& in) const
|
||||||
{
|
{
|
||||||
if (read_binary_number<unsigned long>(in) == binary_magic_number &&
|
if (read_binary_number<unsigned long>(in) == binary_magic_number &&
|
||||||
read_binary_long<unsigned long>(in) == format_version)
|
read_binary_number<unsigned long>(in) == format_version)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
in.clear();
|
in.clear();
|
||||||
|
|
@ -759,7 +772,8 @@ void write_binary_value_expr(std::ostream& out, value_expr_t * expr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_binary_transaction(std::ostream& out, transaction_t * xact)
|
void write_binary_transaction(std::ostream& out, transaction_t * xact,
|
||||||
|
bool ignore_calculated)
|
||||||
{
|
{
|
||||||
write_binary_long(out, xact->_date);
|
write_binary_long(out, xact->_date);
|
||||||
write_binary_long(out, xact->_date_eff);
|
write_binary_long(out, xact->_date_eff);
|
||||||
|
|
@ -770,10 +784,14 @@ void write_binary_transaction(std::ostream& out, transaction_t * xact)
|
||||||
write_binary_value_expr(out, xact->amount_expr);
|
write_binary_value_expr(out, xact->amount_expr);
|
||||||
} else {
|
} else {
|
||||||
write_binary_number<char>(out, 0);
|
write_binary_number<char>(out, 0);
|
||||||
write_binary_amount(out, xact->amount);
|
if (ignore_calculated && xact->flags & TRANSACTION_CALCULATED)
|
||||||
|
write_binary_amount(out, amount_t());
|
||||||
|
else
|
||||||
|
write_binary_amount(out, xact->amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xact->cost) {
|
if (xact->cost &&
|
||||||
|
(! (ignore_calculated && xact->flags & TRANSACTION_CALCULATED))) {
|
||||||
write_binary_number<char>(out, 1);
|
write_binary_number<char>(out, 1);
|
||||||
if (xact->cost_expr != NULL) {
|
if (xact->cost_expr != NULL) {
|
||||||
write_binary_number<char>(out, 1);
|
write_binary_number<char>(out, 1);
|
||||||
|
|
@ -808,11 +826,22 @@ void write_binary_entry_base(std::ostream& out, entry_base_t * entry)
|
||||||
write_binary_long(out, entry->end_line);
|
write_binary_long(out, entry->end_line);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool ignore_calculated = false;
|
||||||
|
for (transactions_list::const_iterator i = entry->transactions.begin();
|
||||||
|
i != entry->transactions.end();
|
||||||
|
i++)
|
||||||
|
if ((*i)->amount_expr || (*i)->cost_expr) {
|
||||||
|
ignore_calculated = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
write_binary_number<char>(out, ignore_calculated ? 1 : 0);
|
||||||
|
|
||||||
write_binary_long(out, entry->transactions.size());
|
write_binary_long(out, entry->transactions.size());
|
||||||
for (transactions_list::const_iterator i = entry->transactions.begin();
|
for (transactions_list::const_iterator i = entry->transactions.begin();
|
||||||
i != entry->transactions.end();
|
i != entry->transactions.end();
|
||||||
i++)
|
i++)
|
||||||
write_binary_transaction(out, *i);
|
write_binary_transaction(out, *i, ignore_calculated);
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_binary_entry(std::ostream& out, entry_t * entry)
|
void write_binary_entry(std::ostream& out, entry_t * entry)
|
||||||
|
|
@ -917,7 +946,7 @@ void write_binary_journal(std::ostream& out, journal_t * journal)
|
||||||
commodity_index = 0;
|
commodity_index = 0;
|
||||||
|
|
||||||
write_binary_number(out, binary_magic_number);
|
write_binary_number(out, binary_magic_number);
|
||||||
write_binary_long(out, format_version);
|
write_binary_number(out, format_version);
|
||||||
|
|
||||||
// Write out the files that participated in this journal, so that
|
// Write out the files that participated in this journal, so that
|
||||||
// they can be checked for changes on reading.
|
// they can be checked for changes on reading.
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ bool transaction_t::valid() const
|
||||||
if (cost && ! cost->valid())
|
if (cost && ! cost->valid())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (flags & ~0x000f)
|
if (flags & ~0x001f)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -109,6 +109,7 @@ bool entry_base_t::finalize()
|
||||||
// The amount doesn't need to be set because the code below will
|
// The amount doesn't need to be set because the code below will
|
||||||
// balance this transaction against the other.
|
// balance this transaction against the other.
|
||||||
add_transaction(nxact);
|
add_transaction(nxact);
|
||||||
|
nxact->flags |= TRANSACTION_CALCULATED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If one transaction of a two-line transaction is of a different
|
// If one transaction of a two-line transaction is of a different
|
||||||
|
|
@ -191,6 +192,7 @@ bool entry_base_t::finalize()
|
||||||
} else {
|
} else {
|
||||||
transaction_t * nxact = new transaction_t((*x)->account);
|
transaction_t * nxact = new transaction_t((*x)->account);
|
||||||
add_transaction(nxact);
|
add_transaction(nxact);
|
||||||
|
nxact->flags |= TRANSACTION_CALCULATED;
|
||||||
nxact->amount = amt;
|
nxact->amount = amt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -203,6 +205,7 @@ bool entry_base_t::finalize()
|
||||||
case value_t::AMOUNT:
|
case value_t::AMOUNT:
|
||||||
(*x)->amount = *((amount_t *) balance.data);
|
(*x)->amount = *((amount_t *) balance.data);
|
||||||
(*x)->amount.negate();
|
(*x)->amount.negate();
|
||||||
|
(*x)->flags |= TRANSACTION_CALCULATED;
|
||||||
|
|
||||||
balance += (*x)->amount;
|
balance += (*x)->amount;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
13
journal.h
13
journal.h
|
|
@ -22,6 +22,7 @@ namespace ledger {
|
||||||
#define TRANSACTION_BALANCE 0x0002
|
#define TRANSACTION_BALANCE 0x0002
|
||||||
#define TRANSACTION_AUTO 0x0004
|
#define TRANSACTION_AUTO 0x0004
|
||||||
#define TRANSACTION_BULK_ALLOC 0x0008
|
#define TRANSACTION_BULK_ALLOC 0x0008
|
||||||
|
#define TRANSACTION_CALCULATED 0x0010
|
||||||
|
|
||||||
class entry_t;
|
class entry_t;
|
||||||
class account_t;
|
class account_t;
|
||||||
|
|
@ -132,10 +133,18 @@ class entry_base_t
|
||||||
#endif
|
#endif
|
||||||
transactions_list transactions;
|
transactions_list transactions;
|
||||||
|
|
||||||
entry_base_t() : journal(NULL) {
|
entry_base_t() : journal(NULL),
|
||||||
|
#ifdef USE_EDITOR
|
||||||
|
beg_pos(0), beg_line(0), end_pos(0), end_line(0)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
DEBUG_PRINT("ledger.memory.ctors", "ctor entry_base_t");
|
DEBUG_PRINT("ledger.memory.ctors", "ctor entry_base_t");
|
||||||
}
|
}
|
||||||
entry_base_t(const entry_base_t& e) : journal(NULL) {
|
entry_base_t(const entry_base_t& e) : journal(NULL),
|
||||||
|
#ifdef USE_EDITOR
|
||||||
|
beg_pos(0), beg_line(0), end_pos(0), end_line(0)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
DEBUG_PRINT("ledger.memory.ctors", "ctor entry_base_t");
|
DEBUG_PRINT("ledger.memory.ctors", "ctor entry_base_t");
|
||||||
for (transactions_list::const_iterator i = e.transactions.begin();
|
for (transactions_list::const_iterator i = e.transactions.begin();
|
||||||
i != e.transactions.end();
|
i != e.transactions.end();
|
||||||
|
|
|
||||||
10
valexpr.cc
10
valexpr.cc
|
|
@ -130,6 +130,10 @@ void value_expr_t::compute(value_t& result, const details_t& details) const
|
||||||
result = 0L;
|
result = 0L;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case F_NOW:
|
||||||
|
result = long(terminus);
|
||||||
|
break;
|
||||||
|
|
||||||
case DATE:
|
case DATE:
|
||||||
if (details.xact && transaction_has_xdata(*details.xact) &&
|
if (details.xact && transaction_has_xdata(*details.xact) &&
|
||||||
transaction_xdata_(*details.xact).date)
|
transaction_xdata_(*details.xact).date)
|
||||||
|
|
@ -525,11 +529,7 @@ value_expr_t * parse_value_term(std::istream& in)
|
||||||
in.get(c);
|
in.get(c);
|
||||||
switch (c) {
|
switch (c) {
|
||||||
// Basic terms
|
// Basic terms
|
||||||
case 'm':
|
case 'm': node.reset(new value_expr_t(value_expr_t::F_NOW)); break;
|
||||||
node.reset(new value_expr_t(value_expr_t::CONSTANT_T));
|
|
||||||
node->constant_t = terminus;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'a': node.reset(new value_expr_t(value_expr_t::AMOUNT)); break;
|
case 'a': node.reset(new value_expr_t(value_expr_t::AMOUNT)); break;
|
||||||
case 'b': node.reset(new value_expr_t(value_expr_t::COST)); break;
|
case 'b': node.reset(new value_expr_t(value_expr_t::COST)); break;
|
||||||
case 'd': node.reset(new value_expr_t(value_expr_t::DATE)); break;
|
case 'd': node.reset(new value_expr_t(value_expr_t::DATE)); break;
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,7 @@ struct value_expr_t
|
||||||
TOTAL_EXPR,
|
TOTAL_EXPR,
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
|
F_NOW,
|
||||||
F_PARENT,
|
F_PARENT,
|
||||||
F_ARITH_MEAN,
|
F_ARITH_MEAN,
|
||||||
F_VALUE,
|
F_VALUE,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue