BushmanovAS 11 месяцев назад
Родитель 13c7d45255
Сommit 0a61a8520f

@ -1,10 +1,9 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <curl/curl.h>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <curl/curl.h>
#include "histogram.h" #include "histogram.h"
#include "text.h"
#include "svg.h" #include "svg.h"
using namespace std; using namespace std;
@ -15,32 +14,36 @@ struct Input
size_t bin_count{}; size_t bin_count{};
}; };
Input input_data(istream& in, bool prompt = true) Input
input_data(istream& stream, bool prompt)
{ {
size_t number_count; size_t number_count;
if (prompt) if (prompt) {
cerr << "Enter number count: "; cerr << "Enter number count: ";
in >> number_count; }
Input input; stream >> number_count;
input.numbers.resize(number_count); Input in;
in.numbers.resize(number_count);
for (size_t i = 0; i < number_count; i++) for (size_t i = 0; i < number_count; i++)
{ {
in >> input.numbers[i]; stream >> in.numbers[i];
} }
if (prompt) if (prompt) {
cerr << "Enter bin count: "; cerr << "Enter bin count: ";
in >> input.bin_count;
return input;
} }
size_t stream >> in.bin_count;
write_data(void* items, size_t item_size, size_t item_count, void* ctx) { 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; size_t data_size = item_size * item_count;
stringstream* buffer = reinterpret_cast<stringstream*>(ctx); stringstream* buffer = reinterpret_cast<stringstream*>(ctx);
(*buffer).write(reinterpret_cast<const char*>(items), data_size); buffer->write(reinterpret_cast<const char*>(items), data_size);
return data_size; return data_size;
} }
Input
download(const string& address) { Input download(const string& address) {
stringstream buffer; stringstream buffer;
CURL* curl = curl_easy_init(); CURL* curl = curl_easy_init();
if (curl) { if (curl) {
@ -50,7 +53,7 @@ download(const string& address) {
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
if (res != CURLE_OK) { if (res != CURLE_OK) {
cerr << curl_easy_strerror(res); fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
exit(1); exit(1);
} }
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
@ -58,17 +61,20 @@ download(const string& address) {
return input_data(buffer, false); return input_data(buffer, false);
} }
int main(int argc, char* argv[]) int main(int argc, char* argv[]) {
{
bool show_prompts;
cout << "Show prompts? (1 for yes, 0 for no): ";
cin >> show_prompts;
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); if (curl_version_info(CURLVERSION_NOW) != nullptr) {
auto curl_ver = curl_version_info(CURLVERSION_NOW)->version;
cerr << "cURL version " << curl_ver << "\n";
auto ssl_ver = curl_version_info(CURLVERSION_NOW)->ssl_version;
cerr << "SSL version " << ssl_ver << "\n";
} else{ cerr<<"curl_version_info() failed \n"; }
vector<size_t> bins = make_histogram(input.numbers, input.bin_count);
show_histogram_svg(bins); show_histogram_svg(bins);
} }

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