2011-09-20 09:58:35 -04:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2014-02-23 07:59:59 -05:00
|
|
|
* Copyright (C) 1998 - 2014, 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
|
|
|
|
* are also available at http://curl.haxx.se/docs/copyright.html.
|
|
|
|
*
|
|
|
|
* 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: "
|
|
|
|
#define WARN_TEXTWIDTH (79 - (int)strlen(WARN_PREFIX))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Emit warning formatted message on configured 'errors' stream unless
|
|
|
|
* mute (--silent) was selected.
|
|
|
|
*/
|
|
|
|
|
2014-02-23 07:59:59 -05:00
|
|
|
void warnf(struct OperationConfig *config, const char *fmt, ...)
|
2011-09-20 09:58:35 -04:00
|
|
|
{
|
2014-02-27 15:21:23 -05:00
|
|
|
if(!config->global->mute) {
|
2011-09-20 09:58:35 -04:00
|
|
|
va_list ap;
|
|
|
|
int len;
|
|
|
|
char *ptr;
|
|
|
|
char print_buffer[256];
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
len = vsnprintf(print_buffer, sizeof(print_buffer), fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
ptr = print_buffer;
|
|
|
|
while(len > 0) {
|
2014-03-01 08:00:31 -05:00
|
|
|
fputs(WARN_PREFIX, config->global->errors);
|
2011-09-20 09:58:35 -04:00
|
|
|
|
|
|
|
if(len > (int)WARN_TEXTWIDTH) {
|
|
|
|
int cut = WARN_TEXTWIDTH-1;
|
|
|
|
|
|
|
|
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! */
|
|
|
|
cut = WARN_TEXTWIDTH-1;
|
|
|
|
|
2014-03-01 08:00:31 -05:00
|
|
|
(void)fwrite(ptr, cut + 1, 1, config->global->errors);
|
|
|
|
fputs("\n", config->global->errors);
|
2011-09-20 09:58:35 -04:00
|
|
|
ptr += cut+1; /* skip the space too */
|
|
|
|
len -= cut;
|
|
|
|
}
|
|
|
|
else {
|
2014-03-01 08:00:31 -05:00
|
|
|
fputs(ptr, config->global->errors);
|
2011-09-20 09:58:35 -04:00
|
|
|
len = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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");
|
|
|
|
}
|
|
|
|
|