diff --git a/main.cpp b/main.cpp index 0a2e78e..dd949d2 100644 --- a/main.cpp +++ b/main.cpp @@ -1,3 +1,5 @@ +#include +#include #include #include #include @@ -35,16 +37,15 @@ input_data(istream& in, bool prompt) return rez; } -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[1]); + curl_easy_setopt(curl, CURLOPT_URL, address.c_str()); res = curl_easy_perform(curl); if (res != 0) { @@ -53,13 +54,23 @@ main(int argc, char* argv[]) } curl_easy_cleanup(curl); } - return 0; + return input_data(buffer, false); +} + +int +main(int argc, char* argv[]) +{ + Input input; + if (argc > 1) { + input = download(argv[1]); + } else { + input = input_data(cin, true); } curl_global_init(CURL_GLOBAL_ALL); bool prompt = false; auto in = input_data(cin, prompt); - auto bins = make_histogram(in.numbers, in.bin_count); - //show_histogram_svg(bins); - show_histogram_text(bins, in.numbers, in.bin_count); + const auto bins = make_histogram(in.numbers, in.bin_count); + show_histogram_svg(bins); + //show_histogram_text(bins, in.numbers, in.bin_count); }