tool_msgs.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 #include "tool_setup.h"
00023 
00024 #define ENABLE_CURLX_PRINTF
00025 /* use our own printf() functions */
00026 #include "curlx.h"
00027 
00028 #include "tool_cfgable.h"
00029 #include "tool_msgs.h"
00030 
00031 #include "memdebug.h" /* keep this as LAST include */
00032 
00033 #define WARN_PREFIX "Warning: "
00034 #define NOTE_PREFIX "Note: "
00035 
00036 static void voutf(struct GlobalConfig *config,
00037                   const char *prefix,
00038                   const char *fmt,
00039                   va_list ap)
00040 {
00041   size_t width = (79 - (int)strlen(prefix));
00042   if(!config->mute) {
00043     size_t len;
00044     char *ptr;
00045     char print_buffer[256];
00046 
00047     len = vsnprintf(print_buffer, sizeof(print_buffer), fmt, ap);
00048 
00049     ptr = print_buffer;
00050     while(len > 0) {
00051       fputs(prefix, config->errors);
00052 
00053       if(len > width) {
00054         size_t cut = width-1;
00055 
00056         while(!ISSPACE(ptr[cut]) && cut) {
00057           cut--;
00058         }
00059         if(0 == cut)
00060           /* not a single cutting position was found, just cut it at the
00061              max text width then! */
00062           cut = width-1;
00063 
00064         (void)fwrite(ptr, cut + 1, 1, config->errors);
00065         fputs("\n", config->errors);
00066         ptr += cut+1; /* skip the space too */
00067         len -= cut;
00068       }
00069       else {
00070         fputs(ptr, config->errors);
00071         len = 0;
00072       }
00073     }
00074   }
00075 }
00076 
00077 /*
00078  * Emit 'note' formatted message on configured 'errors' stream, if verbose was
00079  * selected.
00080  */
00081 void notef(struct GlobalConfig *config, const char *fmt, ...)
00082 {
00083   va_list ap;
00084   va_start(ap, fmt);
00085   if(config->tracetype)
00086     voutf(config, NOTE_PREFIX, fmt, ap);
00087   va_end(ap);
00088 }
00089 
00090 /*
00091  * Emit warning formatted message on configured 'errors' stream unless
00092  * mute (--silent) was selected.
00093  */
00094 
00095 void warnf(struct GlobalConfig *config, const char *fmt, ...)
00096 {
00097   va_list ap;
00098   va_start(ap, fmt);
00099   voutf(config, WARN_PREFIX, fmt, ap);
00100   va_end(ap);
00101 }
00102 /*
00103  * Emit help formatted message on given stream.
00104  */
00105 
00106 void helpf(FILE *errors, const char *fmt, ...)
00107 {
00108   va_list ap;
00109   if(fmt) {
00110     va_start(ap, fmt);
00111     fputs("curl: ", errors); /* prefix it */
00112     vfprintf(errors, fmt, ap);
00113     va_end(ap);
00114   }
00115   fprintf(errors, "curl: try 'curl --help' "
00116 #ifdef USE_MANUAL
00117           "or 'curl --manual' "
00118 #endif
00119           "for more information\n");
00120 }
00121 


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:07