1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
|
/* $Id: cpl_error_impl.h,v 1.22 2012-04-05 14:44:50 llundin Exp $
*
* This file is part of the ESO Common Pipeline Library
* Copyright (C) 2001-2005 European Southern Observatory
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* $Author: llundin $
* $Date: 2012-04-05 14:44:50 $
* $Revision: 1.22 $
* $Name: not supported by cvs2svn $
*/
#ifndef CPL_ERROR_IMPL_H
#define CPL_ERROR_IMPL_H
#include "cpl_error.h"
#include "cpl_type.h"
#include "cpl_tools.h"
#include <regex.h>
CPL_BEGIN_DECLS
/*-----------------------------------------------------------------------------
Define
-----------------------------------------------------------------------------*/
/*
* As the error handler itself should never fail, it cannot rely on
* allocating memory dynamically. Therefore, define max limits for
* string lengths, size of error queue.
*/
#ifdef PATH_MAX
#define MAX_FILE_LENGTH PATH_MAX
#else
#define MAX_FILE_LENGTH 4096
#endif
#define MAX_NAME_LENGTH 50
/**
* @internal
* @ingroup cpl_error
* @brief Set CPL error code with the current location
* @param code Error code
* @return The specified error code.
* @see cpl_error_set()
*
*/
#define cpl_error_set_(code) cpl_error_set(cpl_func, code)
/**
* @internal
* @ingroup cpl_error
* @brief Propagate a CPL-error to the current location.
* @return The preexisting CPL error code (possibly CPL_ERROR_NONE).
* @see cpl_error_set_where()
*/
#define cpl_error_set_where_() cpl_error_set_where(cpl_func)
/**
* @internal
* @ingroup cpl_error
* @brief Set CPL error code with the current location along with a text message
* @param code Error code
* @param ... Variable argument list with message
* @return The CPL error code
* @see cpl_error_set_message()
*/
#define cpl_error_set_message_(code, ...) \
cpl_error_set_message(cpl_func, code, __VA_ARGS__)
/**
* @ingroup cpl_error
* @internal
* @brief
* Set CPL error code, function name, source file, line number where
* a FITS error occurred along with a FITS specific text message
*
* @param code CPL Error code
* @param fitscode The error code of the failed FITS (CFITSIO) call
* @param fitsfunction The FITS (CFITSIO) function (_not_ as a string) or
* the empty string
* @param ... Variable argument list with message
* @return The CPL error code
* @see cpl_error_set_message()
*
* Example of usage:
* @code
*
* int ioerror = 0;
* (void)fits_open_diskfile(&file, name, READONLY, &ioerror);
*
* if (ioerror) {
* return cpl_error_set_fits(CPL_ERROR_FILE_IO, ioerror,
* fits_open_diskfile,
* "filename='%s', xtnum=%d", name, position);
* }
*
* @endcode
*
* @hideinitializer
*/
#define cpl_error_set_fits(code, fitscode, fitsfunction, ...) \
cpl_error_set_fits_macro(cpl_func, code, fitscode, \
CPL_STRINGIFY(fitsfunction), \
__FILE__, __LINE__, __VA_ARGS__)
/**
* @ingroup cpl_error
* @internal
* @brief
* Set CPL error code, function name, source file, line number where
* a regex error occurred along with a regex specific text message
*
* @param code CPL Error code
* @param regcode The error code of the failed regcomp() call
* @param preg The regex of the failed call
* @param ... Variable argument list with message
* @return The CPL error code
* @see regcomp(), cpl_error_set_message()
*
* Example of usage:
* @code
*
* regex_t regex;
* const int regerror = regcomp(®ex, pattern, REG_EXTENDED | REG_NOSUB);
*
* if (regerror) {
* return cpl_error_set_regex(CPL_ERROR_ILLEGAL_INPUT, regerror, ®ex,
* "pattern='%s', pattern);
* }
*
* @endcode
*
* @hideinitializer
*/
#define cpl_error_set_regex(code, regcode, preg, ...) \
cpl_error_set_regex_macro(cpl_func, code, regcode, preg, \
__FILE__, __LINE__, __VA_ARGS__)
#ifndef CPL_WCS_INSTALLED
/* Make sure the WCS error macro can be invoked also when
wcs_errmsg is not defined. This is useful for unit testing. */
#define wcs_errmsg NULL
#endif
/**
* @ingroup cpl_error
* @internal
* @brief
* Set CPL error code, function name, source file, line number where
* a WCSLIB error occurred along with a WCSLIB specific text message
* @param code CPL Error code
* @param wcscode The error code of the failed WCSLIB call
* @param wcsfunction Character string with WCSLIB function name or
* the empty string
* @param ... Variable argument list with message
* @return The CPL error code
* @see cpl_error_set_message(), WCSLIB
* @note This macro accesses
* extern const char *wcs_errmsg[];
* If an internal inconsistency in WCSLIB causes a too large error number
* to be returned, the behaviour is undefined (e.g. a segfault).
*
* Example of usage:
* @code
*
* #ifdef CPL_WCS_INSTALLED
*
* #include <wcslib.h>
*
* const int wcserror = wcspih(shdr,np,0,0,&nrej,&nwcs,&wwcs);
*
* if (wcserror) {
* return cpl_error_set_wcs(CPL_ERROR_ILLEGAL_INPUT, wcserror,
* "wcspih", "np=%d", np);
* }
*
* #endif
*
* @endcode
*
* @hideinitializer
*/
#define cpl_error_set_wcs(code, wcscode, wcsfunction, ...) \
cpl_error_set_wcs_macro(cpl_func, code, wcscode, wcsfunction, \
wcs_errmsg, __FILE__, __LINE__, __VA_ARGS__)
struct _cpl_error_ {
cpl_error_code code;
unsigned line;
char function[MAX_NAME_LENGTH+1];
char file[MAX_FILE_LENGTH+1];
char msg[CPL_ERROR_MAX_MESSAGE_LENGTH];
};
/*-----------------------------------------------------------------------------
Prototypes of private functions
-----------------------------------------------------------------------------*/
cpl_error * cpl_errorstate_append(void);
const cpl_error * cpl_errorstate_find(void) CPL_ATTR_PURE;
cpl_boolean cpl_error_is_set(void) CPL_ATTR_PURE;
cpl_boolean cpl_error_is_readonly(void) CPL_ATTR_PURE;
void cpl_error_set_readonly(void);
void cpl_error_reset_readonly(void);
cpl_error_code
cpl_error_set_fits_macro(const char *, cpl_error_code, int,
const char *, const char *,
unsigned, const char *, ...) CPL_ATTR_PRINTF(7,8);
cpl_error_code
cpl_error_set_regex_macro(const char *, cpl_error_code, int,
const regex_t *, const char *,
unsigned, const char *, ...) CPL_ATTR_PRINTF(7,8);
cpl_error_code
cpl_error_set_wcs_macro(const char *, cpl_error_code, int,
const char *, const char *[], const char *,
unsigned, const char *, ...) CPL_ATTR_PRINTF(8,9);
#ifdef HAVE_LIBPTHREAD
void cpl_error_init_locks(void);
#endif
CPL_END_DECLS
#endif
/* end of cpl_error_impl.h */
|