summaryrefslogtreecommitdiff
path: root/ovsdb/dot2pic
blob: d682be5f96107c4178a6f600f685c3a1dd8cb1fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#! /usr/bin/perl

# Copyright (c) 2009, 2010, 2011, 2013 Nicira, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

use strict;
use warnings;

use Getopt::Long;

my $font_scale = 0;
GetOptions("f=i" => \$font_scale) || exit 1;

my ($scale) = 1;
printf ".ps %+d\n", -$font_scale if $font_scale;
print ".PS\n";
print "linethick = 1;\n";
while (<>) {
    if (/^graph/) {
        (undef, $scale) = split;
    } elsif (/^node/) {
        my (undef, $name, $x, $y, $width, $height, $label, $style, $shape, $color, $fillcolor) = split;
        $x *= $scale;
        $y *= $scale;
        $width *= $scale;
        $height *= $scale;
        print "linethick = ", ($style eq 'bold' ? 0.5 : 1.0), ";\n";
        print "box at $x,$y wid $width height $height \"$name\"\n";
        if ($style eq 'bold') {
            my $inset = 2.0 / 72.0;
            $width -= $inset * 2;
            $height -= $inset * 2;
            print "box at $x,$y wid $width height $height\n";
        }
    } elsif (/edge/) {
        my (undef, $tail, $head, $n, $rest) = split(' ', $_, 5);
        my @xy;
        for (1...$n) {
            my ($x, $y);
            ($x, $y, $rest) = split(' ', $rest, 3);
            push(@xy, [$x * $scale, $y * $scale]);
        }
        my ($label, $xl, $yl);
        if (scalar(my @junk = split(' ', $rest)) > 2) {
            if ($rest =~ s/^"([^"]*)"\s+//) {
                $label = $1;
            } else {
                ($label, $rest) = split(' ', $rest, 2);
            }
            ($xl, $yl, $rest) = split(' ', $rest, 3);
            $xl *= $scale;
            $yl *= $scale;
        }
        my ($style, $color) = split(' ', $rest);

        print "linethick = ", ($style eq 'dotted' ? 0.5 : 1), ";\n";

        print "spline -> from $xy[0][0],$xy[0][1]";
        for (my ($i) = 0; $i <= $#xy; $i++) {
            print " to $xy[$i][0],$xy[$i][1]";
        }
        print "\n";

        print "\"$label\" at $xl,$yl\n" if defined($label);
    }

}
printf ".ps %+d\n", $font_scale if $font_scale;
print ".PE\n";