diff --git a/main.cpp b/main.cpp index d185251..774c343 100644 --- a/main.cpp +++ b/main.cpp @@ -7,6 +7,8 @@ #include "text.h" #include "svg.h" #include +#include +#include using namespace std; @@ -50,36 +52,36 @@ Input input_data(istream& in, bool prompt) return stct; } -int main(int argc, char* argv[]) +Input +download(const string& address) { - curl_global_init(CURL_GLOBAL_ALL); + stringstream buffer; - if (argc > 1) + CURL *curl = curl_easy_init(); + if(curl) { - CURL *curl = curl_easy_init(); - if(curl) + CURLcode res; + curl_easy_setopt(curl, CURLOPT_URL, address.c_str()); + res = curl_easy_perform(curl); + if (res != CURLE_OK) { - CURLcode res; - curl_easy_setopt(curl, CURLOPT_URL, argv[1]); - res = curl_easy_perform(curl); - if (res != CURLE_OK){ - cerr << curl_easy_strerror(res); - exit(1); - } - curl_easy_cleanup(curl); + cerr << curl_easy_strerror(res); + exit(1); } - return 0; + curl_easy_cleanup(curl); } + return input_data(buffer, false); +} - //Ввод массива и количества корзин - auto in = input_data(cin, true); - - //Создание вектора bins для гистограммы - vector bins = make_histogram(in.Numbers, in.bin_count); +int +main(int argc, char* argv[]) { + Input input; + if (argc > 1) { + input = download(argv[1]); + } else { + input = input_data(cin, true); + } - //Вывод гистограммы + const auto bins = make_histogram(input.Numbers, input.bin_count); show_histogram_svg(bins); - //show_histogram_text(bins); - - return 0; }