home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / src / runtime / errmsg.r < prev    next >
Text File  |  2000-07-29  |  4KB  |  166 lines

  1. /*
  2.  * errmsg.r -- err_msg, irunerr, drunerr
  3.  */
  4.  
  5. #ifdef PresentationManager
  6. extern MRESULT_N_EXPENTRY RuntimeErrorDlgProc(HWND, ULONG, MPARAM, MPARAM);
  7. HAB HInterpAnchorBlock;
  8. #endif                    /* PresentationManager */
  9.  
  10. #if AMIGA && __SASC
  11. extern void PostClip(char *file, int line, int number, char *text);
  12. extern void CallARexx(char *script);
  13. #endif                    /* AMIGA && __SASC */
  14.  
  15. extern struct errtab errtab[];        /* error numbers and messages */
  16.  
  17. /*
  18.  * err_msg - print run-time error message, performing trace back if required.
  19.  *  This function underlies the rtt runerr() construct.
  20.  */
  21. void err_msg(n, v)
  22. int n;
  23. dptr v;
  24. {
  25.    register struct errtab *p;
  26. #ifdef PresentationManager
  27.    HMODULE modhand;
  28. #endif
  29.  
  30.    if (n == 0) {
  31.       k_errornumber = t_errornumber;
  32.       k_errorvalue = t_errorvalue;
  33.       have_errval = t_have_val;
  34.       }
  35.    else {
  36.       k_errornumber = n;
  37.       if (v == NULL) {
  38.          k_errorvalue = nulldesc;
  39.          have_errval = 0;
  40.          }
  41.       else {
  42.          k_errorvalue = *v;
  43.          have_errval = 1;
  44.          }
  45.       }
  46.  
  47.    k_errortext = "";
  48.    for (p = errtab; p->err_no > 0; p++)
  49.       if (p->err_no == k_errornumber) {
  50.          k_errortext = p->errmsg;
  51.          break;
  52.          }
  53.  
  54.    EVVal((word)k_errornumber,E_Error);
  55.  
  56. #ifndef PresentationManager
  57.    if (pfp != NULL) {
  58.       if (IntVal(kywd_err) == 0 || !err_conv) {
  59.          fprintf(stderr, "\nRun-time error %d\n", k_errornumber);
  60. #if COMPILER
  61.          if (line_info)
  62.             fprintf(stderr, "File %s; Line %d\n", file_name, line_num);
  63. #else                    /* COMPILER */
  64.          fprintf(stderr, "File %s; Line %ld\n", findfile(ipc.opnd),
  65.             (long)findline(ipc.opnd));
  66. #endif                    /* COMPILER */
  67.          }
  68.       else {
  69.          IntVal(kywd_err)--;
  70.          return;
  71.          }
  72.       }
  73.    else
  74.       fprintf(stderr, "\nRun-time error %d in startup code\n", n);
  75.    fprintf(stderr, "%s\n", k_errortext);
  76.  
  77.    if (have_errval) {
  78.       fprintf(stderr, "offending value: ");
  79.       outimage(stderr, &k_errorvalue, 0);
  80.       putc('\n', stderr);
  81.       }
  82.  
  83.    if (!debug_info)
  84.       c_exit(EXIT_FAILURE);
  85.  
  86.    if (pfp == NULL) {        /* skip if start-up problem */
  87.       if (dodump)
  88.          abort();
  89.       c_exit(EXIT_FAILURE);
  90.       }
  91.  
  92.    fprintf(stderr, "Traceback:\n");
  93.    tracebk(pfp, glbl_argp);
  94.    fflush(stderr);
  95.  
  96.  
  97.    if (dodump)
  98.       abort();
  99.  
  100. #if AMIGA && __SASC
  101.    PostClip(findfile(ipc.opnd), findline(ipc.opnd), k_errornumber, k_errortext);
  102.    CallARexx(IconxRexx);
  103. #endif                    /* AMIGA && __SASC */
  104.  
  105.    c_exit(EXIT_FAILURE);
  106. #else                    /* PresentationManager */
  107.  
  108.   if (pfp != NULL) {
  109.      if (IntVal(kywd_err) == 0 || !err_conv) {
  110.      DosQueryModuleHandle("xiconxdl.dll",&modhand);
  111.      if (WinDlgBox(HWND_DESKTOP, HWND_DESKTOP, RuntimeErrorDlgProc, modhand,
  112.         IDD_RUNERR, NULL) == DID_ERROR) {
  113.  
  114.       WinMessageBox(HWND_DESKTOP, HWND_DESKTOP,
  115.           "An Error occurred, but the dialog cannot be loaded.\nExecution halting.",
  116.           "Icon Runtime System", 0, MB_OK|MB_ICONHAND|MB_MOVEABLE);
  117.      }
  118.      }
  119.      else {
  120.     IntVal(kywd_err)--;
  121.     return;
  122.      }
  123.   }
  124.  
  125.   if (dodump)
  126.     abort();
  127.  
  128.   c_exit(EXIT_FAILURE);
  129. #endif                    /* PresentationManager */
  130. }
  131.  
  132. /*
  133.  * irunerr - print an error message when the offending value is a C_integer
  134.  *  rather than a descriptor.
  135.  */
  136. void irunerr(n, v)
  137. int n;
  138. C_integer v;
  139.    {
  140.    t_errornumber = n;
  141.    IntVal(t_errorvalue) = v;
  142.    t_errorvalue.dword = D_Integer;
  143.    t_have_val = 1;
  144.    err_msg(0,NULL);
  145.    }
  146.  
  147. /*
  148.  * drunerr - print an error message when the offending value is a C double
  149.  *  rather than a descriptor.
  150.  */
  151. void drunerr(n, v)
  152. int n;
  153. double v;
  154.    {
  155.    union block *bp;
  156.  
  157.    bp = (union block *)alcreal(v);
  158.    if (bp != NULL) {
  159.       t_errornumber = n;
  160.       BlkLoc(t_errorvalue) = bp;
  161.       t_errorvalue.dword = D_Real;
  162.       t_have_val = 1;
  163.       }
  164.    err_msg(0,NULL);
  165.    }
  166.