From c927c74c2d6fb0aabb95e552af8ca5ec1e749cd1 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 10 Nov 2009 00:30:09 -0500 Subject: Throw an exception if an include file doesn't exist --- src/textual.cc | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/textual.cc') diff --git a/src/textual.cc b/src/textual.cc index 37c38e55..badbdee5 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -613,6 +613,10 @@ void instance_t::include_directive(char * line) DEBUG("textual.include", "Line " << linenum << ": " << "Including path '" << filename << "'"); + if (! exists(filename)) + throw_(std::runtime_error, + _("File to include was not found: '%1'" << filename)); + ifstream stream(filename); instance_t instance(account_stack, tag_stack, -- cgit v1.2.3 From 09c9ec4b41fa93c2a4637b5715bbb8dedf875192 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 10 Nov 2009 01:05:12 -0500 Subject: Directives no longer require @ or ! prefix char --- src/textual.cc | 121 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 62 insertions(+), 59 deletions(-) (limited to 'src/textual.cc') diff --git a/src/textual.cc b/src/textual.cc index badbdee5..238098f1 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -125,7 +125,7 @@ namespace { void tag_directive(char * line); void pop_directive(char * line); void define_directive(char * line); - void general_directive(char * line); + bool general_directive(char * line); post_t * parse_post(char * line, std::streamsize len, @@ -354,51 +354,53 @@ void instance_t::read_next_directive() period_xact_directive(line); break; -#if defined(TIMELOG_SUPPORT) - case 'i': - clock_in_directive(line, false); - break; - case 'I': - clock_in_directive(line, true); - break; - - case 'o': - clock_out_directive(line, false); - break; - case 'O': - clock_out_directive(line, true); - break; - - case 'h': - case 'b': - break; -#endif // TIMELOG_SUPPORT - - case 'A': // a default account for unbalanced posts - default_account_directive(line); - break; - case 'C': // a set of conversions - price_conversion_directive(line); - break; - case 'D': // a default commodity for "xact" - default_commodity_directive(line); - break; - case 'N': // don't download prices - nomarket_directive(line); - break; - case 'P': // a pricing xact - price_xact_directive(line); - break; - case 'Y': // set the current year - year_directive(line); - break; - case '@': case '!': line++; // fall through... default: // some other directive - general_directive(line); + if (! general_directive(line)) { + switch (line[0]) { +#if defined(TIMELOG_SUPPORT) + case 'i': + clock_in_directive(line, false); + break; + case 'I': + clock_in_directive(line, true); + break; + + case 'o': + clock_out_directive(line, false); + break; + case 'O': + clock_out_directive(line, true); + break; + + case 'h': + case 'b': + break; +#endif // TIMELOG_SUPPORT + + case 'A': // a default account for unbalanced posts + default_account_directive(line); + break; + case 'C': // a set of conversions + price_conversion_directive(line); + break; + case 'D': // a default commodity for "xact" + default_commodity_directive(line); + break; + case 'N': // don't download prices + nomarket_directive(line); + break; + case 'P': // a pricing xact + price_xact_directive(line); + break; + case 'Y': // set the current year + year_directive(line); + break; + } + } break; } } @@ -689,58 +691,56 @@ void instance_t::define_directive(char * line) def.compile(scope); // causes definitions to be established } -void instance_t::general_directive(char * line) +bool instance_t::general_directive(char * line) { - char * p = line; - char * arg = next_element(line); - + char * p = line; if (*p == '@' || *p == '!') p++; switch (*p) { case 'a': if (std::strcmp(p, "account") == 0) { - account_directive(arg); - return; + account_directive(next_element(line)); + return true; } else if (std::strcmp(p, "alias") == 0) { - alias_directive(arg); - return; + alias_directive(next_element(line)); + return true; } break; case 'd': if (std::strcmp(p, "def") == 0) { - define_directive(arg); - return; + define_directive(next_element(line)); + return true; } break; case 'e': if (std::strcmp(p, "end") == 0) { - end_directive(arg); - return; + end_directive(next_element(line)); + return true; } break; case 'i': if (std::strcmp(p, "include") == 0) { - include_directive(arg); - return; + include_directive(next_element(line)); + return true; } break; case 'p': if (std::strcmp(p, "pop") == 0) { - pop_directive(arg); - return; + pop_directive(next_element(line)); + return true; } break; case 't': if (std::strcmp(p, "tag") == 0) { - tag_directive(arg); - return; + tag_directive(next_element(line)); + return true; } break; } @@ -749,7 +749,10 @@ void instance_t::general_directive(char * line) call_scope_t args(*this); args.push_back(string_value(p)); op->as_function()(args); + return true; } + + return false; } post_t * instance_t::parse_post(char * line, -- cgit v1.2.3 From 009b25739728de755892fdc542038c570ba67ba6 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 10 Nov 2009 01:05:44 -0500 Subject: It's now an error to use "end" without "account" --- src/textual.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/textual.cc') diff --git a/src/textual.cc b/src/textual.cc index 238098f1..ca7aa190 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -643,9 +643,9 @@ void instance_t::account_directive(char * line) void instance_t::end_directive(char *) { - if (account_stack.empty()) + if (account_stack.size() <= 1) throw_(std::runtime_error, - _("'end' directive found, but no account currently active")); + _("'end' directive found, but no master account currently active")); else account_stack.pop_back(); } -- cgit v1.2.3 From 16a2a16097e356a12feb18a091fd4f19993c350e Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 10 Nov 2009 01:06:04 -0500 Subject: Support include-ing of relative pathnames --- src/textual.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/textual.cc') diff --git a/src/textual.cc b/src/textual.cc index ca7aa190..1d8de046 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -608,7 +608,17 @@ void instance_t::xact_directive(char * line, std::streamsize len) void instance_t::include_directive(char * line) { - path filename(line); + path filename; + + if (line[0] != '/' && line[0] != '\\' && line[0] != '~') { + string::size_type pos = pathname.string().rfind('/'); + if (pos == string::npos) + pos = pathname.string().rfind('\\'); + if (pos != string::npos) + filename = path(string(pathname.string(), 0, pos + 1)) / line; + } else { + filename = line; + } filename = resolve_path(filename); -- cgit v1.2.3 From 3e39329eff14b02d9f72c506839ea9bf908116aa Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 10 Nov 2009 01:28:42 -0500 Subject: Added "bucket" directive, as alt for A --- src/textual.cc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/textual.cc') diff --git a/src/textual.cc b/src/textual.cc index 1d8de046..c3a44be6 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -119,7 +119,7 @@ namespace { void period_xact_directive(char * line); void xact_directive(char * line, std::streamsize len); void include_directive(char * line); - void account_directive(char * line); + void master_account_directive(char * line); void end_directive(char * line); void alias_directive(char * line); void tag_directive(char * line); @@ -643,7 +643,7 @@ void instance_t::include_directive(char * line) count += instance.count; } -void instance_t::account_directive(char * line) +void instance_t::master_account_directive(char * line) { if (account_t * acct = account_stack.front()->find_account(line)) account_stack.push_front(acct); @@ -710,7 +710,7 @@ bool instance_t::general_directive(char * line) switch (*p) { case 'a': if (std::strcmp(p, "account") == 0) { - account_directive(next_element(line)); + master_account_directive(next_element(line)); return true; } else if (std::strcmp(p, "alias") == 0) { @@ -719,8 +719,15 @@ bool instance_t::general_directive(char * line) } break; + case 'b': + if (std::strcmp(p, "bucket") == 0) { + default_account_directive(next_element(line)); + return true; + } + break; + case 'd': - if (std::strcmp(p, "def") == 0) { + if (std::strcmp(p, "def") == 0 || std::strcmp(p, "define") == 0) { define_directive(next_element(line)); return true; } @@ -983,8 +990,8 @@ post_t * instance_t::parse_post(char * line, << "POST assign: parsed amt = " << *post->assigned_amount); amount_t& amt(*post->assigned_amount); - value_t account_total(post->account->amount(false) - .strip_annotations(keep_details_t())); + value_t account_total + (post->account->amount(false).strip_annotations(keep_details_t())); DEBUG("post.assign", "line " << linenum << ": " "account balance = " << account_total); -- cgit v1.2.3 From 329a0dfcc53354be7873385383ca6d8238e5a97e Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 10 Nov 2009 02:26:34 -0500 Subject: Corrected the parsing of data file directives --- src/textual.cc | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src/textual.cc') diff --git a/src/textual.cc b/src/textual.cc index c3a44be6..5a9e2165 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -703,60 +703,66 @@ void instance_t::define_directive(char * line) bool instance_t::general_directive(char * line) { - char * p = line; + char buf[8192]; + + std::strcpy(buf, line); + + char * p = buf; + char * arg = next_element(buf); + if (*p == '@' || *p == '!') p++; switch (*p) { case 'a': if (std::strcmp(p, "account") == 0) { - master_account_directive(next_element(line)); + master_account_directive(arg); return true; } else if (std::strcmp(p, "alias") == 0) { - alias_directive(next_element(line)); + alias_directive(arg); return true; } break; case 'b': if (std::strcmp(p, "bucket") == 0) { - default_account_directive(next_element(line)); + default_account_directive(arg); return true; } break; case 'd': if (std::strcmp(p, "def") == 0 || std::strcmp(p, "define") == 0) { - define_directive(next_element(line)); + define_directive(arg); return true; } break; case 'e': if (std::strcmp(p, "end") == 0) { - end_directive(next_element(line)); + end_directive(arg); return true; } break; case 'i': if (std::strcmp(p, "include") == 0) { - include_directive(next_element(line)); + include_directive(arg); return true; } break; case 'p': if (std::strcmp(p, "pop") == 0) { - pop_directive(next_element(line)); + pop_directive(arg); return true; } break; case 't': if (std::strcmp(p, "tag") == 0) { - tag_directive(next_element(line)); + tag_directive(arg); return true; } break; -- cgit v1.2.3 From 39532bdf357e0aa696c7cc50787d3bb9e68d4ede Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 10 Nov 2009 02:44:16 -0500 Subject: Automated transactions now use report query syntax This returns their behavior back very close to what 2.x accepts. --- src/textual.cc | 5 +++-- test/baseline/opt-actual.test | 2 +- test/regress/5A03CFC3.test | 2 +- test/regress/727B2DF8.test | 2 +- test/regress/793F6BF0.test | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src/textual.cc') diff --git a/src/textual.cc b/src/textual.cc index 5a9e2165..1d0d7998 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -36,6 +36,7 @@ #include "post.h" #include "account.h" #include "option.h" +#include "query.h" #include "pstream.h" #include "pool.h" #include "session.h" @@ -508,8 +509,8 @@ void instance_t::automated_xact_directive(char * line) } std::auto_ptr ae - (new auto_xact_t(predicate_t(skip_ws(line + 1), - keep_details_t(true, true, true)))); + (new auto_xact_t(query_t(string(skip_ws(line + 1)), + keep_details_t(true, true, true)))); reveal_context = false; diff --git a/test/baseline/opt-actual.test b/test/baseline/opt-actual.test index 1d9ddc89..8e7b432e 100644 --- a/test/baseline/opt-actual.test +++ b/test/baseline/opt-actual.test @@ -1,6 +1,6 @@ print --actual <<< -= account =~ /Books/ += Books Expenses:Taxes 0.05 Assets:Checking -0.05 diff --git a/test/regress/5A03CFC3.test b/test/regress/5A03CFC3.test index a5a12af3..440ff960 100644 --- a/test/regress/5A03CFC3.test +++ b/test/regress/5A03CFC3.test @@ -1,6 +1,6 @@ bal assets <<< -= account =~ /^Income/ += /^Income/ (Liabilities:Tithe) 0.12 ~ Monthly diff --git a/test/regress/727B2DF8.test b/test/regress/727B2DF8.test index 8c29e1ff..a13e8292 100644 --- a/test/regress/727B2DF8.test +++ b/test/regress/727B2DF8.test @@ -2,7 +2,7 @@ reg --color --force-color <<< N $ -= account =~ /^Expenses:Books/ += /^Expenses:Books/ (Liabilities:Taxes) -0.10 ~ Monthly diff --git a/test/regress/793F6BF0.test b/test/regress/793F6BF0.test index 754ddca3..059bd9b6 100644 --- a/test/regress/793F6BF0.test +++ b/test/regress/793F6BF0.test @@ -2,7 +2,7 @@ entry 2009/03/15 book 10 <<< N $ -= account =~ /^Expenses:Books/ += /^Expenses:Books/ (Liabilities:Taxes) -0.10 ~ Monthly -- cgit v1.2.3