home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / intrvews / xgrab.lha / xgrab / ui / pred.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-07  |  3.9 KB  |  202 lines

  1. /**
  2.    GRAB Graph Layout and Browser System
  3.  
  4.    Copyright (c) 1989, Tera Computer Company
  5.  **/
  6.  
  7.   /** 
  8.      pred.c -- routines for reading and executing (predicate) commands
  9.    **/
  10.  
  11. #include "malloc.h"
  12. #include <stdio.h>
  13. #include <pwd.h>
  14. #include <strings.h>
  15.  
  16. #include "attribute.h"
  17. #include "digraph.h"
  18. #include "interf.h"
  19. #include "pparse.h"
  20. #include "globals.h"
  21. #include "cursor.h"
  22.  
  23. void DoGraph();
  24. void DoLayoutGraph();
  25. PTREE *get_commands();
  26. static FILE *commfile;
  27.  
  28. int EndDoGetCommandsFromFile();    
  29.  
  30. void DoGetCommandsFromFile()
  31. {
  32.     IChangeStatusLine("Type name of file with commands", FALSE);
  33.     TakeTextInput(EndDoGetCommandsFromFile);
  34. }
  35.  
  36. static char newName[MAXSTR];        /* new file name */
  37.  
  38. #define BAD 0
  39. #define OK 1
  40.  
  41. EndDoGetCommandsFromFile()
  42. {
  43.     int status    = OK;
  44.     char *buf;
  45.     char name[MAXSTR];
  46.  
  47.     OutofText(newName);
  48.  
  49.     if (newName[0] != '\0')         /* if user entered a name */
  50.     {        
  51.     if (newName[0] == '~') 
  52.     {
  53.         status = expand_tilde(newName, name);
  54.     } 
  55.  
  56.     if (status == BAD || newName[0] != '~') 
  57.     {
  58.         strcpy(name, newName);    /* copy name of file to global var */
  59.     }
  60.     }
  61.  
  62.     buf = (char *) malloc(sizeof(char) * MAXSTR * 2);
  63.  
  64.     if (newName[0] == '\0') 
  65.     {
  66.     IChangeStatusLine("No filename; no commands read", FALSE);
  67.     }
  68.     else if (status != OK) 
  69.     {
  70.     sprintf(buf, "bad file name: \"%s\"", name);
  71.     IChangeStatusLine(buf, FALSE);
  72.     dispose(buf);
  73.     }
  74.     else
  75.     {
  76.     read_commands(name, FALSE);
  77.     }
  78. }
  79.  
  80. read_commands(name, layout)
  81. char *name;
  82. BOOL layout;    /* layout again no matter what */
  83.   /* read commands from the file name */
  84. {
  85.     char *buf;
  86.     BOOL relayout, newattr, changed, err, focus;
  87.     PTREE *ptree;
  88.     NODE *fnode;
  89.  
  90.     buf = (char *) malloc(sizeof(char) * MAXLINE);
  91.     sprintf(buf, "reading commands from \"%s\"", name);
  92.     IChangeStatusLine(buf, TRUE);
  93.     ISetCursor(waitC);
  94.  
  95.     if (*name != '\0' && (commfile = fopen(name, "r")) != NULL) 
  96.     {
  97.     init_parse(commfile);
  98.     ptree = get_commands(&err);
  99.  
  100.     if (err)
  101.     {
  102.         IChangeStatusLine("Command parse error.  Commands not executed.",
  103.                         FALSE);
  104.  
  105.         if (layout)
  106.         {
  107.             IChangeStatusLine("Laying out graph", TRUE);
  108.         DisplayReadGraph();
  109.         }
  110.     }
  111.     else
  112.     {
  113.         exec_commands(ptree, &err, &changed, &relayout, &newattr, &focus,
  114.               &fnode);
  115.         dispose_ptree(ptree);
  116.         fclose(commfile);
  117.  
  118.         if (layout && !relayout)
  119.         {
  120.             IChangeStatusLine("Laying out graph", TRUE);
  121.         DisplayReadGraph();    /* lays it out only if it has to */
  122.         changed = FALSE;
  123.         }
  124.         else if (layout && relayout)
  125.         {
  126.             IChangeStatusLine("Laying out graph", TRUE);
  127.         FixUp();        /* always lay out */
  128.         DisplayNewGraph();
  129.         relayout = FALSE;    /* don't do it again */
  130.         changed = FALSE;
  131.         }
  132.             
  133.             if (!err)
  134.         {
  135.             if (changed)
  136.             {
  137.                 ckpt_done = FALSE;
  138.                 graphChanged = TRUE;
  139.     
  140.                 if (relayout) 
  141.                 {
  142.                     IChangeStatusLine("Laying out graph", TRUE);
  143.                     relay_digraph(digraph);
  144.                 }
  145.  
  146.                 if (newattr)
  147.                 {
  148.                     DisplayNewGraph();
  149.                 }
  150.                 else
  151.                 {
  152.             StartDisp();
  153.                 }
  154.             }
  155.  
  156.         if (focus)
  157.         {
  158.             if (Displayed(fnode))
  159.             {
  160.                 FocusNode(fnode);
  161.             }
  162.         }
  163.     
  164.         if (focus && !Displayed(fnode))
  165.         {
  166.             IChangeStatusLine("Final focus command not executed; node is hidden", FALSE);
  167.         }
  168.         else
  169.         {
  170.             IChangeStatusLine("Commands executed.", FALSE);
  171.         }
  172.         }
  173.         else
  174.         {
  175.             IChangeStatusLine("Command execution error.  Commands not executed", FALSE);
  176.         }
  177.     }
  178.     }
  179.     else 
  180.     {
  181.     if (layout)
  182.     {
  183.         IChangeStatusLine("Laying out graph", TRUE);
  184.         DisplayReadGraph();
  185.     }
  186.  
  187.  
  188.         if (*name != '\0')
  189.         {
  190.         sprintf(buf, "Couldn't open %s", name);
  191.         IChangeStatusLine(buf, FALSE);
  192.         }
  193.         else
  194.         {
  195.         IChangeStatusLine("No file to read", FALSE);
  196.         }
  197.     }
  198.     
  199.     IUnsetCursor();
  200.     dispose(buf);
  201. }
  202.