#include #include "histogram.h" #include "svg.h" #include #include #include using namespace std; struct Input { vector numbers; size_t bin_count{}; }; Input input_data(istream& sin, bool prompt = true) { if (prompt){ Input in; size_t number_count; cerr << "Input number count" << endl; sin >> number_count; in.numbers.resize(number_count); for (size_t i = 0; i < number_count; i++) { cerr << "Input number "<< i << endl; sin >> in.numbers[i]; } cerr << "Input bin count" << endl; sin >> in.bin_count; return in; } else{ Input in; size_t number_count; sin >> number_count; in.numbers.resize(number_count); for (size_t i = 0; i < number_count; i++) { sin >> in.numbers[i]; } sin >> in.bin_count; return in; } } size_t write_data(void* items, size_t item_size, size_t item_count, void* ctx) { size_t data_size = item_size * item_count; stringstream* buffer = reinterpret_cast(ctx); buffer->write(reinterpret_cast(items), data_size); return data_size; } Input download(const string& address) { stringstream buffer; CURL* curl = curl_easy_init(); if (curl) { CURLcode res; curl_easy_setopt(curl, CURLOPT_URL, address.c_str()); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer); res = curl_easy_perform(curl); if (res != CURLE_OK) { cout << curl_easy_strerror(res); exit(1); } curl_easy_cleanup(curl); } return input_data(buffer, false); } int main(int argc, char* argv[]) { Input in; string link, color = ""; bool flag = false; if (argc == 2) { in = download(argv[1]); } else if (argc == 3) { cout << "Wrong argument, use correct input -stroke or leave input empty" << endl; exit(2); } else if (argc > 3) { for (size_t i = 1; i < argc; i++) { string cur = argv[i]; if (cur.find("://") != string::npos) { link = cur; } else if (i != argc - 1){ string curm = argv[i+1]; if (cur == "-stroke" && curm.find("://") == string::npos) { flag = true; color = curm; } } else if (cur == "-stroke" && i == (argc - 1)) { cout << "Wrong argument, use correct input -stroke or leave input empty" << endl; exit(2); } } in = download(link); } else { in = input_data(cin, false); } auto bins = make_histogram(in.numbers, in.bin_count); show_histogram_svg(bins, color); return 0; }