diff --git a/main.cpp b/main.cpp index 59a702e..c6fa958 100644 --- a/main.cpp +++ b/main.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include "requester.hpp" @@ -30,8 +31,6 @@ void print_version() { int main(int argc, const char * argv[]) { try { - std::string base_url {"https://www.swiftcoder.nl/cpp1/"}; - std::string next_url {"start.txt"}; int opt_char, opt_val; struct option long_options[] = { {"help", no_argument, nullptr, 'h'}, @@ -57,28 +56,32 @@ int main(int argc, const char * argv[]) { throw std::runtime_error("unrecognized option"); } } + interpreter proc; + bool done {false}; if (optind == argc) { // here when no file args + std::string base_url {"https://www.swiftcoder.nl/cpp1/"}; + std::string next_url {"start.txt"}; + std::string code; + requester req; + while (!done) { + code = req.get(base_url + next_url); + std::istringstream in {code}; + next_url = proc.eval(in, done); + SCInfo(logger, next_url); + } + std::cout << next_url << '\n'; } for (int i = optind; i < argc; ++i) { try { - next_url = argv[i]; + done = false; + std::ifstream file {argv[i]}; + proc.eval(file, done); } catch (const std::runtime_error& ex) { std::cerr << "curly: " << ex.what() << '\n'; } } - bool done {false}; - std::string code; - requester req; - interpreter proc; - while (!done) { - code = req.get(base_url + next_url); - std::istringstream in {code}; - next_url = proc.eval(in, done); - SCInfo(logger, next_url); - } - std::cout << next_url << '\n'; } catch (const std::exception& ex) { std::cerr << "curly: " << ex.what() << '\n';