home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / fp / ifp_unix.lzh / ifp / interp / error.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-05-23  |  4.9 KB  |  197 lines

  1.  
  2. /****** error.c *******************************************************/
  3. /**                                                                  **/
  4. /**                    University of Illinois                        **/
  5. /**                                                                  **/
  6. /**                Department of Computer Science                    **/
  7. /**                                                                  **/
  8. /**   Tool: IFP                         Version: 0.5                 **/
  9. /**                                                                  **/
  10. /**   Author:  Arch D. Robison          Date:   May 1, 1985          **/
  11. /**                                                                  **/
  12. /**   Revised by: Arch D. Robison       Date:  Sept 8, 1986          **/
  13. /**                                                                  **/
  14. /**   Principal Investigators: Prof. R. H. Campbell                  **/
  15. /**                            Prof. W. J. Kubitz                    **/
  16. /**                                                                  **/
  17. /**                                                                  **/
  18. /**------------------------------------------------------------------**/
  19. /**   (C) Copyright 1987  University of Illinois Board of Trustees   **/
  20. /**                       All Rights Reserved.                       **/
  21. /**********************************************************************/
  22.  
  23. /************************ Error Message Routines **********************/
  24.  
  25. #include <stdio.h>
  26. #include <ctype.h>
  27. #include "struct.h"
  28. #include "node.h"
  29. #include "umax.h"
  30. #include "inob.h"
  31.  
  32. /* Some common error messages */
  33.  
  34. char ArgNotSeq[] = "not a sequence",
  35.      ArgSeqOb [] = "must be <sequence object>",
  36.      ArgObSeq [] = "must be <object sequence>",
  37.      ArgNull  [] = "empty sequence",
  38.      ArgBottom[] = "argument is ?";         
  39.  
  40. /*
  41.  * PrintErr
  42.  *
  43.  * Check if error message should be printed.  Error messages are not printed if
  44.  * the argument is BOTTOM (in which case the error has already been noted), or
  45.  * SysStop is set (the user has interrupted execution).
  46.  *
  47.  * Input
  48.  *      InOut = argument to function                  
  49.  *
  50.  * Output
  51.  *      result = true iff error message should be printed
  52.  */
  53. boolean PrintErr (InOut)
  54.    ObjectPtr InOut;
  55.    {
  56.       return InOut->Tag != BOTTOM && !SysStop;
  57.    }
  58.  
  59. /*
  60.  * FormError
  61.  *
  62.  * Print PFO error message.
  63.  *
  64.  * Input
  65.  *    InOut = input to form
  66.  *    Message = error message
  67.  *    N = offended form's index in FormTable
  68.  *    P = form parameter list
  69.  */
  70. void FormError (InOut,Message,N,P)
  71.    ObjectPtr InOut;              
  72.    char *Message;
  73.    int N;
  74.    ListPtr P;
  75.    {
  76.       extern int TraceDepth;
  77.  
  78.       if (PrintErr (InOut)) {
  79.          LineWait ();
  80.      OutForm (FormTable[N].FormNode,P,TraceDepth);
  81.      printf (": %s\n",Message);
  82.      OutObject (InOut);
  83.      printf ("\n");
  84.          LineSignal ();
  85.       }
  86.       RepTag (InOut,BOTTOM);
  87.    }
  88.  
  89. /*
  90.  * FunError
  91.  *
  92.  * Print primitive function error.
  93.  *
  94.  * Input
  95.  *      Message = error message
  96.  *      InOut = offending object
  97.  *      ApplyFun {global} = offended function
  98.  */
  99. void FunError (Message,InOut)
  100.    char *Message;
  101.    ObjectPtr InOut;
  102.    {
  103.       if (PrintErr (InOut)) {
  104.          LineWait ();
  105.      printf ("\n");
  106.      OutNode (ApplyFun);
  107.      printf (": %s\n",Message);
  108.      OutObject (InOut);
  109.      printf ("\n");
  110.          LineSignal ();
  111.       }
  112.       RepTag (InOut,BOTTOM);
  113.    }
  114.  
  115. /*
  116.  * DefError
  117.  *
  118.  * Print definition error display.
  119.  * 
  120.  * Input
  121.  *      Caller = calling node
  122.  *      F = name of erroneous function
  123.  *      Message = error message to print 
  124.  */
  125. void DefError (Caller,F,Message)
  126.    NodePtr Caller;
  127.    ObjectPtr F;
  128.    char *Message;
  129.    {
  130.       LineWait ();
  131.       OutObject (F);
  132.       if (Caller != NULL) {
  133.      printf (" (from ");
  134.      OutNode (Caller);
  135.      printf (")");
  136.       }
  137.       printf (": %s\n",Message);
  138.       LineSignal ();
  139.    }
  140.  
  141. /*
  142.  * IntError
  143.  *
  144.  * Print internal error message.
  145.  *
  146.  * Input
  147.  *    Message = error message
  148.  */
  149. void IntError (Message)
  150.    char *Message;
  151.    {
  152.       fprintf (stderr,"\nINTERNAL ERROR (%s)\n",Message);
  153.       if (Debug) abort (); 
  154.       SysError = INTERNAL;
  155.    }
  156.  
  157. /*
  158.  * InError
  159.  *
  160.  * Print input error message.
  161.  *
  162.  * Input
  163.  *    F = input descriptor
  164.  *    Message = error message 
  165.  *    
  166.  * Output
  167.  *    result = 0
  168.  */
  169. int InError (F,Message)
  170.    InDesc *F;
  171.    char *Message;
  172.    {
  173.       char *S;
  174.  
  175.       if (F->ComLevel > 0) Message = "open comment";
  176.       printf ("Input error");
  177.  
  178.       if (F->InLineNum >= 0) {
  179.      printf (" in ");
  180.      OutNode (F->InDefMod); 
  181.      printf ("/");
  182.      if (F->InFunName != NULL) OutString (F->InFunName);
  183.      else printf ("%IMPORT");
  184.      printf (" on line %d:\n%s",F->InLineNum,F->InBuf);
  185.          if (F->InBuf[strlen (F->InBuf)-1] != '\n') printf ("\n");
  186.       } else printf ("\n");
  187.  
  188.       for (S=F->InBuf; S<F->InPtr; S++) 
  189.      printf ("%c", isspace (*S) ? *S : ' ');
  190.       printf ("^\n%s\n",Message);
  191.  
  192.       return F->ComLevel = 0;
  193.    }  
  194.  
  195. /****************************** end of error.c *******************************/
  196.  
  197.