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

  1.  
  2. /****** outfun.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: June 30, 1985          **/
  11. /**                                                                  **/
  12. /**   Revised by: Arch D. Robison       Date:  Dec 12, 1985          **/
  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.  
  24. #include <stdio.h>
  25. #include <ctype.h>
  26. #include "struct.h"
  27. #include "node.h"
  28.  
  29. /*
  30.  * OutLongNode - internal to OutNode
  31.  */
  32. private void OutLongNode (N)
  33.    register NodePtr N;
  34.    {
  35.       if (N->NodeParent != NULL) {
  36.      OutLongNode (N->NodeParent);
  37.      printf ("/");
  38.      OutString (N->NodeName);
  39.       }
  40.    }
  41.  
  42. /*
  43.  * OutNode
  44.  *
  45.  * Output node N in UNIX path format.  
  46.  * Abbreviate if it is in the current directory.
  47.  */
  48. void OutNode (N)
  49.    register NodePtr N;
  50.    {
  51.       extern boolean LongPathFlag;
  52.  
  53.       if (N == NULL) printf ("(NULL NODE)");
  54.       else {
  55.          register NodePtr M;
  56.      if (!LongPathFlag && NULL != (M = FindNode (CurWorkDir,N->NodeName)) &&
  57.                   (M->NodeType == IMPORT || M->NodeType == DEF)) 
  58.         OutString (N->NodeName);
  59.      else OutLongNode (N);
  60.       }
  61.    }
  62.  
  63. /*
  64.  * OutForm
  65.  * 
  66.  * Print a functional form and its parameters.
  67.  *
  68.  * Input
  69.  *      N = pointer to form node
  70.  *      P = pointer to parameter list
  71.  *      Depth = depth to print function (ellipses used at that depth)
  72.  */
  73. void OutForm (N,P,Depth)
  74.    register NodePtr N;
  75.    ListPtr P;
  76.    int Depth;
  77.    {
  78.       long L;
  79.       register FormEntry *T;
  80.  
  81.       L = ListLength (P);
  82.  
  83.       for (T=FormTable; T<ArrayEnd(FormTable); T++) 
  84.      if (T->FormNode == N) {
  85.         switch (T-FormTable) {
  86.  
  87.            case NODE_Comp:
  88.           while (P!=NULL) {
  89.             OutFun (&P->Val,Depth);
  90.             if (NULL != (P=P->Next)) printf ("|");
  91.           }
  92.           break;
  93.  
  94.            case NODE_Cons:
  95.           printf ("[");
  96.           while (P!=NULL) {
  97.              OutFun (&P->Val,Depth);
  98.              if (NULL != (P=P->Next)) printf (",");       
  99.           }
  100.           printf ("]");
  101.           break;
  102.  
  103.            case NODE_RInsert:
  104.            case NODE_Filter:
  105.            case NODE_Each:
  106.           printf ("%s ",T->FormInPrefix); 
  107.           OutFun (&P->Val,Depth);
  108.           printf (" END");
  109.           break;
  110.  
  111.            case NODE_If:
  112.           printf ("IF ");    OutFun (&P->Val,Depth);
  113.           printf (" THEN "); OutFun (&(P=P->Next)->Val,Depth);
  114.           printf (" ELSE "); OutFun (&P->Next->Val,Depth);
  115.           printf (" END"); 
  116.           break;
  117.    
  118.            case NODE_C: 
  119.           if (!L) {
  120.              printf ("?");
  121.              break;
  122.           } 
  123.           /* else drop through */
  124. #if FETCH
  125.            case NODE_Fetch:
  126. #endif
  127.            case NODE_Out: 
  128.           printf ("%s",T->FormInPrefix); OutObject (&P->Val);
  129.           break;
  130.  
  131.            case NODE_Sel:
  132.           if (P->Val.Int >= 0) printf ("%d",P->Val.Int);
  133.           else printf ("%dr",-P->Val.Int);
  134.           break;
  135.  
  136.            case NODE_While:
  137.           printf ("WHILE "); OutFun (&P->Val,Depth);
  138.           printf (" DO ");   OutFun (&P->Next->Val,Depth);
  139.           printf (" END");
  140.           break;
  141. #if XDEF
  142.            case NODE_XDef: {
  143.           extern void OutLHS ();
  144.           printf ("{");    OutLHS (&P->Val);
  145.           printf (" := "); OutFun (&P->Next->Val,Depth); 
  146.           printf ("} ");
  147.           OutFun (&P->Next->Next->Val,Depth); 
  148.           break;
  149.            }
  150. #endif
  151.         }
  152.         return;
  153.      }
  154.  
  155.       printf ("(");
  156.       OutNode (N); 
  157.       for (; P != NULL; P=P->Next) {    
  158.      printf (" ");
  159.      OutObject (&P->Val);
  160.       }
  161.       printf (")");
  162.    }
  163.  
  164.  
  165. /*
  166.  * OutFun
  167.  *
  168.  * Print function *F. *F may be linked if it was unlinked.
  169.  *
  170.  * The possible representations for the function are described
  171.  * in the comments for "Apply" in apply.c.
  172.  *
  173.  * Input
  174.  *      *F = function
  175.  *      Depth = depth to print function, 0 = "..."
  176.  *
  177.  * Output
  178.  *      *F = may be linked function
  179.  */
  180. void OutFun (F,Depth)
  181.    register ObjectPtr F;
  182.    int Depth;
  183.    {
  184.       register ListPtr P;
  185.  
  186.       if (SysStop > 1) return;
  187.  
  188.       if (F == NULL) printf ("(null)");          /* Internal error */
  189.       else if (--Depth < 0) printf ("..");
  190.       else 
  191.  
  192.      switch (F->Tag) {
  193.  
  194.         default:
  195.            printf ("(tag = %d)",F->Tag);     /* Internal error */
  196.            break;
  197.  
  198.         case LIST:
  199.            P = F->List;
  200.            if (P == NULL) printf ("()");
  201.            else
  202.  
  203.           switch (P->Val.Tag) {
  204.     
  205.              case LIST:   /* unlinked form */
  206.             LinkPath (&P->Val);
  207.             if (!ObIsDefNode (&P->Val)) {
  208.                printf ("(");
  209.                OutObject (&P->Val);
  210.                for (; P != NULL; P=P->Next) {    
  211.                   printf (" ");
  212.                   OutObject (&P->Val);
  213.                }
  214.                printf (")");
  215.                return;
  216.             } /* else drop down to case NODE */
  217.  
  218.              case NODE:   /* linked form */
  219.             OutForm (P->Val.Node,P->Next,Depth);
  220.             return;
  221.  
  222.              case STRING:
  223.             LinkPath (F);
  224.             if (F->Tag == NODE) break; /* drop down to case NODE */
  225.  
  226.              default: /* unlinked function or internal error */
  227.             for (; P!=NULL; P=P->Next) {
  228.                printf ("/");
  229.                OutObject (&P->Val);
  230.             }
  231.             return;
  232.           }
  233.  
  234.         case NODE:
  235.            OutNode (F->Node);
  236.            break;
  237.  
  238.         case STRING:
  239.            OutString (F->String);
  240.            break;
  241.      }
  242.    }
  243.  
  244.  
  245. /******************************* end of outfun.c ******************************/
  246.  
  247.