summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am8
-rw-r--r--amount.h1
-rw-r--r--autoxact.h2
-rw-r--r--binary.cc2
-rw-r--r--binary.h2
-rw-r--r--config.h2
-rw-r--r--datetime.h2
-rw-r--r--error.h2
-rw-r--r--format.h2
-rw-r--r--gnucash.cc2
-rw-r--r--journal.cc2
-rw-r--r--ledger.h283
-rw-r--r--main.cc5
-rw-r--r--parser.cc2
-rw-r--r--python.cc2
-rw-r--r--qif.cc2
-rw-r--r--textual.cc7
-rw-r--r--valexpr.h2
-rw-r--r--walk.h2
19 files changed, 50 insertions, 282 deletions
diff --git a/Makefile.am b/Makefile.am
index 198af05b..b362d3df 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -50,7 +50,7 @@ all-clean: maintainer-clean
rm -fr *~ .*~ .\#* *.html *.info *.pdf *.a *.so *.o *.lo *.la \
*.elc *.aux *.cp *.fn *.ky *.log *.pg *.toc *.tp *.vr \
.gdb_history gmon.out h out TAGS ledger valexpr .deps \
- .libs build AUTHORS ChangeLog COPYING INSTALL Makefile \
- acconf.h acconf.h.in aclocal.m4 autom4te config.guess \
- config.sub configure depcomp install-sh libtool ltconfig \
- ltmain.sh missing stamp texinfo.tex Makefile.in
+ .libs build AUTHORS COPYING INSTALL Makefile acconf.h \
+ acconf.h.in aclocal.m4 autom4te config.guess config.sub \
+ configure depcomp install-sh libtool ltconfig ltmain.sh \
+ missing stamp texinfo.tex Makefile.in
diff --git a/amount.h b/amount.h
index dd8ff335..ed1c9bb5 100644
--- a/amount.h
+++ b/amount.h
@@ -6,6 +6,7 @@
#include <ctime>
#include <cctype>
#include <iostream>
+#include <sstream>
#include <cassert>
#include <exception>
diff --git a/autoxact.h b/autoxact.h
index 255138a8..d3acd27c 100644
--- a/autoxact.h
+++ b/autoxact.h
@@ -1,7 +1,7 @@
#ifndef _AUTOXACT_H
#define _AUTOXACT_H
-#include "ledger.h"
+#include "journal.h"
#include "valexpr.h"
#include <deque>
diff --git a/binary.cc b/binary.cc
index c328dfe8..23fdbce3 100644
--- a/binary.cc
+++ b/binary.cc
@@ -1,4 +1,4 @@
-#include "ledger.h"
+#include "journal.h"
#include "binary.h"
#include <fstream>
diff --git a/binary.h b/binary.h
index 4487f25e..d57888a5 100644
--- a/binary.h
+++ b/binary.h
@@ -1,7 +1,7 @@
#ifndef _BINARY_H
#define _BINARY_H
-#include "ledger.h"
+#include "journal.h"
#include "parser.h"
#include <deque>
diff --git a/config.h b/config.h
index bdc31b7e..5c7bba2e 100644
--- a/config.h
+++ b/config.h
@@ -1,7 +1,7 @@
#ifndef _CONFIG_H
#define _CONFIG_H
-#include "ledger.h"
+#include "journal.h"
#include "option.h"
#include "valexpr.h"
#include "datetime.h"
diff --git a/datetime.h b/datetime.h
index 51483172..41c97fe1 100644
--- a/datetime.h
+++ b/datetime.h
@@ -1,7 +1,7 @@
#ifndef _DATETIME_H
#define _DATETIME_H
-#include "ledger.h"
+#include "journal.h"
#include <ctime>
#include <sstream>
diff --git a/error.h b/error.h
index d5107f6d..52af358a 100644
--- a/error.h
+++ b/error.h
@@ -1,7 +1,7 @@
#ifndef _ERROR_H
#define _ERROR_H
-#include "ledger.h"
+#include "journal.h"
#include <exception>
#include <string>
diff --git a/format.h b/format.h
index 9e6aa7df..8b3f760f 100644
--- a/format.h
+++ b/format.h
@@ -1,7 +1,7 @@
#ifndef _FORMAT_H
#define _FORMAT_H
-#include "ledger.h"
+#include "journal.h"
#include "valexpr.h"
#include "walk.h"
diff --git a/gnucash.cc b/gnucash.cc
index 6367c7c9..cfbac2f8 100644
--- a/gnucash.cc
+++ b/gnucash.cc
@@ -1,5 +1,5 @@
#include "gnucash.h"
-#include "ledger.h"
+#include "journal.h"
#include "error.h"
#include <iostream>
diff --git a/journal.cc b/journal.cc
index d7b852eb..2aec9b01 100644
--- a/journal.cc
+++ b/journal.cc
@@ -1,4 +1,4 @@
-#include "ledger.h"
+#include "journal.h"
#include "valexpr.h"
#include "datetime.h"
#include "error.h"
diff --git a/ledger.h b/ledger.h
index 22069a6d..02b43cb3 100644
--- a/ledger.h
+++ b/ledger.h
@@ -10,264 +10,29 @@
// Copyright (c) 2003,2004 John Wiegley <johnw@newartisans.com>
//
-#include <map>
-#include <list>
-#include <string>
-#include <ctime>
-#include <iostream>
-
-#include "amount.h"
-#include "value.h"
-#include "debug.h"
-
-namespace ledger {
-
-// These flags persist with the object
-#define TRANSACTION_NORMAL 0x0000
-#define TRANSACTION_VIRTUAL 0x0001
-#define TRANSACTION_BALANCE 0x0002
-#define TRANSACTION_AUTO 0x0004
-#define TRANSACTION_BULK_ALLOC 0x0008
-
-class entry_t;
-class account_t;
-
-class transaction_t
-{
- public:
- entry_t * entry;
- account_t * account;
- amount_t amount;
- amount_t * cost;
- unsigned short flags;
- std::string note;
- mutable void * data;
-
- transaction_t(account_t * _account = NULL)
- : entry(NULL), account(_account), cost(NULL),
- flags(TRANSACTION_NORMAL), data(NULL) {
- }
-
- transaction_t(account_t * _account,
- const amount_t& _amount,
- unsigned int _flags = TRANSACTION_NORMAL,
- const std::string& _note = "")
- : entry(NULL), account(_account), amount(_amount),
- cost(NULL), flags(_flags), note(_note), data(NULL) {
- }
-
- ~transaction_t() {
- //assert(! data);
- if (cost)
- delete cost;
- }
-
- bool operator==(const transaction_t& xact) {
- return this == &xact;
- }
- bool operator!=(const transaction_t& xact) {
- return ! (*this == xact);
- }
-
- bool valid() const;
-};
-
-balance_pair_t& add_transaction_to(const transaction_t& xact,
- balance_pair_t& bal_pair);
-value_t& add_transaction_to(const transaction_t& xact, value_t& value);
-
-typedef std::list<transaction_t *> transactions_list;
-
-class entry_t
-{
- public:
- enum state_t {
- UNCLEARED, CLEARED, PENDING
- };
-
- std::time_t date;
- state_t state;
- std::string code;
- std::string payee;
-
- transactions_list transactions;
-
- entry_t() : date(-1), state(UNCLEARED) {}
- ~entry_t() {
- for (transactions_list::iterator i = transactions.begin();
- i != transactions.end();
- i++)
- if (! ((*i)->flags & TRANSACTION_BULK_ALLOC))
- delete *i;
- else
- (*i)->~transaction_t();
- }
-
- bool operator==(const entry_t& entry) {
- return this == &entry;
- }
- bool operator!=(const entry_t& entry) {
- return ! (*this == entry);
- }
-
- void add_transaction(transaction_t * xact);
- bool remove_transaction(transaction_t * xact);
-
- bool valid() const;
-};
-
-bool finalize_entry(entry_t& entry);
-
-
-typedef std::map<const std::string, account_t *> accounts_map;
-typedef std::pair<const std::string, account_t *> accounts_pair;
-
-class account_t
-{
- public:
- typedef unsigned long ident_t;
-
- account_t * parent;
- std::string name;
- std::string note;
- unsigned short depth;
- accounts_map accounts;
- transactions_list transactions;
- mutable void * data;
- mutable ident_t ident;
- mutable std::string _fullname;
-
- account_t(account_t * _parent = NULL,
- const std::string& _name = "",
- const std::string& _note = "")
- : parent(_parent), name(_name), note(_note),
- depth(parent ? parent->depth + 1 : 0), data(NULL), ident(0) {}
-
- ~account_t();
-
- bool operator==(const account_t& account) {
- return this == &account;
- }
- bool operator!=(const account_t& account) {
- return ! (*this == account);
- }
-
- std::string fullname() const;
-
- void add_account(account_t * acct) {
- accounts.insert(accounts_pair(acct->name, acct));
- }
- bool remove_account(account_t * acct) {
- accounts_map::size_type n = accounts.erase(acct->name);
- return n > 0;
- }
-
- account_t * find_account(const std::string& name, bool auto_create = true);
-
- operator std::string() const {
- return fullname();
- }
-
- // These functions should only be called from journal_t::add_entry
- // and journal_t::remove_entry; or from the various parsers.
- void add_transaction(transaction_t * xact) {
- transactions.push_back(xact);
- }
- bool remove_transaction(transaction_t * xact);
-
- friend class journal_t;
-
- bool valid() const;
-};
-
-std::ostream& operator<<(std::ostream& out, const account_t& account);
-
-
-template <typename T>
-void add_hook(std::list<T>& list, T func, const bool prepend = false) {
- if (prepend)
- list.push_front(func);
- else
- list.push_back(func);
-}
-
-template <typename T>
-void remove_hook(std::list<T>& list, T func) {
- list.remove(func);
-}
-
-template <typename T, typename Data>
-bool run_hooks(std::list<T>& list, Data& entry) {
- for (typename std::list<T>::const_iterator i = list.begin();
- i != list.end();
- i++)
- if (! (*i)(entry))
- return false;
- return true;
-}
-
-
-typedef std::list<entry_t *> entries_list;
-typedef std::list<std::string> strings_list;
-
-class journal_t
-{
- public:
- account_t * master;
- entries_list entries;
- strings_list sources;
- char * item_pool;
- char * item_pool_end;
-
- mutable accounts_map accounts_cache;
-
- typedef bool (*entry_finalize_hook_t)(entry_t& entry);
-
- std::list<entry_finalize_hook_t> entry_finalize_hooks;
-
- journal_t() {
- master = new account_t(NULL, "");
- item_pool = item_pool_end = NULL;
- add_hook(entry_finalize_hooks, finalize_entry);
- }
- ~journal_t();
-
- bool operator==(const journal_t& journal) {
- return this == &journal;
- }
- bool operator!=(const journal_t& journal) {
- return ! (*this == journal);
- }
-
- void add_account(account_t * acct) {
- master->add_account(acct);
- }
- bool remove_account(account_t * acct) {
- return master->remove_account(acct);
- }
-
- account_t * find_account(const std::string& name, bool auto_create = true) {
- accounts_map::iterator c = accounts_cache.find(name);
- if (c != accounts_cache.end())
- return (*c).second;
-
- account_t * account = master->find_account(name, auto_create);
- accounts_cache.insert(accounts_pair(name, account));
- return account;
- }
- account_t * find_account_re(const std::string& regexp);
-
- bool add_entry(entry_t * entry);
- bool remove_entry(entry_t * entry);
-
- entry_t * derive_entry(strings_list::iterator begin,
- strings_list::iterator end);
-
- bool valid() const;
-};
-
-extern const std::string version;
-
-} // namespace ledger
+#include <amount.h>
+#include <balance.h>
+#include <value.h>
+
+#include <journal.h>
+
+#include <datetime.h>
+#include <format.h>
+#include <quotes.h>
+#include <valexpr.h>
+#include <walk.h>
+
+#include <option.h>
+#include <config.h>
+
+#include <parser.h>
+#include <textual.h>
+#include <autoxact.h>
+#include <binary.h>
+#include <qif.h>
+
+#include <error.h>
+#include <timing.h>
+#include <util.h>
#endif // _LEDGER_H
diff --git a/main.cc b/main.cc
index e0f6c883..a6ecaa51 100644
--- a/main.cc
+++ b/main.cc
@@ -1,7 +1,6 @@
-#include "ledger.h"
+#include "journal.h"
#include "parser.h"
#include "textual.h"
-#include "autoxact.h"
#include "binary.h"
#include "qif.h"
#include "acconf.h"
@@ -164,8 +163,6 @@ int parse_and_report(int argc, char * argv[], char * envp[])
{
std::auto_ptr<journal_t> journal(new journal_t);
- add_hook(journal->entry_finalize_hooks, handle_auto_xacts);
-
// Parse command-line arguments, and those set in the environment
TIMER_START(process_opts);
diff --git a/parser.cc b/parser.cc
index 46c334d0..bbedaa7d 100644
--- a/parser.cc
+++ b/parser.cc
@@ -1,5 +1,5 @@
#include "parser.h"
-#include "ledger.h"
+#include "journal.h"
#include <fstream>
#include <deque>
diff --git a/python.cc b/python.cc
index a7abb1ec..6c2fef2a 100644
--- a/python.cc
+++ b/python.cc
@@ -1,5 +1,5 @@
#include "python.h"
-#include "ledger.h"
+#include "journal.h"
#include "acconf.h"
#include <boost/python.hpp>
diff --git a/qif.cc b/qif.cc
index 987dc65c..c8b8aa22 100644
--- a/qif.cc
+++ b/qif.cc
@@ -1,4 +1,4 @@
-#include "ledger.h"
+#include "journal.h"
#include "qif.h"
#include "datetime.h"
#include "error.h"
diff --git a/textual.cc b/textual.cc
index 18eef1e0..b6bc934c 100644
--- a/textual.cc
+++ b/textual.cc
@@ -1,4 +1,4 @@
-#include "ledger.h"
+#include "journal.h"
#include "textual.h"
#include "datetime.h"
#include "autoxact.h"
@@ -223,6 +223,7 @@ unsigned int textual_parser_t::parse(std::istream& in,
account_t * master,
const std::string * original_file)
{
+ static bool added_autoxact_hook = false;
static char line[MAX_LINE + 1];
char c;
unsigned int count = 0;
@@ -431,6 +432,10 @@ unsigned int textual_parser_t::parse(std::istream& in,
}
case '=': // automated transactions
+ if (! added_autoxact_hook) {
+ add_hook(journal->entry_finalize_hooks, handle_auto_xacts);
+ added_autoxact_hook = true;
+ }
parse_automated_transactions(in, account_stack.front(), auto_xacts);
break;
diff --git a/valexpr.h b/valexpr.h
index 1ae9d5a9..7950a674 100644
--- a/valexpr.h
+++ b/valexpr.h
@@ -1,7 +1,7 @@
#ifndef _EXPR_H
#define _EXPR_H
-#include "ledger.h"
+#include "journal.h"
#include "value.h"
#include "error.h"
diff --git a/walk.h b/walk.h
index b78ae733..40d2b66b 100644
--- a/walk.h
+++ b/walk.h
@@ -1,7 +1,7 @@
#ifndef _WALK_H
#define _WALK_H
-#include "ledger.h"
+#include "journal.h"
#include "balance.h"
#include "valexpr.h"
#include "datetime.h"