/[bison]/bison/src/print_graph.c
ViewVC logotype

Diff of /bison/src/print_graph.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by marc, Wed Aug 8 20:31:21 2001 UTC revision 1.7 by akim, Thu Oct 4 14:55:20 2001 UTC
# Line 19  Line 19 
19     Boston, MA 02111-1307, USA.  */     Boston, MA 02111-1307, USA.  */
20    
21  #include "system.h"  #include "system.h"
 #include "xalloc.h"  
22  #include "files.h"  #include "files.h"
23  #include "gram.h"  #include "gram.h"
24  #include "LR0.h"  #include "LR0.h"
# Line 35  Line 34 
34  #include "quotearg.h"  #include "quotearg.h"
35    
36  static graph_t graph;  static graph_t graph;
37    static FILE *fgraph = NULL;
38    
39  static unsigned node_output_size = 0;  static size_t node_output_size = 0;
40    
41  /* Return an unambiguous printable representated, allocated in slot 0,  /* Return an unambiguous printable representated, allocated in slot 0,
42     for NAME, suitable for C strings.  */     for NAME, suitable for C strings.  */
# Line 136  print_actions (int state, const char *no Line 136  print_actions (int state, const char *no
136    
137              if (state > state1)              if (state > state1)
138                edge.type = back_edge;                edge.type = back_edge;
139              open_edge (&edge, &graph_obstack);              open_edge (&edge, fgraph);
140              /* The edge source is the current node.  */              /* The edge source is the current node.  */
141              edge.sourcename = node_name;              edge.sourcename = node_name;
142              sprintf (buff, "%d", state1);              sprintf (buff, "%d", state1);
# Line 145  print_actions (int state, const char *no Line 145  print_actions (int state, const char *no
145              /* FIXME: Be aware that quote uses static memory.  The string              /* FIXME: Be aware that quote uses static memory.  The string
146                 must be output immediately (which is the case here). */                 must be output immediately (which is the case here). */
147              edge.label = tags[symbol] ? quote (tags[symbol]) : NULL;              edge.label = tags[symbol] ? quote (tags[symbol]) : NULL;
148              output_edge (&edge, &graph_obstack);              output_edge (&edge, fgraph);
149              close_edge (&graph_obstack);              close_edge (fgraph);
150            }            }
151          }          }
152      }      }
# Line 198  print_actions (int state, const char *no Line 198  print_actions (int state, const char *no
198            symbol = accessing_symbol[state1];            symbol = accessing_symbol[state1];
199    
200            new_edge (&edge);            new_edge (&edge);
201            open_edge (&edge, &graph_obstack);            open_edge (&edge, fgraph);
202            edge.sourcename = node_name;            edge.sourcename = node_name;
203            sprintf (buff, "%d", state1);            sprintf (buff, "%d", state1);
204            edge.targetname = buff;            edge.targetname = buff;
205            edge.color = red;            edge.color = red;
206            edge.label = tags[symbol] ? quote (tags[symbol]) : NULL;            edge.label = tags[symbol] ? quote (tags[symbol]) : NULL;
207            output_edge (&edge, &graph_obstack);            output_edge (&edge, fgraph);
208            close_edge (&graph_obstack);            close_edge (fgraph);
209          }          }
210      }      }
211  }  }
# Line 223  print_state (int state) Line 223  print_state (int state)
223    new_node (&node);     /* Set node attributs default value.  */    new_node (&node);     /* Set node attributs default value.  */
224    sprintf (name, "%d", state);    sprintf (name, "%d", state);
225    node.title = name;    /* Give a name to the node.  */    node.title = name;    /* Give a name to the node.  */
   open_node (&node_obstack);  
   /* Output a VCG formatted attributs list.  */  
   output_node (&node, &node_obstack);  
226        
227    {    {
228      /* Here we begin to compute the node label. */        /* Here we begin to compute the node label. */  
# Line 241  print_state (int state) Line 238  print_state (int state)
238      print_actions (state, node.title, &node_obstack);      print_actions (state, node.title, &node_obstack);
239            
240      obstack_sgrow (&node_obstack, "\"\n");              /* Close Label.  */      obstack_sgrow (&node_obstack, "\"\n");              /* Close Label.  */
241          }    
242      close_node (&node_obstack);  
243    }    open_node (fgraph);
244        /* Output a VCG formatted attributs list.  */
245    /* `obstack_cat' NODE_OBSTACK to GRAPH_OBSTACK.  */    output_node (&node, fgraph);
246    obstack_grow (&graph_obstack,    /* Save the node label.  */
247                  obstack_base (&node_obstack),    fwrite (obstack_base (&node_obstack),
248                  obstack_object_size (&node_obstack));            obstack_object_size (&node_obstack), 1, fgraph);
249    obstack_finish (&node_obstack);    close_node (fgraph);
250    
251      obstack_free (&node_obstack, 0);
252  }  }
253    
254    
# Line 257  void Line 256  void
256  print_graph (void)  print_graph (void)
257  {  {
258    int i;    int i;
259      
260    if (!graph_flag)    if (!graph_flag)
261      return;      return;
262    
263      /* Output file.  */
264      fgraph = xfopen (spec_graph_file, "w");
265    
266    new_graph (&graph);    new_graph (&graph);
267    
268  #if 0  #if 0
# Line 268  print_graph (void) Line 271  print_graph (void)
271  #endif  #endif
272    
273    graph.display_edge_labels = yes;    graph.display_edge_labels = yes;
274    graph.layoutalgorithm = 0;    graph.layoutalgorithm = normal;
275    
276    graph.port_sharing = no;    graph.port_sharing = no;
277    graph.finetuning = yes;    graph.finetuning = yes;
# Line 279  print_graph (void) Line 282  print_graph (void)
282    graph.crossing_weight = median;    graph.crossing_weight = median;
283    
284    /* Output graph options. */    /* Output graph options. */
285    open_graph (&graph_obstack);    open_graph (fgraph);
286    output_graph (&graph, &graph_obstack);    output_graph (&graph, fgraph);
287    
288    for (i = 0; i < nstates; i++)    for (i = 0; i < nstates; i++)
289      /* Output nodes & edges. */      /* Output nodes & edges. */
290      print_state (i);      print_state (i);
291    
292    /* Close graph. */    /* Close graph. */
293    close_graph (&graph, &graph_obstack);    close_graph (&graph, fgraph);
294      xfclose (fgraph);
295  }  }

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26