|
|
|
@ -3,6 +3,7 @@
|
|
|
|
|
#include "svg.h"
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <curl/curl.h>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
@ -12,17 +13,20 @@ struct Input
|
|
|
|
|
size_t bin_count{};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Input input_data(istream& sin, bool prompt)
|
|
|
|
|
Input input_data(istream& sin, bool prompt = true)
|
|
|
|
|
{
|
|
|
|
|
if (prompt){
|
|
|
|
|
Input in;
|
|
|
|
|
size_t number_count;
|
|
|
|
|
cerr << "Input number count" << endl;
|
|
|
|
|
sin >> number_count;
|
|
|
|
|
in.numbers.resize(number_count);
|
|
|
|
|
for (size_t i = 0; i < number_count; i++)
|
|
|
|
|
{
|
|
|
|
|
cerr << "Input number "<< i << endl;
|
|
|
|
|
sin >> in.numbers[i];
|
|
|
|
|
}
|
|
|
|
|
cerr << "Input bin count" << endl;
|
|
|
|
|
sin >> in.bin_count;
|
|
|
|
|
return in;
|
|
|
|
|
}
|
|
|
|
@ -40,19 +44,69 @@ Input input_data(istream& sin, bool prompt)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
|
if (argc > 1) {
|
|
|
|
|
CURL* curl = curl_easy_init();
|
|
|
|
|
auto res = curl_easy_perform(curl);
|
|
|
|
|
if (res != 0) {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Input
|
|
|
|
|
download(const string& address) {
|
|
|
|
|
stringstream buffer;
|
|
|
|
|
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_WRITEDATA, &buffer);
|
|
|
|
|
res = curl_easy_perform(curl);
|
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
|
cout << curl_easy_strerror(res);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
Input in = input_data(cin, false);
|
|
|
|
|
return input_data(buffer, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
|
Input in;
|
|
|
|
|
string link, color = "";
|
|
|
|
|
bool flag = false;
|
|
|
|
|
if (argc == 2) {
|
|
|
|
|
in = download(argv[1]);
|
|
|
|
|
}
|
|
|
|
|
else if (argc == 3) {
|
|
|
|
|
cout << "Wrong argument, use correct input -stroke <color> or leave input empty" << endl;
|
|
|
|
|
exit(2);
|
|
|
|
|
}
|
|
|
|
|
else if (argc > 3) {
|
|
|
|
|
for (size_t i = 1; i < argc; i++) {
|
|
|
|
|
string cur = argv[i];
|
|
|
|
|
if (cur.find("://") != string::npos) {
|
|
|
|
|
link = cur;
|
|
|
|
|
}
|
|
|
|
|
else if (i != argc - 1){
|
|
|
|
|
string curm = argv[i+1];
|
|
|
|
|
if (cur == "-stroke" && curm.find("://") == string::npos) {
|
|
|
|
|
flag = true;
|
|
|
|
|
color = curm;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (cur == "-stroke" && i == (argc - 1)) {
|
|
|
|
|
cout << "Wrong argument, use correct input -stroke <color> or leave input empty" << endl;
|
|
|
|
|
exit(2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
in = download(link);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
in = input_data(cin, false);
|
|
|
|
|
}
|
|
|
|
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
|
|
|
|
show_histogram_svg(bins);
|
|
|
|
|
show_histogram_svg(bins, color);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|