Задача на автомат правки

parent 4ac67fac
downloader
*.tar.gz
*.html
...@@ -48,8 +48,7 @@ main(int argc, char** argv) ...@@ -48,8 +48,7 @@ main(int argc, char** argv)
} }
} }
printf("url:%s\nfilepath:%s\nurl file=%s\nfilepath file=%s\n", url, filepath, url_file_path, filepaths_file_path); printf("URL: %s\nFilepath: %s\nURL File: %s\nFilepaths File: %s\n", url, filepath, url_file_path, filepaths_file_path);
CURL *curl = curl_easy_init(); CURL *curl = curl_easy_init();
if(!curl) if(!curl)
...@@ -105,7 +104,7 @@ main(int argc, char** argv) ...@@ -105,7 +104,7 @@ main(int argc, char** argv)
void void
die(const char * error) die(const char * error)
{ {
fprintf(stderr,"%s\n",error); fprintf(stderr, "Error: %s\n", error);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
...@@ -116,7 +115,7 @@ download_file(char *url, char *filepath, CURL *curl) ...@@ -116,7 +115,7 @@ download_file(char *url, char *filepath, CURL *curl)
file = fopen(filepath,"wb"); file = fopen(filepath,"wb");
if(!file){ if(!file){
fprintf(stderr, "Could not open file!"); fprintf(stderr, "Error: Could not open file for writing: %s\n", filepath);
exit(1); exit(1);
} }
...@@ -148,14 +147,26 @@ get_default_filepath(char *url) ...@@ -148,14 +147,26 @@ get_default_filepath(char *url)
filepath = tmp; filepath = tmp;
tmp = strtok(NULL, "/"); tmp = strtok(NULL, "/");
} }
//TODO: move malloc and free from here // TODO: Move memory allocation and deallocation logic to the caller function for better resource management.
return filepath; return filepath;
} }
void void
usage() usage()
{ {
puts("Usage:\n\t-u url to get file from, other arguments can be omited.\n\t-f filepath to save file to. Can be omited, filename from url will be used.\n\t-uf file with urls to fetch files from. \n\t-ff filepath file, file with paths to save files from urls file. Can be omited, filename from url will be used.\n\tTo perform at least one of -u arguments should be given.\nSupported combinations:\n\t<url>\n\t-u <url>\n\t-u <url> -f <path to save fileto>\n\t-uf <path to file with urls>\n\t-uf <path to file with url> -ff<path to file with filenames>\n!Program rewrites files!"); puts("Usage:\n"
"\t-u <url> to get file from. Other arguments can be omitted.\n"
"\t-f <filepath> to save file to. Can be omitted; filename from URL will be used.\n"
"\t-uf <filepath> file with URLs to fetch files from.\n"
"\t-ff <filepath> file with paths to save files from URLs file. Can be omitted; filename from URL will be used.\n"
"At least one of the -u arguments should be given.\n"
"Supported combinations:\n"
"\t<url>\n"
"\t-u <url>\n"
"\t-u <url> -f <path to save file to>\n"
"\t-uf <path to file with URLs>\n"
"\t-uf <path to file with URL> -ff <path to file with filenames>\n"
"! Note: This program rewrites files!");
exit(0); exit(0);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment