summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2006-02-25 13:17:36 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 02:41:26 -0400
commit70b3eda8d13fd6f8805791b52c1191619cf1fc03 (patch)
tree507771356689066b331fdff138b539c287d2306d
parent88a895a4944efcae0f7dbc7e7d73bef817cd317e (diff)
downloadfork-ledger-70b3eda8d13fd6f8805791b52c1191619cf1fc03.tar.gz
fork-ledger-70b3eda8d13fd6f8805791b52c1191619cf1fc03.tar.bz2
fork-ledger-70b3eda8d13fd6f8805791b52c1191619cf1fc03.zip
*** no comment ***
-rw-r--r--Makefile.am3
-rwxr-xr-xacprep4
-rw-r--r--binary.cc65
-rw-r--r--journal.cc5
-rw-r--r--journal.h13
-rw-r--r--valexpr.cc10
-rw-r--r--valexpr.h1
7 files changed, 73 insertions, 28 deletions
diff --git a/Makefile.am b/Makefile.am
index 2fc919af..68eb29b0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -77,6 +77,9 @@ bin_PROGRAMS = ledger
ledger_CXXFLAGS =
ledger_SOURCES = main.cc
ledger_LDADD = $(LIBOBJS) libledger.la
+if USE_EDITOR
+ledger_CXXFLAGS += -DUSE_EDITOR=1
+endif
if HAVE_EXPAT
ledger_CXXFLAGS += -DHAVE_EXPAT=1
ledger_LDADD += -lexpat
diff --git a/acprep b/acprep
index 13efd189..8aa0f343 100755
--- a/acprep
+++ b/acprep
@@ -23,13 +23,13 @@ LIBDIRS="-L/sw/lib -L/usr/local/lib"
if [ "$1" = "--debug" ]; then
./configure CPPFLAGS="$INCDIRS" LDFLAGS="$LIBDIRS" CXXFLAGS="-g" \
- --enable-debug --disable-emacs
+ --enable-debug
elif [ "$1" = "--opt" ]; then
./configure CPPFLAGS="$INCDIRS" LDFLAGS="$LIBDIRS" \
CXXFLAGS="-fomit-frame-pointer -O3 -mcpu=7450 -fPIC"
elif [ "$1" = "--flat-opt" ]; then
./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
./configure CPPFLAGS="$INCDIRS" LDFLAGS="$LIBDIRS" \
CXXFLAGS="-fomit-frame-pointer -O3 -mcpu=7450 -fPIC -DDEBUG_LEVEL=1"
diff --git a/binary.cc b/binary.cc
index 5cb4697a..24613da9 100644
--- a/binary.cc
+++ b/binary.cc
@@ -13,15 +13,15 @@ namespace ledger {
static unsigned long binary_magic_number = 0xFFEED765;
#ifdef USE_EDITOR
#ifdef DEBUG_ENABLED
-static unsigned long format_version = 0x00020587;
+static unsigned long format_version = 0x00020589;
#else
-static unsigned long format_version = 0x00020586;
+static unsigned long format_version = 0x00020588;
#endif
#else
#ifdef DEBUG_ENABLED
-static unsigned long format_version = 0x00020507;
+static unsigned long format_version = 0x00020509;
#else
-static unsigned long format_version = 0x00020506;
+static unsigned long format_version = 0x00020508;
#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,
- transaction_t *& xact_pool)
+ transaction_t *& xact_pool, bool& finalize)
{
#ifdef USE_EDITOR
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);
#endif
+ bool ignore_calculated = read_binary_number<char>(data) == 1;
+
for (unsigned long i = 0, count = read_binary_long<unsigned long>(data);
i < count;
i++) {
DEBUG_PRINT("ledger.memory.ctors", "ctor transaction_t");
read_binary_transaction(data, xact_pool);
+ if (ignore_calculated && xact_pool->flags & TRANSACTION_CALCULATED)
+ finalize = true;
entry->add_transaction(xact_pool++);
}
}
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_eff);
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,
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);
entry->predicate = new item_predicate<transaction_t>(entry->predicate_string);
}
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);
std::istringstream stream(entry->period_string);
entry->period.parse(stream);
@@ -595,8 +600,11 @@ unsigned int read_binary_journal(std::istream& in,
for (unsigned long i = 0; i < count; i++) {
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;
+ if (finalize && ! entry_pool->finalize())
+ continue;
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++) {
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;
+ if (finalize && ! period_entry->finalize())
+ continue;
journal->period_entries.push_back(period_entry);
}
@@ -623,13 +634,15 @@ unsigned int read_binary_journal(std::istream& in,
delete[] commodities;
delete[] data_pool;
+ VALIDATE(journal->valid());
+
return count;
}
bool binary_parser_t::test(std::istream& in) const
{
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;
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_eff);
@@ -770,10 +784,14 @@ void write_binary_transaction(std::ostream& out, transaction_t * xact)
write_binary_value_expr(out, xact->amount_expr);
} else {
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);
if (xact->cost_expr != NULL) {
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);
#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());
for (transactions_list::const_iterator i = entry->transactions.begin();
i != entry->transactions.end();
i++)
- write_binary_transaction(out, *i);
+ write_binary_transaction(out, *i, ignore_calculated);
}
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;
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
// they can be checked for changes on reading.
diff --git a/journal.cc b/journal.cc
index 9e073388..232bb97a 100644
--- a/journal.cc
+++ b/journal.cc
@@ -55,7 +55,7 @@ bool transaction_t::valid() const
if (cost && ! cost->valid())
return false;
- if (flags & ~0x000f)
+ if (flags & ~0x001f)
return false;
return true;
@@ -109,6 +109,7 @@ bool entry_base_t::finalize()
// The amount doesn't need to be set because the code below will
// balance this transaction against the other.
add_transaction(nxact);
+ nxact->flags |= TRANSACTION_CALCULATED;
}
// If one transaction of a two-line transaction is of a different
@@ -191,6 +192,7 @@ bool entry_base_t::finalize()
} else {
transaction_t * nxact = new transaction_t((*x)->account);
add_transaction(nxact);
+ nxact->flags |= TRANSACTION_CALCULATED;
nxact->amount = amt;
}
@@ -203,6 +205,7 @@ bool entry_base_t::finalize()
case value_t::AMOUNT:
(*x)->amount = *((amount_t *) balance.data);
(*x)->amount.negate();
+ (*x)->flags |= TRANSACTION_CALCULATED;
balance += (*x)->amount;
break;
diff --git a/journal.h b/journal.h
index a5953921..e0007634 100644
--- a/journal.h
+++ b/journal.h
@@ -22,6 +22,7 @@ namespace ledger {
#define TRANSACTION_BALANCE 0x0002
#define TRANSACTION_AUTO 0x0004
#define TRANSACTION_BULK_ALLOC 0x0008
+#define TRANSACTION_CALCULATED 0x0010
class entry_t;
class account_t;
@@ -132,10 +133,18 @@ class entry_base_t
#endif
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");
}
- 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");
for (transactions_list::const_iterator i = e.transactions.begin();
i != e.transactions.end();
diff --git a/valexpr.cc b/valexpr.cc
index 72ba5f6d..013cfad7 100644
--- a/valexpr.cc
+++ b/valexpr.cc
@@ -130,6 +130,10 @@ void value_expr_t::compute(value_t& result, const details_t& details) const
result = 0L;
break;
+ case F_NOW:
+ result = long(terminus);
+ break;
+
case DATE:
if (details.xact && transaction_has_xdata(*details.xact) &&
transaction_xdata_(*details.xact).date)
@@ -525,11 +529,7 @@ value_expr_t * parse_value_term(std::istream& in)
in.get(c);
switch (c) {
// Basic terms
- case 'm':
- node.reset(new value_expr_t(value_expr_t::CONSTANT_T));
- node->constant_t = terminus;
- break;
-
+ case 'm': node.reset(new value_expr_t(value_expr_t::F_NOW)); 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 'd': node.reset(new value_expr_t(value_expr_t::DATE)); break;
diff --git a/valexpr.h b/valexpr.h
index 73d5113e..c9db4601 100644
--- a/valexpr.h
+++ b/valexpr.h
@@ -61,6 +61,7 @@ struct value_expr_t
TOTAL_EXPR,
// Functions
+ F_NOW,
F_PARENT,
F_ARITH_MEAN,
F_VALUE,