summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--amount.h32
-rw-r--r--binary.cc44
-rw-r--r--ledger.h33
-rw-r--r--main.cc13
4 files changed, 68 insertions, 54 deletions
diff --git a/amount.h b/amount.h
index 03d4e095..5e31d95f 100644
--- a/amount.h
+++ b/amount.h
@@ -171,13 +171,13 @@ inline std::istream& operator>>(std::istream& in, amount_t& amt) {
std::ostream& operator<<(std::ostream& out, const amount_t& amt);
-#define COMMODITY_STYLE_DEFAULTS 0x00
-#define COMMODITY_STYLE_SUFFIXED 0x01
-#define COMMODITY_STYLE_SEPARATED 0x02
-#define COMMODITY_STYLE_EUROPEAN 0x04
-#define COMMODITY_STYLE_THOUSANDS 0x08
-#define COMMODITY_STYLE_CONSULTED 0x10
-#define COMMODITY_STYLE_NOMARKET 0x20
+#define COMMODITY_STYLE_DEFAULTS 0x0000
+#define COMMODITY_STYLE_SUFFIXED 0x0001
+#define COMMODITY_STYLE_SEPARATED 0x0002
+#define COMMODITY_STYLE_EUROPEAN 0x0004
+#define COMMODITY_STYLE_THOUSANDS 0x0008
+#define COMMODITY_STYLE_CONSULTED 0x0010
+#define COMMODITY_STYLE_NOMARKET 0x0020
typedef std::map<const std::time_t, amount_t> history_map;
typedef std::pair<const std::time_t, amount_t> history_pair;
@@ -197,16 +197,16 @@ class commodity_t
const std::time_t moment) = 0;
};
- typedef unsigned short ident_t;
+ typedef unsigned long ident_t;
- std::string symbol;
- std::string name;
- std::string note;
- unsigned int precision;
- unsigned int flags;
- history_map history;
- amount_t conversion;
- ident_t ident;
+ std::string symbol;
+ std::string name;
+ std::string note;
+ unsigned short precision;
+ unsigned short flags;
+ history_map history;
+ amount_t conversion;
+ ident_t ident;
// If set, this global function pointer is called to determine
// whether prices have been updated in the meanwhile.
diff --git a/binary.cc b/binary.cc
index a16808f0..8f622cb7 100644
--- a/binary.cc
+++ b/binary.cc
@@ -14,8 +14,6 @@
namespace ledger {
-static char buf[4096];
-
unsigned long binary_magic_number = 0xFFEED765;
static unsigned long format_version = 0x0002000a;
@@ -53,10 +51,22 @@ inline void read_binary_string(std::istream& in, std::string& str)
unsigned char len;
read_binary_number(in, len);
- if (len) {
+ if (len == 0xff) {
+ unsigned short slen;
+ read_binary_number(in, slen);
+ char * buf = new char[slen + 1];
+ in.read(buf, slen);
+ buf[slen] = '\0';
+ str = buf;
+ delete[] buf;
+ }
+ else if (len) {
+ char buf[256];
in.read(buf, len);
buf[len] = '\0';
str = buf;
+ } else {
+ str = "";
}
read_binary_guard(in, 0x3002);
@@ -64,20 +74,9 @@ inline void read_binary_string(std::istream& in, std::string& str)
inline std::string read_binary_string(std::istream& in)
{
- read_binary_guard(in, 0x3001);
-
- unsigned char len;
- read_binary_number(in, len);
- if (len) {
- in.read(buf, len);
- buf[len] = '\0';
- read_binary_guard(in, 0x3002);
- return buf;
- }
-
- read_binary_guard(in, 0x3002);
-
- return "";
+ std::string temp;
+ read_binary_string(in, temp);
+ return temp;
}
void read_binary_amount(std::istream& in, amount_t& amt)
@@ -271,8 +270,15 @@ inline void write_binary_string(std::ostream& out, const std::string& str)
{
write_binary_guard(out, 0x3001);
- unsigned char len = str.length();
- write_binary_number(out, len);
+ unsigned long len = str.length();
+ if (len > 255) {
+ assert(len < 65536);
+ write_binary_number<unsigned char>(out, 0xff);
+ write_binary_number<unsigned short>(out, len);
+ } else {
+ write_binary_number<unsigned char>(out, len);
+ }
+
if (len)
out.write(str.c_str(), len);
diff --git a/ledger.h b/ledger.h
index 1e0759aa..885e451a 100644
--- a/ledger.h
+++ b/ledger.h
@@ -27,14 +27,16 @@
namespace ledger {
-#define TRANSACTION_NORMAL 0x00
-#define TRANSACTION_VIRTUAL 0x01
-#define TRANSACTION_BALANCE 0x02
-#define TRANSACTION_AUTO 0x04
+// These flags persist with the object
+#define TRANSACTION_NORMAL 0x0000
+#define TRANSACTION_VIRTUAL 0x0001
+#define TRANSACTION_BALANCE 0x0002
+#define TRANSACTION_AUTO 0x0004
-#define TRANSACTION_HANDLED 0x10
-#define TRANSACTION_DISPLAYED 0x20
-#define TRANSACTION_NO_TOTAL 0x40
+// These flags are only used during formatting, and are not saved
+#define TRANSACTION_HANDLED 0x0001
+#define TRANSACTION_DISPLAYED 0x0002
+#define TRANSACTION_NO_TOTAL 0x0004
class entry_t;
class account_t;
@@ -46,12 +48,12 @@ class transaction_t
account_t * account;
amount_t amount;
amount_t cost;
- unsigned int flags;
+ unsigned short flags;
std::string note;
mutable balance_pair_t total;
mutable unsigned int index;
- mutable unsigned int dflags;
+ mutable unsigned short dflags;
transaction_t(entry_t * _entry, account_t * _account)
: entry(_entry), account(_account), flags(TRANSACTION_NORMAL),
@@ -110,12 +112,12 @@ typedef std::pair<const std::string, account_t *> accounts_pair;
class account_t
{
public:
- typedef unsigned short ident_t;
+ typedef unsigned long ident_t;
account_t * parent;
std::string name;
std::string note;
- unsigned char depth;
+ unsigned short depth;
accounts_map accounts;
transactions_list transactions;
@@ -174,10 +176,11 @@ typedef std::list<std::string> strings_list;
class journal_t
{
public:
- account_t * master;
- entries_list entries;
- mutable accounts_map accounts_cache;
- std::list<std::string> sources;
+ account_t * master;
+ entries_list entries;
+ strings_list sources;
+
+ mutable accounts_map accounts_cache;
journal_t() {
master = new account_t(NULL, "");
diff --git a/main.cc b/main.cc
index fd9342df..4223b3ff 100644
--- a/main.cc
+++ b/main.cc
@@ -50,7 +50,7 @@ int main(int argc, char * argv[], char * envp[])
TIMER_STOP(process_args);
- const bool use_cache = config->files.empty();
+ bool use_cache = config->files.empty();
// Process options from the environment
@@ -91,6 +91,7 @@ int main(int argc, char * argv[], char * envp[])
if (entry_count == 0 || exceptions.size() > 0) {
journal.reset(new journal_t);
entry_count = 0;
+ cache_dirty = true;
} else {
cache_dirty = false;
}
@@ -100,7 +101,13 @@ int main(int argc, char * argv[], char * envp[])
for (strings_list::iterator i = config->files.begin();
i != config->files.end();
i++)
- entry_count += parse_journal_file(*i, journal.get());
+ if (*i == "-") {
+ use_cache = false;
+ entry_count += parse_textual_journal(std::cin, journal.get(),
+ journal->master);
+ } else {
+ entry_count += parse_journal_file(*i, journal.get());
+ }
if (! config->price_db.empty())
if (parse_journal_file(config->price_db, journal.get()))
@@ -452,8 +459,6 @@ int main(int argc, char * argv[], char * envp[])
// feeding each transaction that matches `predicate' to the chain.
walk_entries(journal->entries, *formatter.get());
- formatter->flush();
-
#ifdef DEBUG_ENABLED
// The transaction display flags (dflags) are not recorded in the
// binary cache, and only need to be cleared if the transactions