libkcal

icalerror.h

Go to the documentation of this file.
00001 /* -*- Mode: C -*- */
00002 /*======================================================================
00003   FILE: icalerror.h
00004   CREATOR: eric 09 May 1999
00005   
00006 
00007 
00008  (C) COPYRIGHT 2000, Eric Busboom <eric@softwarestudio.org>
00009      http://www.softwarestudio.org
00010 
00011  This program is free software; you can redistribute it and/or modify
00012  it under the terms of either: 
00013 
00014     The LGPL as published by the Free Software Foundation, version
00015     2.1, available at: http://www.fsf.org/copyleft/lesser.html
00016 
00017   Or:
00018 
00019     The Mozilla Public License Version 1.0. You may obtain a copy of
00020     the License at http://www.mozilla.org/MPL/
00021 
00022   The original code is icalerror.h
00023 
00024 ======================================================================*/
00025 
00026 
00027 #ifndef ICALERROR_H
00028 #define ICALERROR_H
00029 
00030 #include <assert.h>
00031 #include <stdio.h> /* For icalerror_warn() */
00032 
00033 
00034 #ifdef HAVE_CONFIG_H
00035 #include "config.h"
00036 #endif
00037 
00038 #define ICAL_SETERROR_ISFUNC
00039 
00040 
00044 void icalerror_stop_here(void);
00045 
00046 void icalerror_crash_here(void);
00047 
00048 typedef enum icalerrorenum {
00049     ICAL_NO_ERROR,     /* icalerrno may not be initialized - put it first so and pray that the compiler initialize things to zero */    
00050     ICAL_BADARG_ERROR,
00051     ICAL_NEWFAILED_ERROR,
00052     ICAL_ALLOCATION_ERROR,
00053     ICAL_MALFORMEDDATA_ERROR, 
00054     ICAL_PARSE_ERROR,
00055     ICAL_INTERNAL_ERROR, /* Like assert --internal consist. prob */
00056     ICAL_FILE_ERROR,
00057     ICAL_USAGE_ERROR,
00058     ICAL_UNIMPLEMENTED_ERROR,
00059     ICAL_UNKNOWN_ERROR  /* Used for problems in input to icalerror_strerror()*/
00060 
00061 } icalerrorenum;
00062 
00063 icalerrorenum * icalerrno_return(void);
00064 #define icalerrno (*(icalerrno_return()))
00065 
00071 extern int icalerror_errors_are_fatal;
00072 
00073 /* Warning messages */
00074 
00075 #ifdef __GNUC__ca
00076 #define icalerror_warn(message) {fprintf(stderr,"%s(), %s:%d: %s\n",__FUNCTION__,__FILE__,__LINE__,message);}
00077 #else /* __GNU_C__ */
00078 #define icalerror_warn(message) {fprintf(stderr,"%s:%d: %s\n",__FILE__,__LINE__,message);}
00079 #endif /* __GNU_C__ */
00080 
00081 
00082 void icalerror_clear_errno(void);
00083 void _icalerror_set_errno(icalerrorenum);
00084 
00085 /* Make an individual error fatal or non-fatal. */
00086 typedef enum icalerrorstate { 
00087     ICAL_ERROR_FATAL,     /* Not fata */
00088     ICAL_ERROR_NONFATAL,  /* Fatal */
00089     ICAL_ERROR_DEFAULT,   /* Use the value of icalerror_errors_are_fatal*/
00090     ICAL_ERROR_UNKNOWN    /* Asked state for an unknown error type */
00091 } icalerrorstate ;
00092 
00093 char* icalerror_strerror(icalerrorenum e);
00094 char* icalerror_perror();
00095 void icalerror_set_error_state( icalerrorenum error, icalerrorstate);
00096 icalerrorstate icalerror_get_error_state( icalerrorenum error);
00097 
00098 #ifndef ICAL_SETERROR_ISFUNC
00099 #define icalerror_set_errno(x) \
00100 icalerrno = x; \
00101 if(icalerror_get_error_state(x)==ICAL_ERROR_FATAL || \
00102    (icalerror_get_error_state(x)==ICAL_ERROR_DEFAULT && \
00103     icalerror_errors_are_fatal == 1 )){ \
00104    icalerror_warn(icalerror_strerror(x)); \
00105    assert(0); \
00106 } 
00107 #else
00108 void icalerror_set_errno(icalerrorenum x); 
00109 #endif
00110 
00111 #ifdef ICAL_ERRORS_ARE_FATAL
00112 #undef NDEBUG
00113 #endif
00114 
00115 #define icalerror_check_value_type(value,type);
00116 #define icalerror_check_property_type(value,type);
00117 #define icalerror_check_parameter_type(value,type);
00118 #define icalerror_check_component_type(value,type);
00119 
00120 /* Assert with a message */
00121 #ifdef ICAL_ERRORS_ARE_FATAL
00122 
00123 #ifdef __GNUC__
00124 #define icalerror_assert(test,message) if(!(test)){fprintf(stderr,"%s(), %s:%d: %s\n",__FUNCTION__,__FILE__,__LINE__,message);icalerror_stop_here(); abort();}
00125 #else /*__GNUC__*/
00126 #define icalerror_assert(test,message) if(!(test)){fprintf(stderr,"%s:%d: %s\n",__FILE__,__LINE__,message);icalerror_stop_here(); abort();}
00127 #endif /*__GNUC__*/
00128 
00129 #else /* ICAL_ERRORS_ARE_FATAL */
00130 #define icalerror_assert(test,message) 
00131 #endif /* ICAL_ERRORS_ARE_FATAL */
00132 
00133 /* Check & abort if check fails */
00134 #define icalerror_check_arg(test,arg) if(!(test)) { icalerror_set_errno(ICAL_BADARG_ERROR); }
00135 
00136 /* Check & return void if check fails*/
00137 #define icalerror_check_arg_rv(test,arg) if(!(test)) {icalerror_set_errno(ICAL_BADARG_ERROR); return; }
00138 
00139 /* Check & return 0 if check fails*/
00140 #define icalerror_check_arg_rz(test,arg) if(!(test)) { icalerror_set_errno(ICAL_BADARG_ERROR); return 0;}
00141 
00142 /* Check & return an error if check fails*/
00143 #define icalerror_check_arg_re(test,arg,error) if(!(test)) { icalerror_stop_here(); assert(0); return error;}
00144 
00145 /* Check & return something*/
00146 #define icalerror_check_arg_rx(test,arg,x) if(!(test)) { icalerror_set_errno(ICAL_BADARG_ERROR); return x;}
00147 
00148 
00149 
00150 /* String interfaces to set an error to NONFATAL and restore it to its
00151    original value */
00152 
00153 icalerrorstate icalerror_supress(const char* error);
00154 void icalerror_restore(const char* error, icalerrorstate es);
00155 
00156 
00157 #endif /* !ICALERROR_H */
00158 
00159 
00160