summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2023-02-16 16:34:36 +0100
committerDaniel Stenberg <daniel@haxx.se>2023-02-17 09:22:49 +0100
commit6841f2ed5fb53a74b8d6a31d4035fd52221c4275 (patch)
tree536cc42d9f8ca5e37a790b3409b6c6dc818af4f1 /src
parent6d860f1758c9128e726a006d3aaea4d4c09bf77d (diff)
downloadcurl-6841f2ed5fb53a74b8d6a31d4035fd52221c4275.tar.gz
curl: make --silent work stand-alone
- renamed the struct field to 'silent' to match the cmdline option - make --show-error toggle independently of --silent - make --silent independent of ->noprogress as well By doing this, the three options --silent, --no-progress-meter and --show-error should work independently of each other and also work with and without '--no-' prefix as documented. Reported-by: u20221022 on github Fixes #10535 Closes #10536
Diffstat (limited to 'src')
-rw-r--r--src/tool_cfgable.h8
-rw-r--r--src/tool_getparam.c18
-rw-r--r--src/tool_main.c2
-rw-r--r--src/tool_msgs.c4
-rw-r--r--src/tool_operate.c28
5 files changed, 26 insertions, 34 deletions
diff --git a/src/tool_cfgable.h b/src/tool_cfgable.h
index 21ad1c2da..6f821be24 100644
--- a/src/tool_cfgable.h
+++ b/src/tool_cfgable.h
@@ -298,11 +298,9 @@ struct OperationConfig {
};
struct GlobalConfig {
- int showerror; /* -1 == unset, default => show errors
- 0 => -s is used to NOT show errors
- 1 => -S has been used to show errors */
- bool mute; /* don't show messages, --silent given */
- bool noprogress; /* don't show progress bar --silent given */
+ bool showerror; /* show errors when silent */
+ bool silent; /* don't show messages, --silent given */
+ bool noprogress; /* don't show progress bar */
bool isatty; /* Updated internally if output is a tty */
FILE *errors; /* Error stream, defaults to stderr */
bool errors_fopened; /* Whether error stream isn't stderr */
diff --git a/src/tool_getparam.c b/src/tool_getparam.c
index dc2edb28b..e2cc99480 100644
--- a/src/tool_getparam.c
+++ b/src/tool_getparam.c
@@ -2268,21 +2268,11 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
/* use remote file's time */
config->remote_time = toggle;
break;
- case 's':
- /* don't show progress meter, don't show errors : */
- if(toggle)
- global->mute = global->noprogress = TRUE;
- else
- global->mute = global->noprogress = FALSE;
- if(global->showerror < 0)
- /* if still on the default value, set showerror to the reverse of
- toggle. This is to allow -S and -s to be used in an independent
- order but still have the same effect. */
- global->showerror = (!toggle)?TRUE:FALSE; /* toggle off */
+ case 's': /* --silent */
+ global->silent = toggle;
break;
- case 'S':
- /* show errors */
- global->showerror = toggle?1:0; /* toggle on if used with -s */
+ case 'S': /* --show-error */
+ global->showerror = toggle;
break;
case 't':
/* Telnet options */
diff --git a/src/tool_main.c b/src/tool_main.c
index 02d8d3bb7..de7276f14 100644
--- a/src/tool_main.c
+++ b/src/tool_main.c
@@ -155,7 +155,7 @@ static CURLcode main_init(struct GlobalConfig *config)
#endif
/* Initialise the global config */
- config->showerror = -1; /* Will show errors */
+ config->showerror = FALSE; /* show errors when silent */
config->errors = stderr; /* Default errors to stderr */
config->styled_output = TRUE; /* enable detection */
config->parallel_max = PARALLEL_DEFAULT;
diff --git a/src/tool_msgs.c b/src/tool_msgs.c
index 0a9458334..d9c46d6b3 100644
--- a/src/tool_msgs.c
+++ b/src/tool_msgs.c
@@ -42,7 +42,7 @@ static void voutf(struct GlobalConfig *config,
va_list ap)
{
size_t width = (79 - strlen(prefix));
- if(!config->mute) {
+ if(!config->silent) {
size_t len;
char *ptr;
char *print_buffer;
@@ -132,7 +132,7 @@ void helpf(FILE *errors, const char *fmt, ...)
*/
void errorf(struct GlobalConfig *config, const char *fmt, ...)
{
- if(!config->mute) {
+ if(!config->silent) {
va_list ap;
va_start(ap, fmt);
voutf(config, ERROR_PREFIX, fmt, ap);
diff --git a/src/tool_operate.c b/src/tool_operate.c
index 02a5113dd..8bd094885 100644
--- a/src/tool_operate.c
+++ b/src/tool_operate.c
@@ -396,12 +396,13 @@ static CURLcode post_per_transfer(struct GlobalConfig *global,
#ifdef __VMS
if(is_vms_shell()) {
/* VMS DCL shell behavior */
- if(!global->showerror)
+ if(global->silent && !global->showerror)
vms_show = VMSSTS_HIDE;
}
else
#endif
- if(!config->synthetic_error && result && global->showerror) {
+ if(!config->synthetic_error && result &&
+ (!global->silent || global->showerror)) {
const char *msg = per->errorbuffer;
fprintf(global->errors, "curl: (%d) %s\n", result,
(msg && msg[0]) ? msg : curl_easy_strerror(result));
@@ -413,7 +414,7 @@ static CURLcode post_per_transfer(struct GlobalConfig *global,
long code = 0;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
if(code >= 400) {
- if(global->showerror)
+ if(!global->silent || global->showerror)
fprintf(global->errors,
"curl: (%d) The requested URL returned error: %ld\n",
CURLE_HTTP_RETURNED_ERROR, code);
@@ -446,7 +447,7 @@ static CURLcode post_per_transfer(struct GlobalConfig *global,
if(!result && rc) {
/* something went wrong in the writing process */
result = CURLE_WRITE_ERROR;
- if(global->showerror)
+ if(!global->silent || global->showerror)
fprintf(global->errors, "curl: (%d) Failed writing body\n", result);
}
}
@@ -587,7 +588,7 @@ static CURLcode post_per_transfer(struct GlobalConfig *global,
int rc;
/* We have written data to an output file, we truncate file
*/
- if(!global->mute)
+ if(!global->silent)
fprintf(global->errors, "Throwing away %"
CURL_FORMAT_CURL_OFF_T " bytes\n",
outs->bytes);
@@ -597,7 +598,7 @@ static CURLcode post_per_transfer(struct GlobalConfig *global,
if(ftruncate(fileno(outs->stream), outs->init)) {
/* when truncate fails, we can't just append as then we'll
create something strange, bail out */
- if(global->showerror)
+ if(!global->silent || global->showerror)
fprintf(global->errors,
"curl: (23) Failed to truncate file\n");
return CURLE_WRITE_ERROR;
@@ -613,7 +614,7 @@ static CURLcode post_per_transfer(struct GlobalConfig *global,
rc = fseek(outs->stream, (long)outs->init, SEEK_SET);
#endif
if(rc) {
- if(global->showerror)
+ if(!global->silent || global->showerror)
fprintf(global->errors,
"curl: (23) Failed seeking to end of file\n");
return CURLE_WRITE_ERROR;
@@ -639,7 +640,7 @@ static CURLcode post_per_transfer(struct GlobalConfig *global,
if(!result && rc) {
/* something went wrong in the writing process */
result = CURLE_WRITE_ERROR;
- if(global->showerror)
+ if(!global->silent || global->showerror)
fprintf(global->errors, "curl: (%d) Failed writing body\n", result);
}
if(result && config->rm_partial) {
@@ -799,7 +800,8 @@ static CURLcode single_transfer(struct GlobalConfig *global,
if(!config->globoff && infiles && !inglob) {
/* Unless explicitly shut off */
result = glob_url(&inglob, infiles, &state->infilenum,
- global->showerror?global->errors:NULL);
+ (!global->silent || global->showerror)?
+ global->errors:NULL);
if(result)
break;
config->state.inglob = inglob;
@@ -834,7 +836,8 @@ static CURLcode single_transfer(struct GlobalConfig *global,
/* Unless explicitly shut off, we expand '{...}' and '[...]'
expressions and return total number of URLs in pattern set */
result = glob_url(&state->urls, urlnode->url, &state->urlnum,
- global->showerror?global->errors:NULL);
+ (!global->silent || global->showerror)?
+ global->errors:NULL);
if(result)
break;
urlnum = state->urlnum;
@@ -1316,7 +1319,8 @@ static CURLcode single_transfer(struct GlobalConfig *global,
}
my_setopt_str(curl, CURLOPT_URL, per->this_url);
- my_setopt(curl, CURLOPT_NOPROGRESS, global->noprogress?1L:0L);
+ my_setopt(curl, CURLOPT_NOPROGRESS,
+ global->noprogress || global->silent?1L:0L);
if(config->no_body)
my_setopt(curl, CURLOPT_NOBODY, 1L);
@@ -1853,7 +1857,7 @@ static CURLcode single_transfer(struct GlobalConfig *global,
progressbarinit(&per->progressbar, config);
if((global->progressmode == CURL_PROGRESS_BAR) &&
- !global->noprogress && !global->mute) {
+ !global->noprogress && !global->silent) {
/* we want the alternative style, then we have to implement it
ourselves! */
my_setopt(curl, CURLOPT_XFERINFOFUNCTION, tool_progress_cb);