home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / base / error.cxx < prev    next >
C/C++ Source or Header  |  1995-04-04  |  2KB  |  101 lines

  1.  
  2.  
  3.  
  4.  
  5. /*
  6.  *
  7.  *          Copyright (C) 1994, M. A. Sridhar
  8.  *  
  9.  *
  10.  *     This software is Copyright M. A. Sridhar, 1994. You are free
  11.  *     to copy, modify or distribute this software  as you see fit,
  12.  *     and to use  it  for  any  purpose, provided   this copyright
  13.  *     notice and the following   disclaimer are included  with all
  14.  *     copies.
  15.  *
  16.  *                        DISCLAIMER
  17.  *
  18.  *     The author makes no warranties, either expressed or implied,
  19.  *     with respect  to  this  software, its  quality, performance,
  20.  *     merchantability, or fitness for any particular purpose. This
  21.  *     software is distributed  AS IS.  The  user of this  software
  22.  *     assumes all risks  as to its quality  and performance. In no
  23.  *     event shall the author be liable for any direct, indirect or
  24.  *     consequential damages, even if the  author has been  advised
  25.  *     as to the possibility of such damages.
  26.  *
  27.  */
  28.  
  29.  
  30.  
  31.  
  32. #ifdef __GNUC__
  33. #pragma implementation
  34. #endif
  35.  
  36.  
  37.  
  38. #include <stdio.h>
  39. #include <iostream.h>
  40. #include <stdlib.h>
  41. #include <stdarg.h>
  42.  
  43. #include "base/error.h"
  44.  
  45. static bool YACLWarnFunction (const char* message)
  46. {
  47.     cerr << "YACL: " << message << endl << flush;
  48.     return TRUE;
  49. }
  50.  
  51. static CL_ErrorHandler warnPtr  = YACLWarnFunction,
  52.                        fatalPtr = YACLWarnFunction;
  53.  
  54. void CL_Error::Warning (const char *fmt, ...)
  55. {
  56.     va_list args;
  57.     char msg[200];
  58.  
  59.     va_start (args, fmt);
  60.     vsprintf (msg, fmt,  args);
  61.     (*warnPtr) (msg); 
  62. }
  63.  
  64.  
  65.  
  66. void CL_Error::Fatal (const char *fmt, ...)
  67. {
  68.     va_list args;
  69.     char msg[200];
  70.  
  71.     va_start (args, fmt);
  72.     vsprintf (msg, fmt,  args);
  73.     if ((*fatalPtr) (msg))
  74.         exit (1);
  75. }
  76.  
  77.  
  78.  
  79. CL_ErrorHandler CL_Error::SetWarningHandler    (CL_ErrorHandler
  80.                                                 handler)
  81. {
  82.     if (!handler)
  83.         return warnPtr;
  84.     CL_ErrorHandler h = warnPtr;
  85.     warnPtr = handler;
  86.     return h;
  87. }
  88.  
  89.  
  90. CL_ErrorHandler CL_Error::SetFatalErrorHandler (CL_ErrorHandler handler)
  91. {
  92.     if (!handler)
  93.         return fatalPtr;
  94.     CL_ErrorHandler h = fatalPtr;
  95.     fatalPtr = handler;
  96.     return h;
  97. }
  98.  
  99.  
  100.  
  101.