home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / haswinlib / c / error < prev    next >
Encoding:
Text File  |  1991-02-04  |  3.4 KB  |  131 lines

  1. /* > $.CLIB.C.error
  2.  *
  3.  *      HASWIN Graphics Library
  4.  *     =========================
  5.  *
  6.  *      Copyright (C) H.A.Shaw 1990.
  7.  *              Howard A. Shaw.
  8.  *              The Unit for Space Sciences,
  9.  *              Room 165,
  10.  *              Physics Building,
  11.  *              University of Kent at Canterbury.
  12.  *              Canterbury.
  13.  *              Kent.  CT2 7NJ
  14.  *      You may use and distribute this code freely, however please leave
  15.  *      it alone.  If you find bugs (and there will be many) please contact
  16.  *      me and the master source can be modified.  If you keep me informed
  17.  *      of who you give copies of this to then I can get release upgrades
  18.  *      to them.
  19.  *
  20.  *     error control routines.
  21.  */
  22. #include "includes.h"
  23. #include <signal.h>
  24. #include <stdarg.h>
  25.  
  26. int haswin_initerrorhandlers() {
  27.  
  28.         haswin_flags |= HASWIN_FLAGS_EHANDLER;
  29.         return(HASWIN_TRUE);
  30. }
  31.  
  32. void haswin_restoreerrorhandlers() {
  33.  
  34.         haswin_flags &= ~HASWIN_FLAGS_EHANDLER;
  35.         return;
  36. }
  37.  
  38. int haswin_ok_cancel(char *msg) {
  39.         static char       *error = 0;
  40.         int               reply;
  41.         _kernel_swi_regs  regs, ans;
  42.  
  43.         /* malloc space for the error message */
  44.         error = haswin_realloc(error, asciilen(msg)+5, "haswin_ok_cancel", "error");
  45.         strcpy(&(error[4]), msg);
  46.         *((int *)error) = 0;
  47.         regs.r[0] = (int)error;
  48.         regs.r[1] = 3;
  49.         regs.r[2] = (int)haswin_gettaskname();
  50.         _kernel_swi(HASWIN_Report_error|SWI_X, ®s, &ans);
  51.         reply = ans.r[1];
  52.         return(reply);
  53. }
  54.  
  55. /*
  56.  *      perform printf() in the errorbox window.
  57.  *
  58.  *      The final string is passed to SWI(HASWIN_Report_error) for display.
  59.  */
  60. int haswin_ok_cancelprintf(char *fmt, ...) {
  61.  
  62.         va_list                 ap;
  63.         char                    str[1024];
  64.         int                     len;
  65.  
  66.         if (!fmt)
  67.                 return(HASWIN_FALSE);
  68.         va_start(ap, fmt);
  69.         len = vsprintf(str, fmt, ap);
  70.         haswin_ok_cancel(str);
  71.         va_end(ap);
  72.         return(len);
  73. }
  74.  
  75. void haswin_errorbox(char *msg) {
  76.  
  77.         static  char      error[1024];
  78.         _kernel_swi_regs  regs, ans;
  79.  
  80.         strncpy(&(error[4]), msg, 1000);
  81.         *((int *)error) = 0;
  82.         regs.r[0] = (int)error;
  83.         regs.r[1] = 0x00000011;
  84.         regs.r[2] = (int)haswin_gettaskname();
  85.         _kernel_swi(HASWIN_Report_error|SWI_X, ®s, &ans);
  86. }
  87.  
  88. /*
  89.  *      perform printf() in the errorbox window.
  90.  *
  91.  *      The final string is passed to SWI(HASWIN_Report_error) for display.
  92.  */
  93. int haswin_errorprintf(char *fmt, ...) {
  94.  
  95.         va_list                 ap;
  96.         char                    str[1024];
  97.         int                     len;
  98.  
  99.         if (!fmt)
  100.                 return(HASWIN_FALSE);
  101.         va_start(ap, fmt);
  102.         len = vsprintf(str, fmt, ap);
  103.         haswin_errorbox(str);
  104.         va_end(ap);
  105.         return(len);
  106. }
  107.  
  108. void haswin_internalerror(char *msg) {
  109.  
  110.         if (haswin_flags & HASWIN_FLAGS_VERBOSE)
  111.                 haswin_errorbox(msg);
  112.         return;
  113. }
  114.  
  115. int haswin_interrorprintf(char *fmt, ...) {
  116.  
  117.         va_list                 ap;
  118.         char                    str[1024];
  119.         int                     len;
  120.  
  121.         len = HASWIN_FALSE;
  122.         va_start(ap, fmt);
  123.         if ((fmt) && (haswin_flags & HASWIN_FLAGS_VERBOSE)) {
  124.                 len=vsprintf(str, fmt, ap);
  125.                 haswin_errorbox(str);
  126.         }
  127.         va_end(ap);
  128.         return(len);
  129. }
  130.  
  131.