From f4b7b6e0fa66abcf2358e10cc61679dae496e9f3 Mon Sep 17 00:00:00 2001 From: TarasovEE Date: Sat, 13 Sep 2025 19:06:44 +0300 Subject: [PATCH] =?UTF-8?q?main:=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE?= =?UTF-8?q?=D0=BA=20=D1=81=20cURL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/main.cpp b/main.cpp index e38e2fd..7233e2f 100644 --- a/main.cpp +++ b/main.cpp @@ -5,6 +5,7 @@ #include #include "histogram.h" #include "text.h" +#include "svg.h" using namespace std; @@ -18,13 +19,13 @@ using namespace std; // Ввод оценкок с клавиатуры. -Input -input_data(istream& in, bool prompt) +Input input_data(istream& in, bool prompt) { Input local; size_t number_count; - cerr << "Enter number count: "; + if (prompt) + cerr << "Enter number count: "; in >> number_count; local.numbers.resize(number_count); for (size_t i = 0; i < number_count; i++) @@ -35,10 +36,20 @@ input_data(istream& in, bool prompt) return local; } +// Сохранение файла из сети в буфер. + +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) +Input download(const string& address) { stringstream buffer; @@ -46,7 +57,9 @@ download(const string& address) if(curl) { CURLcode res; - curl_easy_setopt(curl, CURLOPT_URL, address); + 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) { @@ -58,20 +71,9 @@ download(const string& address) return input_data(buffer, false); } -// Сохранение файла из сети в буфер. - -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; -} - - int main(int argc, char* argv[]) { + curl_global_init(CURL_GLOBAL_ALL); Input input; if (argc > 1) input = download(argv[1]); @@ -80,5 +82,7 @@ int main(int argc, char* argv[]) const auto bins = make_histogram(input.numbers, input.bin_count); show_histogram_svg(bins); + + return 0; }