00001 /* * 00002 * This file is part of the ESO X-shooter Pipeline * 00003 * Copyright (C) 2006 European Southern Observatory * 00004 * * 00005 * This library is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the GNU General Public License * 00016 * along with this program; if not, write to the Free Software * 00017 * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA * 00018 * */ 00019 00020 /* 00021 * $Author: amodigli $ 00022 * $Date: 2011/12/02 14:15:28 $ 00023 * $Revision: 1.8 $ 00024 * $Name: HEAD $ 00025 */ 00026 00027 #ifdef HAVE_CONFIG_H 00028 # include <config.h> 00029 #endif 00030 00031 /*----------------------------------------------------------------------------*/ 00045 /*----------------------------------------------------------------------------*/ 00048 /*----------------------------------------------------------------------------- 00049 Includes 00050 -----------------------------------------------------------------------------*/ 00051 00052 #include "xsh_msg.h" 00053 00054 #include <cpl.h> 00055 #include <stdarg.h> 00056 00057 /*----------------------------------------------------------------------------- 00058 Defines 00059 -----------------------------------------------------------------------------*/ 00060 00061 #define MAXSTRINGLENGTH 1024 /* Used to pass a va_list to cpl_msg_warning */ 00062 00063 /*----------------------------------------------------------------------------- 00064 Variables 00065 -----------------------------------------------------------------------------*/ 00066 static int number_of_warnings = 0; 00067 /* Coun't the number of warnings since initialization */ 00068 00069 /*----------------------------------------------------------------------------*/ 00078 /*----------------------------------------------------------------------------*/ 00079 void 00080 xsh_msg_init (void) 00081 { 00082 /* Initialize per recipe: */ 00083 number_of_warnings = 0; 00084 00085 cpl_msg_set_indentation (2); 00086 00087 /* CPL message format is 00088 * [Time][Verbosity][domain][component] message 00089 * 00090 * Don't show the (variable length and wildly 00091 * fluctuating) component. It interferes with 00092 * indentation. The component is available anyway 00093 * on CPL_MSG_DEBUG level. 00094 * 00095 * Don't show the time. This is available on 00096 * the DEBUG level. Use esorex --time to time 00097 * a recipe. 00098 */ 00099 00100 cpl_msg_set_time_off (); 00101 /* Leave it to the recipe caller 00102 * application to define the verbosity 00103 * level cpl_msg_set_level(...); 00104 */ 00105 cpl_msg_set_domain_on (); 00106 cpl_msg_set_component_off (); 00107 } 00108 00109 /*----------------------------------------------------------------------------*/ 00114 /*----------------------------------------------------------------------------*/ 00115 int 00116 xsh_msg_get_warnings ( void ) 00117 { 00118 return number_of_warnings; 00119 } 00120 00121 /*----------------------------------------------------------------------------*/ 00135 /*----------------------------------------------------------------------------*/ 00136 void 00137 xsh_msg_warning_macro (const char *fct, const char *format, ...) 00138 { 00139 char printbuffer[MAXSTRINGLENGTH]; 00140 /* Message functions should never fail, so don't rely on 00141 dynamic memory allocation */ 00142 00143 va_list al; 00144 00145 va_start (al, format); 00146 vsnprintf (printbuffer, MAXSTRINGLENGTH - 1, format, al); 00147 va_end (al); 00148 00149 printbuffer[MAXSTRINGLENGTH - 1] = '\0'; 00150 00151 cpl_msg_warning (fct, "%s", printbuffer); 00152 00153 number_of_warnings += 1; 00154 } 00155