1 /*************************************************************************** 2 * _ _ ____ _ 3 * Project ___| | | | _ \| | 4 * / __| | | | |_) | | 5 * | (__| |_| | _ <| |___ 6 * \___|\___/|_| \_\_____| 7 * 8 * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel (at) haxx.se>, et al. 9 * 10 * This software is licensed as described in the file COPYING, which 11 * you should have received as part of this distribution. The terms 12 * are also available at http://curl.haxx.se/docs/copyright.html. 13 * 14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell 15 * copies of the Software, and permit persons to whom the Software is 16 * furnished to do so, under the terms of the COPYING file. 17 * 18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 19 * KIND, either express or implied. 20 * 21 ***************************************************************************/ 22 #include "tool_setup.h" 23 24 #define ENABLE_CURLX_PRINTF 25 /* use our own printf() functions */ 26 #include "curlx.h" 27 28 #include "tool_cfgable.h" 29 #include "tool_msgs.h" 30 31 #include "memdebug.h" /* keep this as LAST include */ 32 33 #define WARN_PREFIX "Warning: " 34 #define WARN_TEXTWIDTH (79 - (int)strlen(WARN_PREFIX)) 35 36 /* 37 * Emit warning formatted message on configured 'errors' stream unless 38 * mute (--silent) was selected. 39 */ 40 41 void warnf(struct GlobalConfig *config, const char *fmt, ...) 42 { 43 if(!config->mute) { 44 va_list ap; 45 int len; 46 char *ptr; 47 char print_buffer[256]; 48 49 va_start(ap, fmt); 50 len = vsnprintf(print_buffer, sizeof(print_buffer), fmt, ap); 51 va_end(ap); 52 53 ptr = print_buffer; 54 while(len > 0) { 55 fputs(WARN_PREFIX, config->errors); 56 57 if(len > (int)WARN_TEXTWIDTH) { 58 int cut = WARN_TEXTWIDTH-1; 59 60 while(!ISSPACE(ptr[cut]) && cut) { 61 cut--; 62 } 63 if(0 == cut) 64 /* not a single cutting position was found, just cut it at the 65 max text width then! */ 66 cut = WARN_TEXTWIDTH-1; 67 68 (void)fwrite(ptr, cut + 1, 1, config->errors); 69 fputs("\n", config->errors); 70 ptr += cut+1; /* skip the space too */ 71 len -= cut; 72 } 73 else { 74 fputs(ptr, config->errors); 75 len = 0; 76 } 77 } 78 } 79 } 80 81 /* 82 * Emit help formatted message on given stream. 83 */ 84 85 void helpf(FILE *errors, const char *fmt, ...) 86 { 87 va_list ap; 88 if(fmt) { 89 va_start(ap, fmt); 90 fputs("curl: ", errors); /* prefix it */ 91 vfprintf(errors, fmt, ap); 92 va_end(ap); 93 } 94 fprintf(errors, "curl: try 'curl --help' " 95 #ifdef USE_MANUAL 96 "or 'curl --manual' " 97 #endif 98 "for more information\n"); 99 } 100 101