|
|
|
@ -1,9 +1,12 @@
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include "histogram.h"
|
|
|
|
|
#include "text.h"
|
|
|
|
|
#include "svg.h"
|
|
|
|
|
#include <curl/curl.h>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
@ -13,84 +16,69 @@ struct Input
|
|
|
|
|
size_t bin_count{};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Input
|
|
|
|
|
input_data(istream& inn)
|
|
|
|
|
Input input_data(istream& inx, bool prompt)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
bool prompt;
|
|
|
|
|
int reshenie;
|
|
|
|
|
cerr << "Show prompts? (1 for yes, 2 for no):";
|
|
|
|
|
inn >> reshenie;
|
|
|
|
|
if(reshenie == 1)
|
|
|
|
|
{
|
|
|
|
|
prompt = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
prompt = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
size_t number_count;
|
|
|
|
|
if (prompt)
|
|
|
|
|
{
|
|
|
|
|
cerr << "Enter number count: ";
|
|
|
|
|
}
|
|
|
|
|
inn >> number_count;
|
|
|
|
|
if (prompt) cerr << "Enter number count: ";
|
|
|
|
|
inx >> number_count;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Input in;
|
|
|
|
|
in.numbers.resize(number_count);
|
|
|
|
|
|
|
|
|
|
vector<double> numbers(number_count);
|
|
|
|
|
if (prompt) cerr << "Input some numbers: ";
|
|
|
|
|
for (int i = 0; i < number_count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (prompt)
|
|
|
|
|
{
|
|
|
|
|
cerr << "Number[" << i << "]=";
|
|
|
|
|
}
|
|
|
|
|
inn >> in.numbers[i];
|
|
|
|
|
inx >> in.numbers[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (prompt)
|
|
|
|
|
{
|
|
|
|
|
cerr << "Enter bin count: ";
|
|
|
|
|
}
|
|
|
|
|
inn >> in.bin_count;
|
|
|
|
|
if (prompt) cerr << "Enter bin count: ";
|
|
|
|
|
inx >> in.bin_count;
|
|
|
|
|
return in;
|
|
|
|
|
}
|
|
|
|
|
size_t write_data(void* ptr, size_t size, size_t nmemb, void* stream)
|
|
|
|
|
{
|
|
|
|
|
size_t written = fwrite(ptr, size, nmemb, stdout);
|
|
|
|
|
return written;
|
|
|
|
|
|
|
|
|
|
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<stringstream*>(ctx);
|
|
|
|
|
buffer->write(reinterpret_cast<const char*>(items), data_size);
|
|
|
|
|
return data_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
|
{
|
|
|
|
|
if (argc > 1)
|
|
|
|
|
{
|
|
|
|
|
CURL* curl = curl_easy_init();
|
|
|
|
|
if (curl)
|
|
|
|
|
{
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
|
|
|
|
Input
|
|
|
|
|
download(const string& address) {
|
|
|
|
|
stringstream buffer;
|
|
|
|
|
CURL* curl = curl_easy_init();
|
|
|
|
|
if (curl) {
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
|
|
|
|
|
|
|
|
|
|
CURLcode res = curl_easy_perform(curl);
|
|
|
|
|
if (res != CURLE_OK)
|
|
|
|
|
{
|
|
|
|
|
cerr << "cURL error: " << curl_easy_strerror(res) << endl;
|
|
|
|
|
}
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
|
|
|
|
|
|
|
|
|
|
CURLcode res = curl_easy_perform(curl);
|
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
|
cerr << "cURL error: " << curl_easy_strerror(res) << endl;
|
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cerr << "curl_easy_init() failed" << endl;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
|
} else {
|
|
|
|
|
cerr << "curl_easy_init() failed" << endl;
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
curl_global_init(CURL_GLOBAL_ALL);
|
|
|
|
|
auto in = input_data(cin);
|
|
|
|
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
|
|
|
|
|
|
|
|
|
return input_data(buffer, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main(int argc, char* argv[]) {
|
|
|
|
|
Input input;
|
|
|
|
|
if (argc > 1) {
|
|
|
|
|
input = download(argv[1]);
|
|
|
|
|
} else {
|
|
|
|
|
input = input_data(cin, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const auto bins = make_histogram(input.numbers, input.bin_count);
|
|
|
|
|
show_histogram_svg(bins);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|