#!/usr/bin/perl use strict (qw(vars)); use warnings; use Graph::Undirected; my $dists= Graph::Undirected->new(); my $archs= Graph::Undirected->new(); my @arch_labels; my %islandname; open PO, ">/dev/null" or die $!; sub nn_xy ($$) { return "n$_[0]x$_[1]"; } sub parse_yppedia_map () { # We don't even bother with tag soup; instead we do line-oriented parsing. while (<>) { s/\<--.*--\>//g; s/^\s*//; chomp; s/\s+$//; s/\s+/ /g; s/\<\/?(?:b|em)\>//g; s/\{\{Chart\ style\|[^{}]*\}\}//g; next unless m/\{\{/; # only interested in chart template stuff my ($x,$y, $arch,$island,$solid,$dirn); my $nn= sub { return nn_xy($x,$y) }; if (($x,$y,$arch) = m/^\{\{ chart\ label \|(\d+)\|(\d+)\| .* \'\[\[ [^][\']* \| (\S+)\ archipelago \]\]\'*\}\}$/xi) { printf PO "%d,%d arch %s\n", $x,$y,$arch; push @arch_labels, [ $x,$y,$arch ]; } elsif (($x,$y,$island) = m/^\{\{ chart\ island\ icon \|(\d+)\|(\d+)\| (\S.*\S) \| .*\}\}$/xi) { $islandname{$nn->()}= $island; $dists->add_vertex($nn->()); $archs->add_vertex($nn->()); printf PO "%d,%d island %s\n", $x,$y,$island; } elsif (($solid,$x,$y,$dirn) = m/^\{\{ chart\ league((?:\ solid)?) \|(\d+)\|(\d+)\| ([-\/\\o]) \| .*\}\}$/xi) { next if $dirn eq 'o'; my ($bx,$by) = ($x,$y); if ($dirn eq '-') { $bx+=2; } elsif ($dirn eq '\\') { $bx++; $by++; } elsif ($dirn eq '/') { $bx--; $by++; } else { die; } $dists->add_edge($nn->(), nn_xy($bx,$by)); $archs->add_edge($nn->(), nn_xy($bx,$by)) if $solid; printf PO "%d,%d league %s %s \n", $x,$y, $solid?'solid':'dotted', $dirn; } elsif ( m/^\{\{ chart\ head \}\}$/xi ) { next; } else { warn "line $.: ignoring incomprehensible: $_\n"; } } } parse_yppedia_map();