From 33402f6f799b53ff6ae910f6e94977daa75cf27d Mon Sep 17 00:00:00 2001 From: Nick White Date: Tue, 13 May 2008 21:09:31 +0100 Subject: Added quiet option --- src/cli.c | 1 + src/download.c | 26 +++++++++++++++++++------- src/getht.c | 8 +++++++- src/getht.h | 1 + 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/cli.c b/src/cli.c index 1c6227e..d15634d 100644 --- a/src/cli.c +++ b/src/cli.c @@ -65,6 +65,7 @@ void showusage() printf("-d | --download-issue issno Download issue number issno\n"); printf("-f | --force Force re-download of existing files\n"); printf("-h | --help Print this help message\n"); + printf("-q | --quiet Make output less verbose\n"); printf("-v | --verbose Make output more verbose\n"); printf("-V | --version Print version information\n"); } diff --git a/src/download.c b/src/download.c index b287655..7f2610a 100644 --- a/src/download.c +++ b/src/download.c @@ -38,8 +38,11 @@ int update_progress(void *data, double dltotal, double dlnow, int save_file(char *uri, char *filepath, char *filetitle, long resume_offset, struct config * options) /* Save the file *uri to *filepath */ { - printf("Downloading %s ",filetitle); - fflush(stdout); + if(!options->quiet) + { + printf("Downloading %s ",filetitle); + fflush(stdout); + } if(options->curl_handle) { FILE *file; @@ -71,9 +74,14 @@ int save_file(char *uri, char *filepath, char *filetitle, long resume_offset, st } } - curl_easy_setopt(options->curl_handle, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(options->curl_handle, CURLOPT_PROGRESSFUNCTION, update_progress); - curl_easy_setopt(options->curl_handle, CURLOPT_PROGRESSDATA, &resume_offset); + if(!options->quiet) + { + curl_easy_setopt(options->curl_handle, CURLOPT_NOPROGRESS, 0); + curl_easy_setopt(options->curl_handle, CURLOPT_PROGRESSFUNCTION, update_progress); + curl_easy_setopt(options->curl_handle, CURLOPT_PROGRESSDATA, &resume_offset); + } + else + curl_easy_setopt(options->curl_handle, CURLOPT_NOPROGRESS, 1); curl_easy_setopt(options->curl_handle, CURLOPT_RESUME_FROM, resume_offset); @@ -90,7 +98,8 @@ int save_file(char *uri, char *filepath, char *filetitle, long resume_offset, st fclose(file); - printf("\rDownloaded %s \n",filetitle); + if(!options->quiet) + printf("\rDownloaded %s \n",filetitle); } else { fprintf(stderr,"Error: curl failed to initialise.\n"); @@ -212,7 +221,10 @@ void downloadissue(struct config * options, iss * issue, int force) if(remotesize > 0 && localsize < remotesize) save_file(cur_section->uri, filepath, filename, localsize, options); else - printf("Skipping download of completed section %i\n", cur_section->number); + { + if(!options->quiet) + printf("Skipping download of completed section %i\n", cur_section->number); + } } } else diff --git a/src/getht.c b/src/getht.c index ec90f0b..8f52d6f 100644 --- a/src/getht.c +++ b/src/getht.c @@ -39,6 +39,7 @@ int main(int argc, char *argv[]) /* initialise appropriate options vars */ options.startup_check = 0; + options.quiet = 0; options.verbose = 0; options.proxy.type = 0; options.proxy.auth = 0; @@ -91,13 +92,14 @@ int main(int argc, char *argv[]) {"download-issue", required_argument, 0, 'd'}, {"force", no_argument, 0, 'f'}, {"list-issues", no_argument, 0, 'l'}, + {"quiet", no_argument, 0, 'q'}, {"update", no_argument, 0, 'u'}, {"help", no_argument, 0, 'h'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {0, 0, 0, 0} }; - while((c = getopt_long(argc, argv, "ad:fhlmn:osuvVx:t:", long_opts, NULL)) != -1) { + while((c = getopt_long(argc, argv, "ad:fhluqvV", long_opts, NULL)) != -1) { switch(c) { case 'a': downall = 1; @@ -125,6 +127,10 @@ int main(int argc, char *argv[]) showusage(); return 0; break; + case 'q': + options.quiet = 1; + option = 1; + break; case 'v': options.verbose++; option = 1; diff --git a/src/getht.h b/src/getht.h index 4ec0f4a..6a64b6e 100644 --- a/src/getht.h +++ b/src/getht.h @@ -46,6 +46,7 @@ struct config { int startup_check; int verbose; + int quiet; CURL *curl_handle; }; -- cgit v1.2.3