docs: Implement our own dot->pic translator.
[sliver-openvswitch.git] / ovsdb / dot2pic
1 #! /usr/bin/perl
2
3 # Copyright (c) 2009, 2010 Nicira Networks
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at:
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 use strict;
18 use warnings;
19
20 my ($scale) = 1;
21 print ".PS\n";
22 print "linethick = 1;\n";
23 while (<>) {
24     if (/graph (\S+) (\S+) (\S+)/) {
25         $scale = $1;
26     } elsif (my ($name, $x, $y, $width, $height, $label, $style, $shape, $color, $fillcolor) = /node (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+)/) {
27         $x *= $scale;
28         $y *= $scale;
29         $width *= $scale;
30         $height *= $scale;
31         print "box at $x,$y wid $width height $height \"$name\"\n";
32     } elsif (/edge/) {
33         my (undef, $tail, $head, $n, $rest) = split(' ', $_, 5);
34         my @xy;
35         for (1...$n) {
36             my ($x, $y);
37             ($x, $y, $rest) = split(' ', $rest, 3);
38             push(@xy, [$x * $scale, $y * $scale]);
39         }
40         my ($label, $xl, $yl);
41         if (scalar(my @junk = split(' ', $rest)) > 2) {
42             if ($rest =~ s/^"([^"]*)"\s+//) {
43                 $label = $1;
44             } else {
45                 ($label, $rest) = split(' ', $rest, 2);
46             }
47             ($xl, $yl, $rest) = split(' ', $rest, 3);
48             $xl *= $scale;
49             $yl *= $scale;
50         }
51         my ($style, $color) = split(' ', $rest);
52
53         print "spline -> from $xy[0][0],$xy[0][1]";
54         for (my ($i) = 0; $i <= $#xy; $i++) {
55             print " to $xy[$i][0],$xy[$i][1]";
56         }
57         print "\n";
58
59         print "\"$label\" at $xl,$yl\n" if defined($label);
60     }
61
62 }
63 print ".PE\n";