X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-live.git;a=blobdiff_plain;f=yarrg%2Fweb%2Fquery_routesearch;h=9accc54bbf2dbf31987948bc2e8e2606457f2ba9;hp=93fcf0bc1bda2c57d793b0ed7a7b3e196ab12494;hb=2abd3537af0c697684bfb97895f230372101329d;hpb=20bea992a857ea1f03f19d81f7164b113a560e83 diff --git a/yarrg/web/query_routesearch b/yarrg/web/query_routesearch index 93fcf0b..9accc54 100644 --- a/yarrg/web/query_routesearch +++ b/yarrg/web/query_routesearch @@ -46,6 +46,8 @@ $emsgokorprint <%perl> +use BSD::Resource; + my $emsg; my @warningfs; my @islandids; @@ -91,7 +93,62 @@ This feature is not available from the "drop down menus" interface. <%perl> +if (!$emsg && $maxdist > 30) { + $emsg= "Searching for routes of more than 30 leagues is not". + " supported, sorry."; +} + $emsgokorprint->($emsg) or return; @islandids or return; +defined $routeparams->{MaxMass} or defined $routeparams->{MaxVolume} or return; + +#---------- compute the results ---------- + +my @rsargs; + +foreach my $k (qw(MaxMass MaxVolume MaxCapital)) { + my $v= $routeparams->{$k}; + push @rsargs, (defined $v ? $v : -1); +} +push @rsargs, defined $routeparams->{LossPerLeaguePct} + ? $routeparams->{LossPerLeaguePct}*0.01 : 1e-9; +push @rsargs, qw(search 10 10), $maxdist, 'any', @islandids; + +m/[^-.0-9a-zA-Z]/ and die "$_ $& ?" foreach @rsargs; + +unshift @rsargs, dbw_filename($qa->{'Ocean'}); +unshift @rsargs, qw(-DN); + +if ($qa->{'debug'}) { + +[[ <% "@rsargs" |h %> ]]
+<%perl>
+}
+
+unshift @rsargs, sourcebasedir().'/yarrg/routesearch';
+
+my $fh= new IO::File;
+my $child= $fh->open("-|"); defined $child or die $!;
+if (!$child) {
+	my $cpu= BSD::Resource::RLIMIT_CPU;
+	my ($soft,$hard)= getrlimit($cpu);
+	my $max=10;
+	setrlimit($cpu,$max,$hard) or die $! if $soft>$max;
+	exec @rsargs;
+	die $!;
+}
+
+while (<$fh>) {
+	chomp;
+	if ($qa->{'debug'}) {
+
+<% $_ |h %>
+<%perl>
+	}
+}
+
+if ($qa->{'debug'}) {
+	print "
\n"; +}