home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 626a.lha / GUISpell_v1.0 / error.c next >
C/C++ Source or Header  |  1992-03-27  |  1KB  |  68 lines

  1. #error By license you aren't permitted to compile this.  Read GUISpell.doc.
  2. #include <stdlib.h>
  3. #include <stdarg.h>
  4. #include <string.h>
  5. #include <proto/dos.h>
  6. #include "error.h"
  7.  
  8. static void (*CleanupCode)(void);
  9.  
  10. static void PrintMessage (char **code)
  11. {
  12.   struct DosLibrary *DOSBase = (struct DosLibrary *) OpenLibrary (DOSNAME, 0);
  13.  
  14.   if (DOSBase)
  15.     {
  16.       if (Output ())
  17.         {
  18.       va_list ap;
  19.       char *string;
  20.       int number;
  21.       char buffer[(sizeof (int)) * 4];
  22.       int i;
  23.  
  24.       va_start (ap, *code);
  25.       while (**code)
  26.             switch (**code)
  27.           {
  28.           case 'd':
  29.             number = va_arg (ap, int);
  30.             buffer[15] = '\0';
  31.             buffer[14] = '0';
  32.             for (i = 14; number; i--)
  33.               buffer[i] = number % 10 + '0', number /= 10;
  34.             string = &buffer[++i];
  35.             goto write_error;
  36.           case 's':
  37.             string = va_arg (ap, char *);
  38.           write_error:
  39.                 Write (Output (), string, strlen (string));
  40.             (*code)++;
  41.             break;
  42.           default:
  43.             **code = '\0';
  44.           }
  45.           va_end (ap);
  46.         }
  47.       CloseLibrary ((struct Library *) DOSBase);
  48.     }
  49. }
  50.  
  51. void Warning (char *code, ...)
  52. {
  53.   PrintMessage (&code);
  54. }
  55.  
  56. void Error (char *code, ...)
  57. {
  58.   PrintMessage (&code);
  59.   if (CleanupCode)
  60.     (*CleanupCode) ();
  61.   exit (EXIT_FAILURE);
  62. }
  63.  
  64. void OnError (void (*f)(void))
  65. {
  66.   CleanupCode = f;
  67. }
  68.