From: Ian Jackson Date: Wed, 12 Aug 2009 00:54:17 +0000 (+0100) Subject: WIP route fixes etc. X-Git-Tag: 3.4~227 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.web-live.git;a=commitdiff_plain;h=4c157b676894d03718be0395900162acea4f1ff3 WIP route fixes etc. --- diff --git a/yarrg/CommodsDatabase.pm b/yarrg/CommodsDatabase.pm index 2ea674d..7bd7c77 100644 --- a/yarrg/CommodsDatabase.pm +++ b/yarrg/CommodsDatabase.pm @@ -44,7 +44,8 @@ BEGIN { $VERSION = 1.00; @ISA = qw(Exporter); @EXPORT = qw(&db_setocean &db_writer &db_connect $dbh - &db_filename &db_doall &db_onconflict &db_setdatadir); + &db_filename &db_doall &db_onconflict + &db_setdatadir $db_datadir); %EXPORT_TAGS = ( ); @EXPORT_OK = qw(); @@ -52,14 +53,14 @@ BEGIN { our $dbfn; our $dbh; -our $datadir= '.'; +our $db_datadir= '.'; sub db_setdatadir ($) { - $datadir= $_[0]; + $db_datadir= $_[0]; } sub db_setocean ($) { my ($oceanname) = @_; - $dbfn= "$datadir/OCEAN-$oceanname.db"; + $dbfn= "$db_datadir/OCEAN-$oceanname.db"; } sub db_filename () { return $dbfn; @@ -93,7 +94,6 @@ sub db_writer () { } sub db_connect () { - return if $dbh; $dbh= DBI->connect("dbi:SQLite:$dbfn",'','', { AutoCommit=>0, RaiseError=>1, ShowErrorStatement=>1, diff --git a/yarrg/CommodsWeb.pm b/yarrg/CommodsWeb.pm index 377d97b..d09331d 100644 --- a/yarrg/CommodsWeb.pm +++ b/yarrg/CommodsWeb.pm @@ -44,7 +44,7 @@ BEGIN { $VERSION = 1.00; @ISA = qw(Exporter); @EXPORT = qw($dbh &db_setocean &db_connect &db_doall - $self_url $base_url); + &ocean_list); %EXPORT_TAGS = ( ); @EXPORT_OK = qw(); @@ -57,7 +57,22 @@ for my $dir (@INC) { } } -$self_url= 'http://'.$ENV{'SERVER_NAME'}.$ENV{'SCRIPT_NAME'}.$ENV{'PATH_INFO'}; -$base_url= $self_url; $base_url =~ s,/[^/]+,,; +my @ocean_list; + +sub ocean_list () { + if (!@ocean_list) { + my $fn= "$db_datadir/master-info.txt"; + my $f= new IO::File $fn or die $!; + my @r; + while (<$f>) { + next unless m/^ocean\s+(\S.*\S)\s*$/; + push @r, $1; + } + $f->error and die $!; + close $fn; + @ocean_list= @r; + } + return @ocean_list; +} 1; diff --git a/yarrg/web/pirate-route b/yarrg/web/pirate-route index 58f8f28..639c8b1 100644 --- a/yarrg/web/pirate-route +++ b/yarrg/web/pirate-route @@ -7,7 +7,7 @@ my @vars; @vars= ({ Name => 'Ocean', Before => 'Ocean: ', CmpCanon => sub { ucfirst lc $_[0] }, - Values => [ qw(Midnight Ice) ] + Values => [ ocean_list() ] }, { Name => 'Dropdowns', Before => 'Interface: ', CmpCanon => sub { !!$_[0] }, @@ -55,7 +55,7 @@ foreach my $var (@vars) { $qf{$n}= $value; } } - my $uri= URI->new($self_url); + my $uri= URI->new($m->current_comp()->name()); $uri->query_form(%qf); print ''; $after= ''; @@ -66,6 +66,9 @@ foreach my $var (@vars) { print '

'; } +die "unknown ocean $a{Ocean} ?" + unless grep { $_ eq $a{Ocean} } ocean_list(); + db_setocean($a{Ocean}); db_connect(); @@ -75,7 +78,7 @@ db_connect();

% if (!$a{Dropdowns}) { -Enter route (islands, or archipelagoes, separated by commas; +Enter route (islands, or archipelagoes, separated by |s or commas; abbreviations are OK):
+ + % for my $dd (0..$a{Dropdowns}-1) { - +% } + + + +% for my $dd (0..$a{Dropdowns}-1) { + % } +
% } diff --git a/yarrg/web/routetextstring b/yarrg/web/routetextstring index b84fd84..c39d48b 100644 --- a/yarrg/web/routetextstring +++ b/yarrg/web/routetextstring @@ -60,7 +60,7 @@ foreach my $each (split m#[/|,]#, $string) { push @results, $results->[0]; } -$canontext= join ' | ', map { encode_entities($_->[2]) } @results; +$canontext= join ' | ', map { $_->[2] } @results; $output->();