summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2008-07-19 23:10:37 -0400
committerJohn Wiegley <johnw@newartisans.com>2008-07-19 23:10:37 -0400
commit88634973a29693402edd4eb8e943531354c51893 (patch)
tree550f6fca09e80d1a0877e06c3433b37c5bb2e6d5
parentd568319495a0695582797de0be4b85e1e06e73b2 (diff)
downloadfork-ledger-88634973a29693402edd4eb8e943531354c51893.tar.gz
fork-ledger-88634973a29693402edd4eb8e943531354c51893.tar.bz2
fork-ledger-88634973a29693402edd4eb8e943531354c51893.zip
Some basic fixes to get things almost running, although we still can't parse
my personal ledger file yet.
-rw-r--r--amount.cc4
-rw-r--r--amount.h12
-rw-r--r--journal.cc4
-rw-r--r--main.cc8
-rw-r--r--textual.cc15
5 files changed, 37 insertions, 6 deletions
diff --git a/amount.cc b/amount.cc
index 0b500063..46b0fbb4 100644
--- a/amount.cc
+++ b/amount.cc
@@ -489,6 +489,7 @@ amount_t& amount_t::operator*=(const amount_t& amt)
throw_(amount_error, "Cannot multiply two uninitialized amounts");
}
+#if 0
if (has_commodity() && amt.has_commodity() &&
commodity() != amt.commodity())
throw_(amount_error,
@@ -496,6 +497,7 @@ amount_t& amount_t::operator*=(const amount_t& amt)
(has_commodity() ? commodity().symbol() : "NONE") <<
" != " <<
(amt.has_commodity() ? amt.commodity().symbol() : "NONE"));
+#endif
_dup();
@@ -527,6 +529,7 @@ amount_t& amount_t::operator/=(const amount_t& amt)
throw_(amount_error, "Cannot divide two uninitialized amounts");
}
+#if 0
if (has_commodity() && amt.has_commodity() &&
commodity() != amt.commodity())
throw_(amount_error,
@@ -534,6 +537,7 @@ amount_t& amount_t::operator/=(const amount_t& amt)
(has_commodity() ? commodity().symbol() : "NONE") <<
" != " <<
(amt.has_commodity() ? amt.commodity().symbol() : "NONE"));
+#endif
if (! amt)
throw_(amount_error, "Divide by zero");
diff --git a/amount.h b/amount.h
index 8716ad34..665dabe9 100644
--- a/amount.h
+++ b/amount.h
@@ -185,6 +185,7 @@ public:
}
explicit amount_t(const char * val) : quantity(NULL) {
TRACE_CTOR(amount_t, "const char *");
+ assert(val);
parse(val);
}
@@ -229,10 +230,21 @@ public:
}
amount_t& operator=(const amount_t& amt);
+ amount_t& operator=(const double val) {
+ return *this = amount_t(val);
+ }
+ amount_t& operator=(const unsigned long val) {
+ return *this = amount_t(val);
+ }
+ amount_t& operator=(const long val) {
+ return *this = amount_t(val);
+ }
+
amount_t& operator=(const string& str) {
return *this = amount_t(str);
}
amount_t& operator=(const char * str) {
+ assert(str);
return *this = amount_t(str);
}
diff --git a/journal.cc b/journal.cc
index 184b090b..7ee8526e 100644
--- a/journal.cc
+++ b/journal.cc
@@ -108,7 +108,7 @@ bool entry_base_t::finalize()
if (! ((*x)->flags & TRANSACTION_VIRTUAL) ||
((*x)->flags & TRANSACTION_BALANCE)) {
amount_t * p = (*x)->cost ? (*x)->cost : &(*x)->amount;
- if (*p) {
+ if (! p->is_null()) {
if (no_amounts) {
balance = *p;
no_amounts = false;
@@ -251,7 +251,7 @@ bool entry_base_t::finalize()
case value_t::AMOUNT:
(*x)->amount = balance.as_amount_lval();
- (*x)->amount.negate();
+ (*x)->amount.in_place_negate();
(*x)->flags |= TRANSACTION_CALCULATED;
balance += (*x)->amount;
diff --git a/main.cc b/main.cc
index 3c378861..bae22bcd 100644
--- a/main.cc
+++ b/main.cc
@@ -495,10 +495,18 @@ int main(int argc, char * argv[], char * envp[])
report_t report;
ledger::config = &config;
ledger::report = &report;
+
+ amount_t::initialize();
+ value_t::initialize();
+
#if 0
TRACE_PUSH(main, "Ledger starting");
#endif
int status = parse_and_report(config, journal, report, argc, argv, envp);
+
+ value_t::shutdown();
+ amount_t::shutdown();
+
#if 0
TRACE_POP(main, "Ledger done");
#endif
diff --git a/textual.cc b/textual.cc
index 9d06cc66..614172ab 100644
--- a/textual.cc
+++ b/textual.cc
@@ -158,6 +158,8 @@ transaction_t * parse_transaction(char * line, account_t * account,
// Parse the optional amount
+ bool saw_amount = false;
+
if (in.good() && ! in.eof()) {
p = peek_next_nonws(in);
if (in.eof())
@@ -171,6 +173,11 @@ transaction_t * parse_transaction(char * line, account_t * account,
xact->amount_expr =
parse_amount_expr(in, xact->amount, xact.get(),
PARSE_VALEXPR_NO_REDUCE);
+ saw_amount = true;
+
+ xact->amount.reduce();
+ DEBUG("ledger.textual.parse", "line " << linenum << ": " <<
+ "Reduced amount is " << xact->amount);
unsigned long end = (long)in.tellg();
xact->amount_expr.expr = string(line, beg, end - beg);
@@ -186,6 +193,10 @@ transaction_t * parse_transaction(char * line, account_t * account,
if (in.good() && ! in.eof()) {
p = peek_next_nonws(in);
if (p == '@') {
+ if (! saw_amount)
+ throw new parse_error
+ ("Transaction cannot have a cost expression with an amount");
+
DEBUG("ledger.textual.parse", "line " << linenum << ": " <<
"Found a price indicator");
bool per_unit = true;
@@ -249,10 +260,6 @@ transaction_t * parse_transaction(char * line, account_t * account,
}
}
- xact->amount.reduce();
- DEBUG("ledger.textual.parse", "line " << linenum << ": " <<
- "Reduced amount is " << xact->amount);
-
// Parse the optional note
parse_note: