code: final main
Этот коммит содержится в:
44
main.cpp
44
main.cpp
@@ -45,17 +45,6 @@ write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
|
||||
return data_size;
|
||||
}
|
||||
|
||||
string
|
||||
filling(const string& key, const string& color){
|
||||
if(strcmp(key.c_str(), "-fill") == 0){
|
||||
if (strcmp(color.c_str(), " ") == 0){
|
||||
cerr << "Error: no color specified";
|
||||
exit(1);
|
||||
}
|
||||
return color.c_str();
|
||||
}
|
||||
}
|
||||
|
||||
Input
|
||||
download(const string& adress){
|
||||
stringstream buffer;
|
||||
@@ -68,6 +57,7 @@ download(const string& adress){
|
||||
res = curl_easy_perform(curl);
|
||||
if (res != CURLE_OK){
|
||||
cerr << curl_easy_strerror(res);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
@@ -80,20 +70,28 @@ int main(int argc, char* argv[]){
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
Input in;
|
||||
if (argc > 1) {
|
||||
in = download(argv[1]);
|
||||
} else {
|
||||
for (size_t i = 0; i < argc; i += 1){
|
||||
if (strcmp(argv[i], "-fill") == 0){
|
||||
if (i - 1 < 1){
|
||||
in = download(argv[i + 2]);
|
||||
color = argv[i + 1];
|
||||
}
|
||||
else{
|
||||
if (i + 1 >= argc){
|
||||
cerr << "Error: please enter color";
|
||||
exit(1);
|
||||
}
|
||||
else{
|
||||
in = download(argv[i - 1]);
|
||||
color = argv[i + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
in = input_data(cin, true);
|
||||
}
|
||||
|
||||
if (argc > 2){
|
||||
if (argv[3] == NULL){
|
||||
color = filling(argv[2], " ");
|
||||
}
|
||||
else{
|
||||
color = filling(argv[2], argv[3]);
|
||||
}
|
||||
}
|
||||
|
||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||
auto borders = make_borders(in.numbers, in.bin_count);
|
||||
show_histogram_svg(bins, borders, in.bin_count, color);
|
||||
|
||||
Ссылка в новой задаче
Block a user