diff options
author | John Wiegley <johnw@newartisans.com> | 2010-06-24 20:29:20 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-06-24 20:29:20 -0400 |
commit | 35da9ad4665416fe8b016f3fd7cad4975fc3e090 (patch) | |
tree | 000509043e43b74b2e546fe4b06090e5b5a87c5a /src/expr.cc | |
parent | 024fb4f3e0f659fca5aa3770d5d70ac5827797f7 (diff) | |
download | fork-ledger-35da9ad4665416fe8b016f3fd7cad4975fc3e090.tar.gz fork-ledger-35da9ad4665416fe8b016f3fd7cad4975fc3e090.tar.bz2 fork-ledger-35da9ad4665416fe8b016f3fd7cad4975fc3e090.zip |
Added "source" command, for executing valexpr files
Diffstat (limited to 'src/expr.cc')
-rw-r--r-- | src/expr.cc | 24 |
1 files changed, 24 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 |