(KasimovAM) 2 лет назад
Родитель 0fa70231ac
Сommit c566264115

@ -46,12 +46,15 @@ size_t write_data(void* items, size_t item_size, size_t item_count, void* ctx)
} }
Input Input
download(const string& address) { download(const string& address)
stringstream buffer; {
stringstream buffer;
CURL *curl = curl_easy_init(); CURL *curl = curl_easy_init();
if(curl) if(curl)
{ {
CURLcode res; CURLcode res;
curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
curl_version_info_data *version = curl_version_info(CURLVERSION_NOW);
curl_easy_setopt(curl, CURLOPT_URL, address.c_str()); curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
@ -61,9 +64,16 @@ stringstream buffer;
fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res)); fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res));
exit(1); exit(1);
} }
curl_easy_cleanup(curl); else
{
fprintf(stderr,"libcurl version %u.%u.%u\n",
(ver->version_num >> 16) & 0xff,
(ver->version_num >> 8) & 0xff,
ver->version_num & 0xff);
cerr << "OpenSSL version " << version->ssl_version << endl;
}
} }
curl_easy_cleanup(curl);
return input_data(buffer, false); return input_data(buffer, false);
} }
@ -71,14 +81,18 @@ stringstream buffer;
int int
main(int argc, char* argv[]) { main(int argc, char* argv[])
{
Input input; Input input;
if (argc > 1) { if (argc > 1)
{
input = download(argv[1]); input = download(argv[1]);
} else { }
else
{
input = input_data(cin, true); input = input_data(cin, true);
} }
const auto bins = make_histogram(input.numbers, input.bin_count); const auto bins = make_histogram(input.numbers, input.bin_count);
show_histogram_svg(bins); show_histogram_svg(bins);
} }

Загрузка…
Отмена
Сохранить