Этот коммит содержится в:
2023-09-13 21:49:00 +03:00
родитель 8778770f4e
Коммит 21a6cf40ce

Просмотреть файл

@@ -1,9 +1,10 @@
#include <math.h> #include <math.h>
#include <vector> #include <vector>
#include <iostream> #include <iostream>
#include <sstream>
#include <string.h> #include <string.h>
#include <curl/curl.h> #include <curl/curl.h>
#include <string>
#include "histogram.h" #include "histogram.h"
#include "text.h" #include "text.h"
#include "svg.h" #include "svg.h"
@@ -48,29 +49,42 @@ input_data(istream& in,bool prompt) {
return on; return on;
} }
size_t
write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
int main(int argc, char* argv[]) size_t data_size = item_size * item_count;
{ stringstream* buffer = reinterpret_cast<stringstream*>(ctx);
if (argc > 1) { buffer->write(reinterpret_cast<const char*>(items), data_size);
CURL *curl = curl_easy_init(); return data_size;
if(curl) { }
CURLcode res; Input
curl_easy_setopt(curl, CURLOPT_URL, argv[0]); download(const string& address) {
res = curl_easy_perform(curl); stringstream buffer;
if(res != CURLE_OK){ CURL* curl = curl_easy_init();
fprintf(stderr, "curl_easy_perform() failed: %s\n", if(curl) {
curl_easy_strerror(res)); CURLcode res;
exit(1);} res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
} curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
return 0;} curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
curl_global_init(CURL_GLOBAL_ALL);
if(res != CURLE_OK){
auto in = input_data(cin,true); cerr << curl_easy_strerror(res);
auto bins = make_histogram(in.numbers, in.bin_count); exit(1);}
show_histogram_svg(bins); curl_easy_cleanup(curl);}
return 0; 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;
} }