moved curl requester to no args section; when called with file arg will now execute that local file
This commit is contained in:
		
							
								
								
									
										31
									
								
								main.cpp
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								main.cpp
									
									
									
									
									
								
							@@ -11,6 +11,7 @@
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <stdexcept>
 | 
			
		||||
#include <sstream>
 | 
			
		||||
#include <fstream>
 | 
			
		||||
#include <getopt.h>
 | 
			
		||||
#include <libsclogging.hpp>
 | 
			
		||||
#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';
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user