|
|
|
@ -1,10 +1,11 @@
|
|
|
|
|
#include <curl/curl.h>
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include "histogram.h"
|
|
|
|
|
#include "text.h"
|
|
|
|
|
#include "svg.h"
|
|
|
|
|
#include "text.h"
|
|
|
|
|
#include <curl/curl.h>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
@ -40,47 +41,42 @@ Input input_data(istream& in, bool prompt = true) { //
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Callback äëÿ çàïèñè äàííûõ â stringstream
|
|
|
|
|
|
|
|
|
|
// Callback-ôóíęöč˙ äë˙ çŕďčńč ďîëó÷ĺííűő äŕííűő
|
|
|
|
|
static size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userp) {
|
|
|
|
|
((string*)userp)->append((char*)contents, size * nmemb);
|
|
|
|
|
return size * nmemb;
|
|
|
|
|
static size_t Write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
|
|
|
|
|
size_t data_size = item_size * item_count;
|
|
|
|
|
auto* buffer = reinterpret_cast<stringstream*>(ctx);
|
|
|
|
|
buffer->write(reinterpret_cast<const char*>(items), data_size);
|
|
|
|
|
return data_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Input download(const string& address) {
|
|
|
|
|
stringstream buffer;
|
|
|
|
|
CURL* curl = curl_easy_init();
|
|
|
|
|
|
|
|
|
|
if (!curl) {
|
|
|
|
|
cerr << "Îøèáêà: íå óäàëîñü èíèöèàëèçèðîâàòü cURL" << endl;
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
|
curl_global_init(CURL_GLOBAL_ALL);
|
|
|
|
|
|
|
|
|
|
Input input;
|
|
|
|
|
if (argc > 1) {
|
|
|
|
|
CURL* curl = curl_easy_init();
|
|
|
|
|
if (!curl) {
|
|
|
|
|
cerr << "Îřčáęŕ: íĺ óäŕëîńü číčöčŕëčçčđîâŕňü cURL" << endl;
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string readBuffer;
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
|
|
|
|
|
|
|
|
|
|
// Âđĺěĺííîĺ îňęëţ÷ĺíčĺ ďđîâĺđęč SSL äë˙ ňĺńňîâ
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
|
|
|
|
|
|
|
|
|
CURLcode res = curl_easy_perform(curl);
|
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
|
cerr << "Îřčáęŕ cURL: " << curl_easy_strerror(res) << endl;
|
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
|
exit(1); // Çŕâĺđřŕĺě ďđîăđŕěěó ń ęîäîě îřčáęč
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cout << readBuffer;
|
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
|
return 0;
|
|
|
|
|
input = download(argv[1]);
|
|
|
|
|
} else {
|
|
|
|
|
auto input = input_data(cin, true);
|
|
|
|
|
}
|
|
|
|
|
curl_global_init(CURL_GLOBAL_ALL);
|
|
|
|
|
size_t max_count;
|
|
|
|
|
auto in = input_data(cin);
|
|
|
|
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
|
|
|
|
auto bins = make_histogram(input.numbers, input.bin_count);
|
|
|
|
|
show_histogram_svg(bins);
|
|
|
|
|
curl_global_cleanup();
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -89,3 +85,6 @@ int main(int argc, char* argv[]) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|