home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / p / popups / Docs / ExampleSrc / c / Error < prev    next >
Encoding:
Text File  |  1993-05-15  |  2.2 KB  |  85 lines

  1. /*
  2.     THIS SOURCE CODE WAS COPIED (and slightly modified) FROM:
  3.  
  4.     ####             #    #     # #
  5.     #   #            #    #       #          The FreeWare C library for 
  6.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  7.     #   # #  # #     # #  #     # #  #   ___________________________________
  8.     #   # ####  ###  ##   #     # #  #                                      
  9.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  10.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  11.     ________________________________________________________________________
  12.  
  13.     File:    Error.c
  14.     Author:  Copyright © 1992 Jason Williams
  15.     Version: 0.15 (07 Apr 1992)
  16.     Purpose: Centralised error handling functions
  17.     Mods:    7 Apr 1992 - JCW - Added Error_OutOfMemory
  18.             30 Apr 1993 - JCW - Fixed (Wimp_ReportError prototype changed)
  19. */
  20.  
  21.  
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25.  
  26. #include "DeskLib:Error.h"
  27. #include "DeskLib:WimpSWIs.h"
  28.  
  29. static char *taskname = "PopUp Server";
  30.  
  31. extern void Error_Report(int errornum, char *report)
  32. {
  33.   os_error    error;
  34.   error_flags eflags;
  35.  
  36.   sprintf(error.errmess, "%s", report);
  37.   error.errnum = errornum;
  38.  
  39.   eflags.value = 1;
  40.   (void) Wimp_ReportError(&error, eflags.value, taskname);
  41. }
  42.  
  43.  
  44.  
  45. extern void Error_ReportFatal(int errornum, char *report)
  46. {
  47.   char newreport[256];
  48.  
  49.   sprintf(newreport,
  50.      "%s has suffered a fatal internal error (%s) and must quit immediately",
  51.      taskname, report);
  52.   Error_Report(errornum, newreport);
  53.   exit(1);
  54. }
  55.  
  56.  
  57. extern void Error_ReportInternal(int errornum, char *report)
  58. {
  59.   Error_Report(errornum, report);
  60. }
  61.  
  62.  
  63. extern void Error_ReportFatalInternal(int errornum, char *report)
  64. {
  65.   Error_ReportFatal(errornum, report);
  66. }
  67.  
  68.  
  69. extern BOOL Error_OutOfMemory(BOOL fatal, char *place)
  70. {
  71.   char errmess[256];
  72.  
  73.   strcpy(errmess, "Unable to get enough memory for ");
  74.   strcat(errmess, place);
  75.  
  76.   if (fatal)
  77.     Error_ReportFatal(0, errmess);
  78.   else
  79.     Error_Report(0, errmess);
  80.  
  81.   return(FALSE);  /*  Always returns FALSE so can return FALSE from your
  82.                    *  own function at the same time as reporting the error
  83.                    */
  84. }
  85.