err.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /**************************************************************************
  2. **
  3. ** Copyright (C) 1993 David E. Stewart & Zbigniew Leyk, all rights reserved.
  4. **
  5. ** Meschach Library
  6. **
  7. ** This Meschach Library is provided "as is" without any express
  8. ** or implied warranty of any kind with respect to this software.
  9. ** In particular the authors shall not be liable for any direct,
  10. ** indirect, special, incidental or consequential damages arising
  11. ** in any way from use of the software.
  12. **
  13. ** Everyone is granted permission to copy, modify and redistribute this
  14. ** Meschach Library, provided:
  15. ** 1. All copies contain this copyright notice.
  16. ** 2. All modified copies shall carry a notice stating who
  17. ** made the last modification and the date of such modification.
  18. ** 3. No charge is made for this software or works derived from it.
  19. ** This clause shall not be construed as constraining other software
  20. ** distributed on the same medium as this software, nor is a
  21. ** distribution fee considered a charge.
  22. **
  23. ***************************************************************************/
  24. /* err.h 28/09/1993 */
  25. /* RCS id: $Id: err.h,v 1.2 1995/01/30 14:48:05 des Exp $ */
  26. #ifndef ERRHEADER
  27. #define ERRHEADER
  28. #include <setjmp.h>
  29. #include "machine.h"
  30. /* Error recovery */
  31. extern jmp_buf restart;
  32. /* max. # of error lists */
  33. #define ERR_LIST_MAX_LEN 10
  34. /* main error functions */
  35. #ifndef ANSI_C
  36. extern int ev_err(); /* main error handler */
  37. extern int set_err_flag(); /* for different ways of handling
  38. errors, returns old value */
  39. extern int count_errs(); /* to avoid "too many errors" */
  40. extern int err_list_attach(); /* for attaching a list of errors */
  41. extern int err_is_list_attached(); /* checking if a list is attached */
  42. extern int err_list_free(); /* freeing a list of errors */
  43. #else /* ANSI_C */
  44. extern int ev_err(const char *,int,int,const char *,int); /* main error handler */
  45. extern int set_err_flag(int flag); /* for different ways of handling
  46. errors, returns old value */
  47. extern int count_errs(int true_false); /* to avoid "too many errors" */
  48. extern int err_list_attach(int list_num, int list_len,
  49. char **err_ptr,int warn); /* for attaching a list of errors */
  50. extern int err_is_list_attached(int list_num); /* checking if a list
  51. is attached */
  52. extern int err_list_free(int list_num); /* freeing a list of errors */
  53. #endif
  54. /* error(E_TYPE,"myfunc") raises error type E_TYPE for function my_func() */
  55. #define error(err_num,fn_name) ev_err(__FILE__,err_num,__LINE__,fn_name,0)
  56. /* warning(WARN_TYPE,"myfunc") raises warning type WARN_TYPE for
  57. function my_func() */
  58. #define warning(err_num,fn_name) ev_err(__FILE__,err_num,__LINE__,fn_name,1)
  59. /* error flags */
  60. #define EF_EXIT 0 /* exit on error */
  61. #define EF_ABORT 1 /* abort (dump core) on error */
  62. #define EF_JUMP 2 /* jump on error */
  63. #define EF_SILENT 3 /* jump, but don't print message */
  64. #define ERREXIT() set_err_flag(EF_EXIT)
  65. #define ERRABORT() set_err_flag(EF_ABORT)
  66. /* don't print message */
  67. #define SILENTERR() if ( ! setjmp(restart) ) set_err_flag(EF_SILENT)
  68. /* return here on error */
  69. #define ON_ERROR() if ( ! setjmp(restart) ) set_err_flag(EF_JUMP)
  70. /* error types */
  71. #define E_UNKNOWN 0
  72. #define E_SIZES 1
  73. #define E_BOUNDS 2
  74. #define E_MEM 3
  75. #define E_SING 4
  76. #define E_POSDEF 5
  77. #define E_FORMAT 6
  78. #define E_INPUT 7
  79. #define E_NULL 8
  80. #define E_SQUARE 9
  81. #define E_RANGE 10
  82. #define E_INSITU2 11
  83. #define E_INSITU 12
  84. #define E_ITER 13
  85. #define E_CONV 14
  86. #define E_START 15
  87. #define E_SIGNAL 16
  88. #define E_INTERN 17
  89. #define E_EOF 18
  90. #define E_SHARED_VECS 19
  91. #define E_NEG 20
  92. #define E_OVERWRITE 21
  93. #define E_BREAKDOWN 22
  94. /* warning types */
  95. #define WARN_UNKNOWN 0
  96. #define WARN_WRONG_TYPE 1
  97. #define WARN_NO_MARK 2
  98. #define WARN_RES_LESS_0 3
  99. #define WARN_SHARED_VEC 4
  100. /* error catching macros */
  101. /* execute err_part if error errnum is raised while executing ok_part */
  102. #define catch(errnum,ok_part,err_part) \
  103. { jmp_buf _save; int _err_num, _old_flag; \
  104. _old_flag = set_err_flag(EF_SILENT); \
  105. MEM_COPY(restart,_save,sizeof(jmp_buf)); \
  106. if ( (_err_num=setjmp(restart)) == 0 ) \
  107. { ok_part; \
  108. set_err_flag(_old_flag); \
  109. MEM_COPY(_save,restart,sizeof(jmp_buf)); } \
  110. else if ( _err_num == errnum ) \
  111. { set_err_flag(_old_flag); \
  112. MEM_COPY(_save,restart,sizeof(jmp_buf)); \
  113. err_part; } \
  114. else { set_err_flag(_old_flag); \
  115. MEM_COPY(_save,restart,sizeof(jmp_buf)); \
  116. error(_err_num,"catch"); \
  117. } \
  118. }
  119. /* execute err_part if any error raised while executing ok_part */
  120. #define catchall(ok_part,err_part) \
  121. { jmp_buf _save; int _err_num, _old_flag; \
  122. _old_flag = set_err_flag(EF_SILENT); \
  123. MEM_COPY(restart,_save,sizeof(jmp_buf)); \
  124. if ( (_err_num=setjmp(restart)) == 0 ) \
  125. { ok_part; \
  126. set_err_flag(_old_flag); \
  127. MEM_COPY(_save,restart,sizeof(jmp_buf)); } \
  128. else \
  129. { set_err_flag(_old_flag); \
  130. MEM_COPY(_save,restart,sizeof(jmp_buf)); \
  131. err_part; } \
  132. }
  133. /* print message if error raised while executing ok_part,
  134. then re-raise error to trace calls */
  135. #define tracecatch(ok_part,function) \
  136. { jmp_buf _save; int _err_num, _old_flag; \
  137. _old_flag = set_err_flag(EF_JUMP); \
  138. MEM_COPY(restart,_save,sizeof(jmp_buf)); \
  139. if ( (_err_num=setjmp(restart)) == 0 ) \
  140. { ok_part; \
  141. set_err_flag(_old_flag); \
  142. MEM_COPY(_save,restart,sizeof(jmp_buf)); } \
  143. else \
  144. { set_err_flag(_old_flag); \
  145. MEM_COPY(_save,restart,sizeof(jmp_buf)); \
  146. error(_err_num,function); } \
  147. }
  148. #endif /* ERRHEADER */