home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / math / pac / error.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-05  |  4.0 KB  |  148 lines

  1. /* error.c */
  2. /**********************************************************************
  3. *    File Name     : error.c
  4. *    Function      : handling of error messages
  5. *    Author        : Istvan Mohos, 1987
  6. ***********************************************************************/
  7.  
  8. #include "defs.h"
  9.  
  10. e_syntax()
  11. {
  12.     static char *fid = "e_syntax";
  13.  
  14.     _TR
  15.     if (strncmp(Mainbuf, "syntax error", 12) == 0) {
  16.         if (write(A_write[1], "0\n", 2) == -1)
  17.             fatal("error recovery to main pipe write");
  18.         /* read back a zero, so next error won't hang bc pipe */
  19.         wait_main_pipe();
  20.         standout();
  21.         move(MSG, MSGLEFT);
  22.         printw("bc: syntax error                 ");
  23.         if (Hc != -1 && Hf == FVER)
  24.             if ((write(Hc, "ERROR: syntax\n", 14)) != 14)
  25.                 fatal("error recovery hardcopy write");
  26.         standend();
  27.         Bc_error = E_SYNTAX;
  28.     }
  29. TR_
  30. }
  31.  
  32. e_bcexec()
  33. {
  34.     static char *fid = "e_bcexec";
  35.  
  36.     _TR
  37.     if (strncmp(Mainbuf, "save:args", 9) == 0) {
  38.         if (write(A_write[1], "0\n", 2) == -1)
  39.             fatal("error recovery to main pipe write");
  40.         /* read back a zero, so next error won't hang bc pipe */
  41.         wait_main_pipe();
  42.         standout();
  43.         move(MSG, MSGLEFT);
  44.         printw("bc: bc calculator failure        ");
  45.         if (Hc != -1 && Hf == FVER)
  46.             if ((write(Hc, "ERROR: bcexec\n", 14)) != 14)
  47.                 fatal("error recovery hardcopy write");
  48.         standend();
  49.         Bc_error = E_BCEXEC;
  50.     }
  51. TR_
  52. }
  53.  
  54. e_divby0()
  55. {
  56.     static char *fid = "e_divby0";
  57.  
  58.     _TR
  59.     if (strncmp(Mainbuf, "divide by 0", 11) == 0) {
  60.         Mainbuf[0] = '0';
  61.         Mainbuf[1] = '\0';
  62.         standout();
  63.         move(MSG, MSGLEFT);
  64.         printw("bc: divide by 0 error            ");
  65.         if (Hc != -1 && Hf == FVER)
  66.             if ((write(Hc, "ERROR: divide by 0\n", 19)) != 19)
  67.                 fatal("divby0 hardcopy write");
  68.         standend();
  69.         Bc_error = E_DIVBY0;
  70.     }
  71. TR_
  72. }
  73.  
  74. e_exponent()
  75. {
  76.     static char *fid = "e_exponent";
  77.  
  78.     _TR
  79.     if (strncmp(Mainbuf, "exp not an integer", 18) == 0) {
  80.         Mainbuf[0] = '0';
  81.         Mainbuf[1] = '\0';
  82.         standout();
  83.         move(MSG, MSGLEFT);
  84.         printw("bc: non-integer exponent error   ");
  85.         if (Hc != -1 && Hf == FVER)
  86.             if ((write(Hc, "ERROR: exponent not integer\n", 28)) != 28)
  87.                 fatal("non-int exponent hardcopy write");
  88.         standend();
  89.         Bc_error = E_EXPONENT;
  90.     }
  91.     else if (strncmp(Mainbuf, "exp too big", 11) == 0) {
  92.         if (write(A_write[1], "0\n", 2) == -1)
  93.             fatal("exp2big main pipe write");
  94.         /* read back a zero, so next error won't hang bc pipe */
  95.         wait_main_pipe();
  96.         Mainbuf[0] = '0';
  97.         Mainbuf[1] = '\0';
  98.         standout();
  99.         move(MSG, MSGLEFT);
  100.         printw("bc: exponent too big error       ");
  101.         if (Hc != -1 && Hf == FVER)
  102.             if ((write(Hc, "ERROR: exponent too big\n", 24)) !=  24)
  103.                 fatal("exp2big hardcopy write");
  104.         standend();
  105.         Bc_error = E_EXPONENT;
  106.     }
  107. TR_
  108. }
  109.  
  110. e_overflow()
  111. {
  112.     static char *fid = "e_overflow";
  113.  
  114.     _TR
  115.     if (Has_dp == FALSE) { /* don't really care if some digits beyond
  116.                               the dp fall off, in this case */
  117.         standout();
  118.         move(MSG, MSGLEFT);
  119.         printw(" panel overflow: 32 digits max.  ");
  120.         if (Hc != -1 && Hf == FVER)
  121.             if ((write(Hc, "ERROR: overflow\n", 16)) !=  16)
  122.                 fatal("overflow hardcopy write");
  123.         standend();
  124.         Bc_error = E_OVERFLOW;
  125.     }
  126. TR_
  127. }
  128.  
  129. pac_err(message)
  130. char *message;
  131.     char msg[35];
  132.     static char *fid = "pac_err";
  133.  
  134.     _TR
  135.     strcpy(msg, Sp34); 
  136.     if (strlen(message) > 22)
  137.         *(message + 22) = '\0';
  138.     sprintf(msg, "pac error: %-*s", 22, message);
  139.     standout();
  140.     move(MSG, MSGLEFT);
  141.     printw(msg);
  142.     standend();
  143.     pfresh();
  144. TR_
  145. }
  146.  
  147.