home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / mesch12a.zip / err.h < prev    next >
C/C++ Source or Header  |  1994-01-13  |  6KB  |  182 lines

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