diff --git a/main.cpp b/main.cpp index caf385e..cf0e423 100644 --- a/main.cpp +++ b/main.cpp @@ -1,3 +1,5 @@ +#include <sstream> +#include <string> #include <curl/curl.h> #include <iostream> #include <vector> @@ -57,28 +59,37 @@ input_data(istream& in, bool prompt) { } - -int main(int argc, char* argv[]) -{ - if (argc>1){ +Input +download(const string& address) { + stringstream buffer; CURL *curl = curl_easy_init(); if(curl) { CURLcode res; - curl_easy_setopt(curl, CURLOPT_URL, argv[0]); + curl_easy_setopt(curl, CURLOPT_URL, address.c_str()); res = curl_easy_perform(curl); curl_easy_cleanup(curl); if (res!=0){ cout<<res; exit(1); + } } - } + curl_global_init(CURL_GLOBAL_ALL); + return input_data(buffer, false); } - curl_global_init(CURL_GLOBAL_ALL); +int main(int argc, char* argv[]) +{ + Input input; + if (argc > 1) { + input = download(argv[1]); + } else { + input = input_data(cin, true); + } + auto in = input_data(cin, true); - auto bins = make_histogram(in.numbers, in.bin_count, in.number_count, in.max_count); + const auto bins = make_histogram(in.numbers, in.bin_count, in.number_count, in.max_count); vector<double> test; show_histogram_svg(bins, in.max_count, in.bin_count, test);