|
|
|
@ -11,68 +11,80 @@ using namespace std;
|
|
|
|
|
struct Input {
|
|
|
|
|
vector<double> numbers;
|
|
|
|
|
size_t bin_count;
|
|
|
|
|
string stroke_color = "black";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Input input_data(istream& in, bool prompt) {
|
|
|
|
|
Input inp;
|
|
|
|
|
size_t number_count;
|
|
|
|
|
if (prompt){
|
|
|
|
|
cerr << "Enter number count: ";
|
|
|
|
|
}
|
|
|
|
|
if (prompt) cerr << "Enter number count: ";
|
|
|
|
|
in >> number_count;
|
|
|
|
|
inp.numbers.resize(number_count);
|
|
|
|
|
if (prompt){
|
|
|
|
|
cerr << "Enter numbers: ";
|
|
|
|
|
}
|
|
|
|
|
if (prompt) cerr << "Enter numbers: ";
|
|
|
|
|
for (size_t i = 0; i < number_count; i++) {
|
|
|
|
|
in >> inp.numbers[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (prompt) {
|
|
|
|
|
cerr << "Enter bin count: ";
|
|
|
|
|
}
|
|
|
|
|
if (prompt) cerr << "Enter bin count: ";
|
|
|
|
|
in >> inp.bin_count;
|
|
|
|
|
return inp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t
|
|
|
|
|
write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
|
|
|
|
|
size_t write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
|
|
|
|
|
stringstream* buffer = reinterpret_cast<stringstream*>(ctx);
|
|
|
|
|
size_t data_size = item_size * item_count;
|
|
|
|
|
(*buffer).write(reinterpret_cast<const char*>(items), data_size);
|
|
|
|
|
buffer->write(reinterpret_cast<const char*>(items), data_size);
|
|
|
|
|
return data_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Input
|
|
|
|
|
download(const string& adress){
|
|
|
|
|
Input download(const string& address) {
|
|
|
|
|
stringstream buffer;
|
|
|
|
|
CURL* curl = curl_easy_init();
|
|
|
|
|
if(curl) {
|
|
|
|
|
|
|
|
|
|
CURLcode res;
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, adress.c_str());
|
|
|
|
|
if (curl) {
|
|
|
|
|
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){
|
|
|
|
|
CURLcode res = curl_easy_perform(curl);
|
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
|
cerr << curl_easy_strerror(res);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return input_data(buffer, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void process_args(int argc, char* argv[], Input& input) {
|
|
|
|
|
for (int i = 1; i < argc; i++) {
|
|
|
|
|
if (string(argv[i]) == "-stroke") {
|
|
|
|
|
if (i + 1 < argc) {
|
|
|
|
|
input.stroke_color = argv[i + 1];
|
|
|
|
|
i++;
|
|
|
|
|
} else {
|
|
|
|
|
cerr << "Error: trebueca one argument.\n";
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
|
Input input;
|
|
|
|
|
if (argc > 1) {
|
|
|
|
|
input = download(argv[1]);
|
|
|
|
|
} else {
|
|
|
|
|
process_args(argc, argv, input);
|
|
|
|
|
|
|
|
|
|
bool url_provided = false;
|
|
|
|
|
for (int i = 1; i < argc; i++) {
|
|
|
|
|
if (string(argv[i]) != "-stroke" && argv[i][0] != '-') {
|
|
|
|
|
input = download(argv[i]);
|
|
|
|
|
url_provided = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!url_provided) {
|
|
|
|
|
input = input_data(cin, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto bins = make_histogram(input.numbers, input.bin_count);
|
|
|
|
|
show_histogram_svg(bins);
|
|
|
|
|
show_histogram_svg(bins, input.stroke_color);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|