Nikita (PodolskyNK) 11 месяцев назад
Родитель 7f11fd3445
Сommit 9bd2b446f7

@ -3,6 +3,8 @@
#include "histogram.h" #include "histogram.h"
#include "text.h" #include "text.h"
#include "svg.h" #include "svg.h"
#include <sstream>
#include <string>
#include <curl/curl.h> #include <curl/curl.h>
using namespace std; using namespace std;
@ -32,23 +34,30 @@ Input input_data(istream& stream, bool prompt) {
stream >> in.bin_count; stream >> in.bin_count;
return in; return in;
} }
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());
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);
}
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
Input input;
if (argc > 1) { if (argc > 1) {
CURL *curl = curl_easy_init(); input = download(argv[1]);
if(curl) { } else {
CURLcode res; input = input_data(cin, true);
curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
res = curl_easy_perform(curl);
if (res!=CURLE_OK){
cerr << curl_easy_strerror(res);
exit(1);
}
curl_easy_cleanup(curl);
}
return 0;
} }
Input in = input_data(cin, false); const auto bins = make_histogram(input.numbers, input.bin_count);
vector<size_t> bins = make_histogram(in.numbers, in.bin_count);
show_histogram_svg(bins); show_histogram_svg(bins);
} }

Загрузка…
Отмена
Сохранить