2011-09-20 09:58:35 -04:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2017-09-09 17:55:08 -04:00
|
|
|
* Copyright (C) 1998 - 2015, 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2011-09-20 09:58:35 -04:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2016-02-02 18:19:02 -05:00
|
|
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
2011-09-20 09:58:35 -04:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
2012-04-06 17:35:15 -04:00
|
|
|
#include "tool_setup.h"
|
2011-09-20 09:58:35 -04:00
|
|
|
|
|
|
|
#define ENABLE_CURLX_PRINTF
|
|
|
|
/* use our own printf() functions */
|
|
|
|
#include "curlx.h"
|
|
|
|
|
|
|
|
#include "tool_cfgable.h"
|
|
|
|
#include "tool_msgs.h"
|
|
|
|
|
2013-01-03 20:50:28 -05:00
|
|
|
#include "memdebug.h" /* keep this as LAST include */
|
2011-09-20 09:58:35 -04:00
|
|
|
|
|
|
|
#define WARN_PREFIX "Warning: "
|
2015-08-29 17:56:28 -04:00
|
|
|
#define NOTE_PREFIX "Note: "
|
2011-09-20 09:58:35 -04:00
|
|
|
|
2015-08-29 17:56:28 -04:00
|
|
|
static void voutf(struct GlobalConfig *config,
|
|
|
|
const char *prefix,
|
|
|
|
const char *fmt,
|
|
|
|
va_list ap)
|
2011-09-20 09:58:35 -04:00
|
|
|
{
|
2017-05-08 14:23:44 -04:00
|
|
|
size_t width = (79 - strlen(prefix));
|
2015-02-27 15:48:38 -05:00
|
|
|
if(!config->mute) {
|
2015-08-29 17:56:28 -04:00
|
|
|
size_t len;
|
2011-09-20 09:58:35 -04:00
|
|
|
char *ptr;
|
2017-12-12 13:58:47 -05:00
|
|
|
char *print_buffer;
|
2011-09-20 09:58:35 -04:00
|
|
|
|
2017-12-12 13:58:47 -05:00
|
|
|
print_buffer = curlx_mvaprintf(fmt, ap);
|
|
|
|
if(!print_buffer)
|
|
|
|
return;
|
|
|
|
len = strlen(print_buffer);
|
2011-09-20 09:58:35 -04:00
|
|
|
|
|
|
|
ptr = print_buffer;
|
|
|
|
while(len > 0) {
|
2015-08-29 17:56:28 -04:00
|
|
|
fputs(prefix, config->errors);
|
2011-09-20 09:58:35 -04:00
|
|
|
|
2015-08-29 17:56:28 -04:00
|
|
|
if(len > width) {
|
|
|
|
size_t cut = width-1;
|
2011-09-20 09:58:35 -04:00
|
|
|
|
|
|
|
while(!ISSPACE(ptr[cut]) && cut) {
|
|
|
|
cut--;
|
|
|
|
}
|
|
|
|
if(0 == cut)
|
|
|
|
/* not a single cutting position was found, just cut it at the
|
|
|
|
max text width then! */
|
2015-08-29 17:56:28 -04:00
|
|
|
cut = width-1;
|
2011-09-20 09:58:35 -04:00
|
|
|
|
2015-02-27 15:48:38 -05:00
|
|
|
(void)fwrite(ptr, cut + 1, 1, config->errors);
|
|
|
|
fputs("\n", config->errors);
|
2017-09-09 17:55:08 -04:00
|
|
|
ptr += cut + 1; /* skip the space too */
|
2011-09-20 09:58:35 -04:00
|
|
|
len -= cut;
|
|
|
|
}
|
|
|
|
else {
|
2015-02-27 15:48:38 -05:00
|
|
|
fputs(ptr, config->errors);
|
2011-09-20 09:58:35 -04:00
|
|
|
len = 0;
|
|
|
|
}
|
|
|
|
}
|
2017-12-12 13:58:47 -05:00
|
|
|
curl_free(print_buffer);
|
2011-09-20 09:58:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-29 17:56:28 -04:00
|
|
|
/*
|
|
|
|
* Emit 'note' formatted message on configured 'errors' stream, if verbose was
|
|
|
|
* selected.
|
|
|
|
*/
|
|
|
|
void notef(struct GlobalConfig *config, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
if(config->tracetype)
|
|
|
|
voutf(config, NOTE_PREFIX, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Emit warning formatted message on configured 'errors' stream unless
|
|
|
|
* mute (--silent) was selected.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void warnf(struct GlobalConfig *config, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
voutf(config, WARN_PREFIX, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
2011-09-20 09:58:35 -04:00
|
|
|
/*
|
|
|
|
* Emit help formatted message on given stream.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void helpf(FILE *errors, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
if(fmt) {
|
|
|
|
va_start(ap, fmt);
|
|
|
|
fputs("curl: ", errors); /* prefix it */
|
|
|
|
vfprintf(errors, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
fprintf(errors, "curl: try 'curl --help' "
|
|
|
|
#ifdef USE_MANUAL
|
|
|
|
"or 'curl --manual' "
|
|
|
|
#endif
|
|
|
|
"for more information\n");
|
|
|
|
}
|
|
|
|
|