#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper;

# $Id: build_map.pl 588 2010-11-18 20:09:20Z ed $
# $URL: svn+ssh://s5h.net/home/ed/services/repos/desktop/home/ed/code/perl/ipv6/build_map.pl $

my %list;

sub read_file {
	my $file = shift;
	my $last;

	open( F, "<$file" ) or die $!;

	while( my $in = <F> ) {
		if( my ($host, $network) = $in =~ /^\s*\d+\s+(\S+) \(.+\)/ ) {
			if( !defined( $last ) ) {
				$last = $host;
				next;
			}
			#print $host, "\n";
			$list{$last}{"links"}{$host} = 1;
			$last = $host;
		}
	}
	close(F);
}

sub produce_output {
	print "digraph ipv6 {\n";

	foreach my $host ( keys( %list ) ) {
		#print keys %{ $list{$host}{"links"} }, "\n";
		foreach my $link ( keys %{ $list{$host}{"links"} } ) {
			print "\t\"", $host, "\" -> \"", $link, "\"\n";
		}
	}

	print "}\n"
}

while( my $f = <STDIN> ) {
	chomp $f;

	read_file( $f );
}

produce_output();

#print Dumper( \%list );



