00001 /* Part of the culibs project, <http://www.eideticdew.org/culibs/>. 00002 * Copyright (C) 2004--2010 Petter Urkedal <paurkedal@eideticdew.org> 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation, either version 3 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 #ifndef CU_DIAG_H 00019 #define CU_DIAG_H 00020 00021 #include <cu/fwd.h> 00022 #include <cu/clos.h> 00023 #include <stdio.h> 00024 #include <stdarg.h> 00025 #include <cu/va_ref.h> 00026 00027 CU_BEGIN_DECLARATIONS 00028 00029 extern int cuP_verbosity; 00030 00031 /** \defgroup cu_diag_h cu/diag.h: Printing and Error Reporting 00032 ** @{ \ingroup cu_base_mod */ 00033 00034 /** A specialised \ref cu_fprintf for printing error messages. */ 00035 void cu_errf(char const *fmt, ...); 00036 00037 /** As \a cu_errf, but passing arguments as a \c va_list. */ 00038 void cu_verrf(char const *msg, va_list va); 00039 00040 /** A specialised \ref cu_fprintf for printing warnings. */ 00041 void cu_warnf(char const *fmt, ...); 00042 00043 /** As \a cu_warnf, but passing arguments as a \c va_list. */ 00044 void cu_vwarnf(char const *msg, va_list va); 00045 00046 /** Prints an informative message to if verbosity level is at least 00047 ** \a level. */ 00048 void cu_verbf(int level, char const *fmt, ...); 00049 00050 /** The current verbosity level. */ 00051 CU_SINLINE int cu_verbosity() { return cuP_verbosity; } 00052 00053 /** Sets the verbosity level for \ref cu_verbf and \ref cu_verbf_at calls. */ 00054 void cu_set_verbosity(int verbosity); 00055 00056 /** Prints an internal error without location and aborts. Usually \ref cu_bugf 00057 ** is more useful. */ 00058 void cu_bugf_n(char const *fmt, ...) CU_ATTR_NORETURN; 00059 00060 /** Prints an internal error with reference to source code and aborts. */ 00061 void cu_bugf_at(cu_location_t, char const *fmt, ...) CU_ATTR_NORETURN; 00062 00063 /** Prints an internal error with reference to source code and aborts. */ 00064 void cu_bugf_fl(char const *file, int line, 00065 char const *msg, ...) CU_ATTR_NORETURN; 00066 00067 /** Prints an internal error with the location of the callee and aborts. The 00068 ** arguments are the same as \ref cu_bugf_n. */ 00069 #define cu_bugf(...) cu_bugf_fl(__FILE__, __LINE__, __VA_ARGS__) 00070 00071 /** Asserts that the code point of the macro expansion is unreachable. For a 00072 ** version conditioned on \c CU_NDEBUG, see \ref cu_debug_unreachable. */ 00073 #define cu_bug_unreachable() \ 00074 cu_bugf_fl(__FILE__, __LINE__, \ 00075 "This point should not have been reached.") 00076 00077 /** Temporary replacement for unfinished code, which aborts with an error 00078 ** message. */ 00079 #define cu_bug_unfinished() \ 00080 cu_bugf_fl(__FILE__, __LINE__, \ 00081 "Reached a code point which is not yet written.") 00082 00083 /** Similar to \ref cu_bug_unfinished, but also accepts an argument describing 00084 ** the unfinished work. */ 00085 #define cu_bug_todo(descr) cu_bugf_fl(__FILE__, __LINE__, "TODO: "descr) 00086 00087 /** Report that argument number \a argno (from 0) with symbolic name \a argname 00088 ** is outside the domain for the call to \a funcname, and print the additional 00089 ** message using the printf format \a fmt with the remaining arguments, then 00090 ** abort. */ 00091 void cu_bugf_domain_in(char const *funcname, int argno, char const *argname, 00092 char const *fmt, ...) CU_ATTR_NORETURN; 00093 00094 /** Convenience macro around \ref cu_bugf_domain_in, where \c __func__ is 00095 ** passed as the first argument. */ 00096 #define cu_bugf_domain(...) cu_bugf_domain_in(__func__, __VA_ARGS__) 00097 00098 void cu_handle_syserror(int err_code, char const *proc_name); 00099 00100 void cu_raise_out_of_memory(size_t size); 00101 00102 CU_SINLINE void 00103 cu_check_out_of_memory(void *ptr, size_t size) 00104 { 00105 if (!ptr) 00106 cu_raise_out_of_memory(size); 00107 } 00108 00109 00110 00111 /* --- The rest are deprecated. --- */ 00112 00113 typedef cu_clop(cu_diag_format_fn_t, void, 00114 cu_str_t fmt, cu_va_ref_t va, FILE *out); 00115 00116 /*!Define a new format key for \ref cu_fprintf by mapping \a key to the 00117 * handler \a fn. The handler will be passed the format specifier along 00118 * with reference to the current \c va_list state and the output file. 00119 * \deprecated This is deprecated, use \ref cufo_mod "libcufo" for extended 00120 * printing support. */ 00121 void cu_diag_define_format_key(char key, cu_diag_format_fn_t fn) 00122 CU_ATTR_DEPRECATED; 00123 00124 /*!A \c fprintf work-alike which supports registering new keys through \ref 00125 * cu_diag_define_format_key. \note The standard format key support is 00126 * lacking, esp it does not support widths and precision. 00127 * \deprecated This is deprecated, use \ref cufo_mod "libcufo" for extended 00128 * printing support. */ 00129 void cu_fprintf(FILE *, char const *, ...); 00130 00131 /*!As \ref cu_fprintf, but passing arguments as a \c va_list. 00132 * \deprecated This is deprecated, use \ref cufo_mod "libcufo" for extended 00133 * printing support. */ 00134 void cu_vfprintf(FILE *, char const *, va_list va); 00135 00136 /*!A specialised \ref cu_fprintf for printing error messages with reference 00137 * to source code. 00138 * \deprecated This function is deprecated and does not use the new \ref 00139 * cu_logging_h "logging" framework. Use \ref cu_errf with the "%:" format 00140 * specifier instead. */ 00141 void cu_errf_at(cu_location_t loc, char const *fmt, ...); 00142 00143 /*!As \a cu_errf_at, but passing arguments as a \c va_list. 00144 * \deprecated This function is deprecated and does not use the new \ref 00145 * cu_logging_h "logging" framework. Use \ref cu_verrf with the "%:" format 00146 * specifier instead. */ 00147 void cu_verrf_at(cu_location_t loc, char const *msg, va_list va); 00148 00149 /*!A specialised \ref cu_fprintf for printing warnings with reference 00150 * to source code. 00151 * \deprecated This function is deprecated and does not use the new \ref 00152 * cu_logging_h "logging" framework. Use \ref cu_warnf with the "%:" format 00153 * specifier instead. */ 00154 void cu_warnf_at(cu_location_t loc, char const *fmt, ...); 00155 00156 /*!As \a cu_warnf_at, but passing arguments as a \c va_list. 00157 * \deprecated This function is deprecated and does not use the new \ref 00158 * cu_logging_h "logging" framework. Use \ref cu_vwarnf with the "%:" format 00159 * specifier instead. */ 00160 void cu_vwarnf_at(cu_location_t loc, char const *msg, va_list va); 00161 00162 /*!Prints an informative message with reference to source code if verbosity 00163 * level is at least \a level. 00164 * \deprecated This function is deprecated and does not use the new \ref 00165 * cu_logging_h "logging" framework. Use \ref cu_verbf with the "%:" format 00166 * specifier instead. */ 00167 void cu_verbf_at(int level, cu_location_t, char const *fmt, ...); 00168 00169 00170 /** @} */ 00171 CU_END_DECLARATIONS 00172 00173 #endif