code: Финальный вариант
Этот коммит содержится в:
35
lab34.cpp
35
lab34.cpp
@@ -41,20 +41,16 @@ write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Input
|
Input
|
||||||
download(const string& address, const string& argument) {
|
download(const string& address, bool verbose = false) {
|
||||||
stringstream buffer;
|
stringstream buffer;
|
||||||
CURL* curl = curl_easy_init();
|
CURL* curl = curl_easy_init();
|
||||||
if ((argument != "") && (address != "-verbose") && (argument != "-verbose")) {
|
|
||||||
cout << "Wrong argument, use correct input -verbose or leave input empty" << endl;
|
|
||||||
exit(2);
|
|
||||||
}
|
|
||||||
if (curl) {
|
if (curl) {
|
||||||
CURLcode res;
|
CURLcode res;
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, argument == "-verbose" || argument == "" ? address.c_str() : argument.c_str());
|
curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
|
||||||
if (address == "-verbose" || argument == "-verbose") {
|
if (verbose) {
|
||||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, argument == "-verbose" ? argument.c_str() : address.c_str());
|
curl_easy_setopt(curl, CURLOPT_VERBOSE, "-verbose");
|
||||||
}
|
}
|
||||||
res = curl_easy_perform(curl);
|
res = curl_easy_perform(curl);
|
||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
@@ -69,11 +65,26 @@ download(const string& address, const string& argument) {
|
|||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
Input input;
|
Input input;
|
||||||
if (argc > 2) {
|
string link;
|
||||||
input = download(argv[1], argv[2]);
|
bool flag = false;
|
||||||
|
if (argc == 2) {
|
||||||
|
input = download(argv[1]);
|
||||||
}
|
}
|
||||||
else if (argc == 2) {
|
else if (argc > 2) {
|
||||||
input = download(argv[1], "");
|
for (size_t i = 1; i < argc; i++) {
|
||||||
|
string cur = argv[i];
|
||||||
|
if (cur.find("://") != string::npos) {
|
||||||
|
link = cur;
|
||||||
|
}
|
||||||
|
else if (cur == "-verbose") {
|
||||||
|
flag = true;
|
||||||
|
}
|
||||||
|
else if (cur.find("-") != string::npos && cur != "-verbose") {
|
||||||
|
cout << "Wrong argument, use correct input -verbose or leave input empty" << endl;
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
input = download(link, flag);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
input = input_data(cin, true);
|
input = input_data(cin, true);
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user