moved curl requester to no args section; when called with file arg will now execute that local file

This commit is contained in:
Bob Polis 2020-09-21 10:46:31 +02:00
parent 49626f9925
commit a9b707599f

View File

@ -11,6 +11,7 @@
#include <string> #include <string>
#include <stdexcept> #include <stdexcept>
#include <sstream> #include <sstream>
#include <fstream>
#include <getopt.h> #include <getopt.h>
#include <libsclogging.hpp> #include <libsclogging.hpp>
#include "requester.hpp" #include "requester.hpp"
@ -30,8 +31,6 @@ void print_version() {
int main(int argc, const char * argv[]) { int main(int argc, const char * argv[]) {
try { try {
std::string base_url {"https://www.swiftcoder.nl/cpp1/"};
std::string next_url {"start.txt"};
int opt_char, opt_val; int opt_char, opt_val;
struct option long_options[] = { struct option long_options[] = {
{"help", no_argument, nullptr, 'h'}, {"help", no_argument, nullptr, 'h'},
@ -57,28 +56,32 @@ int main(int argc, const char * argv[]) {
throw std::runtime_error("unrecognized option"); throw std::runtime_error("unrecognized option");
} }
} }
interpreter proc;
bool done {false};
if (optind == argc) { if (optind == argc) {
// here when no file args // 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) { for (int i = optind; i < argc; ++i) {
try { try {
next_url = argv[i]; done = false;
std::ifstream file {argv[i]};
proc.eval(file, done);
} catch (const std::runtime_error& ex) { } catch (const std::runtime_error& ex) {
std::cerr << "curly: " << ex.what() << '\n'; 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) { } catch (const std::exception& ex) {
std::cerr << "curly: " << ex.what() << '\n'; std::cerr << "curly: " << ex.what() << '\n';