|
|
@@ -20,15 +20,22 @@ void usage() {
|
|
|
std::cout << "'1d6+$Dex' : Roll 1d6 plus whatever value subs for 'Dex'\n";
|
|
|
}
|
|
|
|
|
|
-void print_binding(std::pair<const std::string, std::string> const & pair,
|
|
|
- std::ostream & os = std::cout) {
|
|
|
+void print_binding_os(std::pair<const std::string, std::string> const & pair,
|
|
|
+ std::ostream & os) {
|
|
|
os << pair.first;
|
|
|
if (pair.second == "") os << " is not defined\n";
|
|
|
else os << " := " << pair.second << "\n";
|
|
|
}
|
|
|
|
|
|
+void print_binding(std::pair<const std::string, std::string> const & pair) {
|
|
|
+ print_binding_os(pair, std::cout);
|
|
|
+}
|
|
|
+
|
|
|
class evaluator {
|
|
|
public:
|
|
|
+ evaluator(std::string const & path = "") {
|
|
|
+ if (!path.empty()) { load(path); }
|
|
|
+ }
|
|
|
void operator()(std::string const & str);
|
|
|
|
|
|
private:
|
|
|
@@ -47,7 +54,7 @@ private:
|
|
|
using namespace std::placeholders;
|
|
|
std::ofstream out(file);
|
|
|
std::for_each(bindings.begin(), bindings.end(),
|
|
|
- std::bind(&print_binding, _1, std::ref(out)));
|
|
|
+ std::bind(&print_binding_os, _1, std::ref(out)));
|
|
|
}
|
|
|
void load(std::string const & file) {
|
|
|
std::ifstream in(file);
|
|
|
@@ -98,10 +105,10 @@ void evaluator::operator()(std::string const & str) {
|
|
|
}
|
|
|
|
|
|
|
|
|
-int main(int, const char **) {
|
|
|
+int main(int argc, const char * argv[]) {
|
|
|
std::string line;
|
|
|
std::cout << "> ";
|
|
|
- evaluator eval;
|
|
|
+ evaluator eval(argc > 1 ? argv[1] : "");
|
|
|
while (std::getline(std::cin, line)) {
|
|
|
eval(line);
|
|
|
std::cout << "> ";
|