diff --git a/.gitignore b/.gitignore index bad7699..8d734ee 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ /start /main.o /curl +/main_copy.cpp +/marks1.txt diff --git a/main.cpp b/main.cpp index 97cee27..3af0bb9 100755 --- a/main.cpp +++ b/main.cpp @@ -1,32 +1,44 @@ -//main.cpp -- the program gets number count, numbers and bin size, then builds a histogram. -//Task 15 -- make a scale under the histogram. - +#include #include #include -#include +#include +#include #include "histogram.h" #include "text.h" #include "svg.h" using namespace std; -struct Input { //data input + +struct Input { vector numbers; size_t bin_count{}; size_t interval_task{}; }; +size_t +write_data(void* items, size_t item_size, size_t item_count, void* ctx) { + size_t data_size = item_size * item_count; -Input -input_data(istream& in, bool prompt) { //input data structure + //struct Input *i = (struct Input *)ctx; + + stringstream* buffer = reinterpret_cast(ctx); + buffer->write(reinterpret_cast(items), data_size); + return data_size; +} + + + +Input +input_data(istream& in, bool prompt) +{ if (prompt == false) { //prompt output cerr.rdbuf(NULL); } size_t number_count; cerr << "Enter number count: \n"; - cerr.flush(); in >> number_count; Input in_data_struct; @@ -51,30 +63,51 @@ input_data(istream& in, bool prompt) { } } +Input +download(const string& address) { + stringstream buffer; + stringstream temp; -int -main(int argc, char* argv[]) { - if (argc > 1) { - CURL* curl = curl_easy_init(); - if (curl) { - CURLcode res; - curl_easy_setopt(curl, CURLOPT_URL, argv[1]); - res = curl_easy_perform(curl); + 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_HEADERFUNCTION, write_data); + curl_easy_setopt(curl, CURLOPT_HEADERDATA, &temp); - if (CURLE_OK == 0) { + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer); + + res = curl_easy_perform(curl); + if (CURLE_OK != 0) { cerr << curl_easy_strerror(res); exit(1); } + cerr << temp.str(); + curl_easy_cleanup(curl); + } + return input_data(buffer, false); +} - curl_easy_cleanup(curl); - } - return 0; +int +main(int argc, char* argv[]) { + Input input; + if (argc > 1) { + input = download(argv[1]); + } else { + input = input_data(cin, true); } - curl_global_init(CURL_GLOBAL_ALL); - auto in = input_data(cin, true); //input data - auto bins = make_histogram(in.numbers, in.bin_count); //calculating bin size for the histogram - show_histogram_svg(bins, in.interval_task); //histogram output in the format svg code + const auto bins = make_histogram(input.numbers, input.bin_count); + show_histogram_svg(bins, input.interval_task); + + //[OUTDATED] + //curl_global_init(CURL_GLOBAL_ALL); + // in = input_data(cin, true); //input data + //auto bins = make_histogram(in.numbers, in.bin_count); //calculating bin size for the histogram + //show_histogram_svg(bins, in.interval_task); //histogram output in the format svg code return 0; } + diff --git a/marks.txt b/marks.txt index d4b30eb..66d3303 100644 --- a/marks.txt +++ b/marks.txt @@ -1,6 +1,13 @@ -142 -1 1 1 1 1 1 1 1 1 -2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 -3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 +10 +3 +3 +3 +3 +3 +3 +4 +5 +5 +5 3 6