3 # Created from gengraph.pl by Thomas Wolmer
6 # This program makes assumptions about the input XML file:
8 # * the title of the numbered sections is a simple number
9 # * the title appears on a line by itself
10 # * the numbered sections are followed by sections of class "backmatter"
12 ################################################################################
16 die( "gbtodot inputXMLfile outputDOTfile\n" ) if( $#ARGV + 1 < 2 );
18 my $infile = shift @ARGV;
19 my $outfile = shift @ARGV;
20 my $baseURL = shift @ARGV;
22 die( "Input file and output file the same: \"$infile\" \"$outfile\"\n" ) if( $infile eq $outfile );
24 open( INFILE, "<$infile" ) or die( "Cannot read $infile: $!\n" );
25 my @inlines = <INFILE>;
28 my $graphName = $infile;
29 $graphName =~ s/\.xml$//;
31 open( OUTFILE, ">$outfile" ) or die( "Cannot write to $outfile: $!\n" );
32 print( OUTFILE "digraph theGraph {\n nodesep=.1; \n ranksep=.2;\n ratio=auto;\n");
33 print( OUTFILE " node [height=.3,width=.3,shape=ellipse,fixedsize=true,fontname=Arial,fontsize=8]\n");
34 print( OUTFILE " edge [arrowsize=.7]\n");
43 foreach my $line (@inlines) {
44 if( $line =~ m|class="backmatter"| ) {
47 if( $line =~ m|<title>(\d+)</title>| ) {
48 # Visualize the previous section's attributes
50 push( @attributes, ( "color=firebrick1", "style=filled" ) );
52 # Assume that small and large illustrations never appear together
54 push( @attributes, ( "fontcolor=DarkGreen", "label=\"s$smallIll\\n$section\"" ) );
57 push( @attributes, ( "fontcolor=blue", "label=\"i$ill\\n$section\"" ) );
59 if( defined( $baseURL ) ) {
60 push( @attributes, ( "URL=\"${baseURL}sect${section}.htm\"", "" ) );
63 # Print out extra section data if needed
64 if( $#attributes > 0 && $section != -1 ) {
65 # print( OUTFILE " $section [", join( ',', @attributes ), "];\n");
66 printf( OUTFILE " %03d [%s];\n", $section, join( ',', @attributes ) );
74 elsif( $line =~ m|<choice\sidref="sect(\d+)">| ) {
75 # print( OUTFILE " $section -> $1;\n" );
76 printf( OUTFILE " %03d -> %03d;\n", $section, $1 );
78 elsif( $line =~ m|idref="sect(\d+)"| && $section != -1 ) { # misc links (should be pruned later)
79 printf( OUTFILE " %03d -> %03d [style=dotted,dir=none];\n", $1, $section );
82 if( $line =~ m|<combat>| ) {
86 if( $line =~ m|src=\"ill(\d+)| ) {
90 if( $line =~ m/src=\"s(mall|ect)(\d+)/ ) {
95 print( OUTFILE "}\n" );