Update html-plain writer.
[docutils.git] / sandbox / rst2graph / sortDot.pl
blob85ea80cce2558edcc69faf2ed51539d3bb1d0aaf
1 #!/usr/bin/perl -w
3 # Sort the statements of a dot file produced by `rst2gv` so the sequence of
4 # lines is stable.
6 my @gather;
8 sub add($) {
9 my( $ln ) = @_;
11 push(@gather, $ln);
14 sub out(@) {
15 my( @lns ) = @_;
17 print(@lns);
20 sub flush(@) {
21 my( @sfx ) = @_;
23 out(sort(@gather), @sfx);
24 @gather = ( );
27 while(defined($_ = <>)) {
28 my $in;
29 if($in = /\{\s*$/ .. /\}\s*$/) {
30 if($in == 1)
31 { out($_); }
32 elsif($in =~ /E/)
33 { flush($_); }
34 elsif(/\{\s*$/)
35 { die("Embedded graphs are not supported: $_"); }
36 elsif(/\\$/)
37 { die("Continuation lines are not supported: $_"); }
38 elsif(/\/\*/ || /\/\// || /#/)
39 { die("Comments are not supported: $_"); }
40 elsif(/;\s*$/) { # A statement
41 if(/^\s*(graph|node|edge)/) # An attribute statement
42 { flush($_); }
43 # Note: The order of nodes output by `pygraphviz` is random. This changes
44 # the semantic of the graph but unfortunately can not be controlled.
45 else
46 { add($_); }
48 else
49 { die("Unsupported line ending: $_"); }
51 else
52 { out($_); }