home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / desklib / examples / DeskLib / Examples / OtherSrc / c / Error next >
Text File  |  1993-07-13  |  3KB  |  124 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for 
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #                                      
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Error.c
  12.     Author:  Copyright © 1992 Jason Williams
  13.              Improved by Philip Colmer
  14.     Version: 0.19 (13 Jul 1993)
  15.     Purpose: Centralised error handling functions
  16.     Mods:    7 Apr 1992 - JCW - Added Error_OutOfMemory
  17.             30 Apr 1993 - JCW - Fixed (Wimp_ReportError prototype changed)
  18.             14 Jun 1993 - PJC - Allowed Error_Report(Fatal) to take
  19.                                 variable arguments
  20.             13 Jul 1993 - PJC - Added varargs to "Internal" versions of above
  21. */
  22.  
  23.  
  24. #include <stdarg.h>
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27. #include <string.h>
  28.  
  29. #include "DeskLib:Error.h"
  30. #include "DeskLib:WimpSWIs.h"
  31. #include "DeskLib:Event.h"
  32.  
  33. extern void Error_Report(int errornum, char *report, ...)
  34. {
  35.   va_list va;
  36.   os_error    error;
  37.   error_flags eflags;
  38.  
  39.   va_start(va, report);
  40.   vsprintf(error.errmess, report, va);
  41.   va_end(va);
  42.   error.errnum = errornum;
  43.  
  44.   eflags.value = 1;
  45.   (void) Wimp_ReportError(&error, eflags.value, event_taskname);
  46. }
  47.  
  48.  
  49.  
  50. extern void Error_ReportFatal(int errornum, char *report, ...)
  51. {
  52.   va_list va;
  53.   char errmess[256];
  54.  
  55.   va_start(va, report);
  56.   vsprintf(errmess, report, va);
  57.   va_end(va);
  58.  
  59.   Error_Report(errornum,
  60.      "%s has suffered a fatal internal error (%s) and must quit immediately",
  61.      event_taskname, errmess);
  62.   exit(1);
  63. }
  64.  
  65.  
  66.  
  67. extern void Error_ReportInternal(int errornum, char *report, ...)
  68. {
  69.   va_list va;
  70.   char errmess[256];
  71.  
  72.   va_start(va, report);
  73.   vsprintf(errmess, report, va);
  74.   va_end(va);
  75.   Error_Report(errornum, errmess);
  76. }
  77.  
  78.  
  79.  
  80. extern void Error_ReportFatalInternal(int errornum, char *report, ...)
  81. {
  82.   va_list va;
  83.   char errmess[256];
  84.  
  85.   va_start(va, report);
  86.   vsprintf(errmess, report, va);
  87.   va_end(va);
  88.   Error_ReportFatal(errornum, errmess);
  89. }
  90.  
  91.  
  92.  
  93. extern BOOL Error_Check(os_error *error)
  94. {
  95.   if (error != NULL)
  96.   {
  97.     Error_Report(error->errnum, error->errmess);
  98.     return(TRUE);
  99.   }
  100.   return(FALSE);
  101. }
  102.  
  103.  
  104.  
  105. extern void Error_CheckFatal(os_error *error)
  106. {
  107.   if (error != NULL)
  108.     Error_ReportFatal(error->errnum, error->errmess);
  109. }
  110.  
  111.  
  112.  
  113. extern BOOL Error_OutOfMemory(BOOL fatal, char *place)
  114. {
  115.   if (fatal)
  116.     Error_ReportFatal(0, "Unable to get enough memory for the %s", place);
  117.   else
  118.     Error_Report(0, "Unable to get enough memory for the %s", place);
  119.  
  120.   return(FALSE);  /*  Always returns FALSE so can return FALSE from your
  121.                    *  own function at the same time as reporting the error
  122.                    */
  123. }
  124.