-sub yppedia_chart_parse () {
- # 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 DEBUG "%2d,%-2d arch %s\n", $x,$y,$arch;
- push @wiarchlabels, [ $x,$y,$arch ];
- } elsif (($x,$y,$island) =
- m/^\{\{ chart\ island\ icon \|(\d+)\|(\d+)\|
- ([^| ][^|]*[^| ]) \| .*\}\}$/xi) {
- my $n= $nn->();
- $wiisland2node{$island}= $n;
- $winode2island{$n}= $island;
- $widists->add_vertex($n);
- $wiarchs->add_vertex($n);
- printf DEBUG "%2d,%-2d 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 '/') { $x++; $by++; }
- else { die; }
-
- my $nb= nn_xy($bx,$by);
- $widists->add_weighted_edge($nn->(), $nb, 1);
- $wiarchs->add_edge($nn->(), $nb) if $solid;
- $wiarchs->add_edge($nn->(), $nb) if $solid;
-
- printf DEBUG "%2d,%-2d league %-6s %s %s\n", $x,$y,
- $solid?'solid':'dotted', $dirn, $nb;
- } elsif (
- m/^\{\{ chart\ head \}\}$/xi
- ) {
- next;
- } else {
- warning("line $.: ignoring incomprehensible: $_");
- }
- }
-}
-
-sub database_fetch_ocean () {
- my ($row,$sth);
- $sth= $dbh->prepare('SELECT islandname, archipelago FROM islands');
- $sth->execute();
- while ($row= $sth->fetchrow_hashref) {
- print DEBUG "database-island $row->{'islandname'}".
- " $row->{'archipelago'}\n";
- $dbisland2arch{$row->{'islandname'}}= $row->{'archipelago'};
- }
- $sth= $dbh->prepare('SELECT dist, a.islandname a, b.islandname b
- FROM dists
- JOIN islands AS a ON dists.aiid==a.islandid
- JOIN islands AS b ON dists.biid==b.islandid');
- $sth->execute();
- while ($row= $sth->fetchrow_hashref) {
- $dbdists->add_weighted_edge($row->{'a'}, $row->{'b'}, $row->{'dist'});
- }
-}
-
-sub database_graph_spr () {
- $dbspr= shortest_path_reduction('db',$dbdists);
+sub run_yppedia_chart_parse ($) {
+ my ($oceanfh) = @_;
+ yppedia_chart_parse($oceanfh, $debugfh,
+ \&nn_xy,
+ sub {
+ my ($x,$y,$arch) = @_;
+ push @wiarchlabels, [ $x,$y,$arch ];
+ },
+ sub {
+ my ($n, $island) = @_;
+ $wiisland2node{$island}= $n;
+ $winode2island{$n}= $island;
+ $widists->add_vertex($n);
+ $wiarchs->add_vertex($n);
+ },
+ sub {
+ my ($na, $nb, $solid) = @_;
+ $widists->add_weighted_edge($na, $nb, 1);
+ $wiarchs->add_edge($na, $nb) if $solid;
+ $wiarchs->add_edge($na, $nb) if $solid;
+ },
+ sub {
+ my ($lno,$l) = @_;
+ warning("line $l: ignoring incomprehensible: $l");
+ });