home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / PROG / CUJDEC93.ZIP / WINROTH / MACROS.H < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-08  |  5.0 KB  |  151 lines

  1. /*
  2. ** Exception Library -- General exception handling for ANSI C programs
  3. ** 
  4. ** Copyright (C) 1993 Computational Vision and Active Perception Lab. (CVAP),
  5. **                    Royal Institute of Technology, Stockholm.
  6. **
  7. ** This library is free software; you can redistribute it and/or
  8. ** modify it under the terms of the GNU Library General Public
  9. ** License as published by the Free Software Foundation; either
  10. ** version 2 of the License, or (at your option) any later version.
  11. ** 
  12. ** This library is distributed in the hope that it will be useful,
  13. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. ** Library General Public License for more details.
  16. ** 
  17. ** You should have received a copy of the GNU Library General Public
  18. ** License along with this library (see COPYING-LIB); if not, write to 
  19. ** the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 
  20. ** USA.
  21. ** 
  22. **                            Written by
  23. **                                 
  24. **                  Harald Winroth, Matti Rendahl
  25. **      Computational Vision and Active Perception Laboratory
  26. **                  Royal Institute of Technology
  27. **                        S-100 44 Stockholm
  28. **                              Sweden
  29. **                                 
  30. ** Report bugs to candela-bug@bion.kth.se, and direct all inquiries to 
  31. ** candela@bion.kth.se.
  32. **
  33. */
  34.  
  35. /*
  36.  * exc-sig-macros.h.
  37.  *
  38.  * This file contains macros for expanding a list of signal names to a type 
  39.  * definition (excSigDomain), a structure initialization (exc_sig) and an
  40.  * exception handler (exc_sig_handler).
  41.  */
  42.  
  43. #ifndef _exception_exc_sig_macros_h
  44. #define _exception_exc_sig_macros_h
  45.  
  46. /*
  47.  * Iterators
  48.  */
  49.  
  50. #define _EXC_SIG_EVAL_1A(OP, F1, F2, F3, ARGS) OP(F1, ARGS, _EXC_SIG_EVAL_1B)
  51. #define _EXC_SIG_EVAL_1B(OP, F1, F2, F3, ARGS) OP(F1, ARGS, _EXC_SIG_EVAL_1A)
  52.  
  53. #define _EXC_SIG_EVAL_2A(OP, F1, F2, F3, ARGS) OP(F2, ARGS, _EXC_SIG_EVAL_2B)
  54. #define _EXC_SIG_EVAL_2B(OP, F1, F2, F3, ARGS) OP(F2, ARGS, _EXC_SIG_EVAL_2A)
  55.  
  56. #define _EXC_SIG_EVAL_3A(OP, F1, F2, F3, ARGS) OP(F3, ARGS, _EXC_SIG_EVAL_3B)
  57. #define _EXC_SIG_EVAL_3B(OP, F1, F2, F3, ARGS) OP(F3, ARGS, _EXC_SIG_EVAL_3A)
  58.  
  59. #define _EXC_SIG_EVAL_1(FORMS) _EXC_SIG_EVAL_1A FORMS
  60. #define _EXC_SIG_EVAL_2(FORMS) _EXC_SIG_EVAL_2A FORMS
  61. #define _EXC_SIG_EVAL_3(FORMS) _EXC_SIG_EVAL_3A FORMS
  62.  
  63. #define _EXC_SIG_APPLY(FUNC, ARGS, NEXT) FUNC ARGS NEXT
  64. #define _EXC_SIG_APPLY_STOP(FUNC, ARGS, NEXT) FUNC ARGS
  65.  
  66. /*
  67.  * Misc
  68.  */ 
  69.  
  70. #define _EXC_SIG_ALLOW_SEMICOLON_HERE                          \
  71.     extern int _exc_sig_allow_semicolon_here /* dummy declaration */
  72.  
  73. /*
  74.  * Signal name entries
  75.  */
  76.  
  77. #define _EXC_SIG_ENTRY_DCL(UP_NAME, LOW_NAME, PRINT_NAME)              \
  78.     excSig LOW_NAME;
  79.  
  80. #define _EXC_SIG_ENTRY_DEF(UP_NAME, LOW_NAME, PRINT_NAME)              \
  81.     {PRINT_NAME, UP_NAME},
  82.  
  83. #define _EXC_SIG_ENTRY_HDL(UP_NAME, LOW_NAME, PRINT_NAME)              \
  84.     case UP_NAME: THROW_TYPED (exc_sig.LOW_NAME, exc_sig_type);
  85.  
  86. #define _EXC_SIG_ENTRY(UP_NAME, LOW_NAME)                      \
  87.   (_EXC_SIG_APPLY, _EXC_SIG_ENTRY_DCL, _EXC_SIG_ENTRY_DEF, _EXC_SIG_ENTRY_HDL,\
  88.    (UP_NAME, LOW_NAME, #UP_NAME))
  89.  
  90. /*
  91.  * Signal struct
  92.  */
  93.  
  94. #define _EXC_SIG_DCL1() typedef struct {
  95. #define _EXC_SIG_DCL2() excSig unknown; } excSigDomain
  96.  
  97. #define _EXC_SIG_DEF1() excSigDomain exc_sig = {
  98. #define _EXC_SIG_DEF2() {"<unknown signal>", 0}}
  99.  
  100. /*
  101.   * Exception handler.
  102.   *
  103.   * Note: This signal handler may be exited with a longjmp. The signal mask
  104.   * will not be restored in that case. Therefore, the mask must be reset
  105.   * before the corresponding exception is thrown. For SYSV, this has been
  106.   * taken care of by specifying SA_NODEFER to sigaction. For BSD, we
  107.   * manipulate the mask directly.
  108.  */
  109.  
  110. #if defined(SVR4) || defined(SYSV) || defined(_SYSV_)
  111. #define _EXC_SIG_HDL1()                               \
  112.     void exc_sig_handler (_EXC_SIG_HANDLER_ARGS(sig))                  \
  113.     {                                           \
  114.     switch (sig)                                   \
  115.     {
  116. #else
  117. #define _EXC_SIG_HDL1()                               \
  118.     void exc_sig_handler (_EXC_SIG_HANDLER_ARGS(sig))                  \
  119.     {                                           \
  120.     sigsetmask (sigblock (0) & ~sigmask(sig));                  \
  121.     switch (sig)                                   \
  122.     {
  123. #endif
  124. #define _EXC_SIG_HDL2()                                  \
  125.         default:                                  \
  126.         THROW_TYPED (exc_sig.unknown, exc_sig_type);              \
  127.     }                                      \
  128.     }                                           \
  129.     _EXC_SIG_ALLOW_SEMICOLON_HERE
  130.  
  131. /*
  132.  * Resulting declaration/definition
  133.  */
  134.  
  135. #define _EXC_SIG_FORMS(LIST)                              \
  136.   (_EXC_SIG_APPLY, _EXC_SIG_DCL1, _EXC_SIG_DEF1, _EXC_SIG_HDL1, ())          \
  137.   LIST                                          \
  138.   (_EXC_SIG_APPLY_STOP, _EXC_SIG_DCL2, _EXC_SIG_DEF2, _EXC_SIG_HDL2, ())
  139.  
  140. #define _EXC_SIG_DECLARE(LIST) _EXC_SIG_EVAL_1 (_EXC_SIG_FORMS(LIST))
  141. #define _EXC_SIG_DEFINE(LIST)  _EXC_SIG_EVAL_2 (_EXC_SIG_FORMS(LIST))
  142. #define _EXC_SIG_HANDLER(LIST) _EXC_SIG_EVAL_3 (_EXC_SIG_FORMS(LIST))
  143.  
  144. /*
  145.  * Let _EXC_SIG expand to a declaration only (it will be redefined later).
  146.  */
  147.  
  148. #define _EXC_SIG(LIST) _EXC_SIG_DECLARE (LIST)
  149.  
  150. #endif /* !_exception_exc_sig_macros_h */
  151.