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; }