home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine 1996 / ARCHIVE_96.iso / discs / mag_discs / volume_9 / issue_08 / toolbox / Step3 / !FormText / c / err next >
Text File  |  1995-12-05  |  2KB  |  80 lines

  1. /* !FormText.err.c */
  2. /* Error reporting */
  3.  
  4. #include <stdlib.h>
  5.  
  6. #include "wimplib.h"
  7.  
  8. #include "err.h"
  9.  
  10. /* Copies a string terminated by any ctrl char */
  11. static char *strncpycr(char *s1, const char *s2, size_t n)
  12. {
  13.   int m;
  14.   for (m=0; m<n; m++)
  15.   {
  16.     s1[m] = s2[m];
  17.     if (s1[m] < ' ')
  18.     {
  19.       s1[m] = 0;
  20.       break;
  21.     }
  22.   }
  23.   return s1;
  24. }
  25.  
  26. static char err_taskname[32] = "FormText";
  27.  
  28. void err_set_taskname(const char *name)
  29. {
  30.   strncpycr(err_taskname, name, sizeof(err_taskname));
  31. }
  32.  
  33. int err_check(const _kernel_oserror *er)
  34. {
  35.   if (!er)
  36.     return 0;
  37.   if (wimp_report_error((_kernel_oserror *) er,
  38.           Wimp_ReportError_OK|Wimp_ReportError_Cancel, err_taskname)
  39.       == Wimp_ReportError_Cancel)
  40.     exit(0);
  41.   return 1;
  42. }
  43.  
  44. void err_check_fatal(const _kernel_oserror *er)
  45. {
  46.   if (!er)
  47.     return;
  48.   wimp_report_error((_kernel_oserror *) er, Wimp_ReportError_Cancel,
  49.           err_taskname);
  50.   exit(0);
  51. }
  52.  
  53. void err_report(int num, const char *mess)
  54. {
  55.   _kernel_oserror er;
  56.   er.errnum = num;
  57.   strncpycr(er.errmess, mess, sizeof(er.errmess));
  58.   wimp_report_error(&er, Wimp_ReportError_OK, err_taskname);
  59. }
  60.  
  61. void err_complain(int num, const char *mess)
  62. {
  63.   _kernel_oserror er;
  64.   er.errnum = num;
  65.   strncpycr(er.errmess, mess, sizeof(er.errmess));
  66.   if (wimp_report_error(&er,
  67.           Wimp_ReportError_OK|Wimp_ReportError_Cancel, err_taskname)
  68.       == Wimp_ReportError_Cancel)
  69.     exit(0);
  70. }
  71.  
  72. void err_complain_fatal(int num, const char *mess)
  73. {
  74.   _kernel_oserror er;
  75.   er.errnum = num;
  76.   strncpycr(er.errmess, mess, sizeof(er.errmess));
  77.   wimp_report_error(&er, Wimp_ReportError_Cancel, err_taskname);
  78.   exit(0);
  79. }
  80.