summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2010-06-24 20:29:20 -0400
committerJohn Wiegley <johnw@newartisans.com>2010-06-24 20:29:20 -0400
commit35da9ad4665416fe8b016f3fd7cad4975fc3e090 (patch)
tree000509043e43b74b2e546fe4b06090e5b5a87c5a
parent024fb4f3e0f659fca5aa3770d5d70ac5827797f7 (diff)
downloadfork-ledger-35da9ad4665416fe8b016f3fd7cad4975fc3e090.tar.gz
fork-ledger-35da9ad4665416fe8b016f3fd7cad4975fc3e090.tar.bz2
fork-ledger-35da9ad4665416fe8b016f3fd7cad4975fc3e090.zip
Added "source" command, for executing valexpr files
-rw-r--r--src/expr.cc24
-rw-r--r--src/expr.h4
-rw-r--r--src/report.cc2
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
diff --git a/src/expr.h b/src/expr.h
index e6eeebf6..a3ae5669 100644
--- a/src/expr.h
+++ b/src/expr.h
@@ -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':