diff options
-rw-r--r-- | src/expr.cc | 24 | ||||
-rw-r--r-- | src/expr.h | 4 | ||||
-rw-r--r-- | src/report.cc | 2 |
3 files changed, 30 insertions, 0 deletions
diff --git a/src/expr.cc b/src/expr.cc index 5bc537d9..878da3f7 100644 --- a/src/expr.cc +++ b/src/expr.cc @@ -33,6 +33,7 @@ #include "expr.h" #include "parser.h" +#include "scope.h" namespace ledger { @@ -162,4 +163,27 @@ void expr_t::dump(std::ostream& out) const if (ptr) ptr->dump(out, 0); } +value_t source_command(call_scope_t& args) +{ + std::istream * in = NULL; + scoped_ptr<ifstream> stream; + + if (args.has(0)) { + stream.reset(new ifstream(path(args.get<string>(0)))); + in = stream.get(); + } + + symbol_scope_t file_locals(args); + + while (in->good() && ! in->eof()) { + char buf[4096]; + in->getline(buf, 4095); + + if (buf[0] != ';') + expr_t(buf).calc(file_locals); + } + + return true; +} + } // namespace ledger @@ -160,6 +160,10 @@ inline value_t expr_value(expr_t::ptr_op_t op) { return temp; } +class call_scope_t; + +value_t source_command(call_scope_t& scope); + } // namespace ledger #endif // _EXPR_H diff --git a/src/report.cc b/src/report.cc index b9ed540c..8f06911c 100644 --- a/src/report.cc +++ b/src/report.cc @@ -1449,6 +1449,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind, case 's': if (is_eq(p, "stats") || is_eq(p, "stat")) return WRAP_FUNCTOR(report_statistics); + else if (is_eq(p, "source")) + return WRAP_FUNCTOR(source_command); break; case 'x': |