>From fefa71283edc0af686c4c8b237b053e77f73d5af Mon Sep 17 00:00:00 2001
From: Jannick <thirdedition@gmx.net>
Date: Sat, 27 Oct 2018 13:52:38 +0200
Subject: [PATCH 4/6] dot output: add a frame around graph together with
 information  on file path of input grammar, bison version, compilation date
 stamp.

The frame is visible in the pdf converted from the dot file.
The dot files produced directly by bison or by bison -> xml ->
xml2dot.xsl are identical.
---
 data/xslt/xml2dot.xsl | 29 ++++++++++++++++++++++-------
 src/graphviz.c        | 23 +++++++++++++++++++----
 2 files changed, 41 insertions(+), 11 deletions(-)

diff --git a/data/xslt/xml2dot.xsl b/data/xslt/xml2dot.xsl
index a46fc56..b3a8816 100644
--- a/data/xslt/xml2dot.xsl
+++ b/data/xslt/xml2dot.xsl
@@ -51,17 +51,32 @@
 
 <xsl:template match="automaton">
   <xsl:param name="filename"/>
+
   <xsl:text>digraph "</xsl:text>
   <xsl:call-template name="escape">
     <xsl:with-param name="subject" select="$filename"/>
   </xsl:call-template>
-  <xsl:text>"&#10;{
-  node [fontname = courier, shape = box, colorscheme = paired6]
-  edge [fontname = courier]
-
-</xsl:text>
-  <xsl:apply-templates select="state"/>
-  <xsl:text>}&#10;</xsl:text>
+  <xsl:text>"&#10;</xsl:text>
+  <xsl:text>{&#10;</xsl:text>
+    <!-- footer label -->
+    <xsl:text>  label="</xsl:text>
+      <xsl:value-of select="/bison-xml-report/compilation/@datestamp"/>
+    <xsl:text> / GNU Bison </xsl:text>
+        <xsl:value-of select="/bison-xml-report/@version"/>
+    <xsl:text>";  fontname = arial;  fontsize = 8;&#10;&#10;</xsl:text>
+    <xsl:text>  node [fontname = courier, shape = box, colorscheme = paired6]&#10;</xsl:text>
+    <xsl:text>  edge [fontname = courier]&#10;&#10;</xsl:text>
+    <xsl:text>  subgraph cluster_0&#10;</xsl:text>
+    <xsl:text>  {&#10;</xsl:text>
+      <!-- frame label -->
+      <xsl:text>    label="</xsl:text>
+      <xsl:call-template name="escape">
+        <xsl:with-param name="subject" select="$filename"/>
+      </xsl:call-template>
+      <xsl:text>"; fontname = arial; fontsize = 11;&#10;&#10;</xsl:text>
+      <xsl:apply-templates select="state"/>
+    <xsl:text>  }&#10;</xsl:text> <!-- close subgraph -->
+  <xsl:text>}&#10;</xsl:text> <!-- close digraph -->
 </xsl:template>
 
 <xsl:template match="automaton/state">
diff --git a/src/graphviz.c b/src/graphviz.c
index d85b23d..2045d7c 100644
--- a/src/graphviz.c
+++ b/src/graphviz.c
@@ -28,6 +28,7 @@
 #include "files.h"
 #include "gram.h"
 #include "graphviz.h"
+#include "print.h"
 #include "tables.h"
 
 /* Return an unambiguous printable representation for NAME, suitable
@@ -54,23 +55,36 @@ start_graph (FILE *fout)
            "digraph %s\n"
            "{\n",
            quote (grammar_file));
+  fprintf (fout,
+           "  label = \"%s / %s\";"
+           "  fontname = arial;"
+           "  fontsize = 8;"
+           "\n\n"
+           , datetimestamp()
+           , PACKAGE_STRING);
   fprintf (fout,
            "  node [fontname = courier, shape = box, colorscheme = paired6]\n"
            "  edge [fontname = courier]\n"
            "\n");
+  fprintf (fout,
+           "  subgraph cluster_0\n"
+           "  {\n"
+           "    label = \"%s\"; fontname = arial; fontsize = 11;\n"
+           "\n",
+           grammar_file);
 }
 
 void
 output_node (int id, char const *label, FILE *fout)
 {
-  fprintf (fout, "  %d [label=\"%s\"]\n", id, label);
+  fprintf (fout, "    %d [label=\"%s\"]\n", id, label);
 }
 
 void
 output_edge (int source, int destination, char const *label,
              char const *style, FILE *fout)
 {
-  fprintf (fout, "  %d -> %d [style=%s", source, destination, style);
+  fprintf (fout, "    %d -> %d [style=%s", source, destination, style);
   if (label)
     fprintf (fout, " label=%s", quote (label));
   fputs ("]\n", fout);
@@ -114,7 +128,7 @@ conclude_red (struct obstack *out, int source, rule_number ruleno,
          with n the source state and m the rule number. This is because we
          don't want all the reductions bearing a same rule number to point to
          the same state, since that is not the desired format. */
-      fprintf (fout, "  %d -> \"%dR%d%s\" [",
+      fprintf (fout, "    %d -> \"%dR%d%s\" [",
                source, source, ruleno, ed);
 
       /* (The lookahead tokens have been added to the beginning of the
@@ -130,7 +144,7 @@ conclude_red (struct obstack *out, int source, rule_number ruleno,
       fprintf (fout, "style=solid]\n");
 
       /* Build the associated diamond representation of the target rule. */
-      fprintf (fout, " \"%dR%d%s\" [label=\"",
+      fprintf (fout, "   \"%dR%d%s\" [label=\"",
                source, ruleno, ed);
       if (ruleno)
         fprintf (fout, "R%d", ruleno);
@@ -215,5 +229,6 @@ output_red (state const *s, reductions const *reds, FILE *fout)
 void
 finish_graph (FILE *fout)
 {
+  fputs ("  }\n", fout);
   fputs ("}\n", fout);
 }
-- 
2.19.1.windows.1

