Some basic fixes to get things almost running, although we still can't parse
my personal ledger file yet.
This commit is contained in:
parent
d568319495
commit
88634973a2
5 changed files with 37 additions and 6 deletions
|
|
@ -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");
|
||||
|
|
|
|||
12
amount.h
12
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
8
main.cc
8
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
|
||||
|
|
|
|||
15
textual.cc
15
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:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue