X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.main.git;a=blobdiff_plain;f=yarrg%2Fweb%2Fcheck_routestring;h=cfa7ec72303e2ea671acb4ef28aa7de9cdedb662;hp=e66cbfbfd35e855ef3a514806cf693426ceae24b;hb=c9225ff45ee5e69855cb24cfb648d903dbba54a7;hpb=c5b3ac45babf8012719dfb7eafd0cfa9d9eddff0 diff --git a/yarrg/web/check_routestring b/yarrg/web/check_routestring old mode 100755 new mode 100644 index e66cbfb..cfa7ec7 --- a/yarrg/web/check_routestring +++ b/yarrg/web/check_routestring @@ -29,70 +29,32 @@ sponsored by Three Rings. - This Mason component parses textual strings giving lists of islands - and archipelagoes, ie textual route strings. + This Mason component simply defines how to look up route entries. + It is called by qtextstring. -<%flags> -inherit => 'qtextstringcheck' - - -<%args> -$ocean -$format -$ctype => undef -$string -$returnhash => { } - - -<%perl> - -# typical url for this script: -# http://www.chiark.greenend.org.uk/ucgi/~clareb/mason/pirates/routetextstring?format=json&ocean=Midnight&string=d - -use CommodsWeb; - -my $dbh= dbw_connect($ocean); - -my $sth= $dbh->prepare("SELECT archipelago,islandid,islandname - FROM islands WHERE islandname LIKE ? - UNION ALL SELECT DISTINCT archipelago,NULL,archipelago - FROM islands WHERE archipelago LIKE ?"); - -my $emsg= ''; -my (@results, $canontext); - -foreach my $each (split m#[/|,]#, $string) { - $each =~ s/^\s*//; $each =~ s/\s*$//; $each =~ s/\s+/ /g; - next if !length $each; - my $err= sub { $emsg= sprintf $_[0], $each; last; }; - my %m; - my $results; - foreach my $pat ("$each\%", "\%$each\%") { - $sth->execute($pat,$pat); - $results= $sth->fetchall_arrayref(); - last if @$results==1; - map { $m{ $_->[2] }=1 } @$results; - $results= undef; - } - if (!$results) { - if (!%m) { - $err->('no island or arch matches "%s"'); - } elsif (keys(%m) > 5) { - $err->(' '); - } else { - $err->('ambiguous island or arch "%s",'. - ' could be '.join(', ', sort keys %m)); - } - } - push @results, $results->[0]; -}; - -$dbh->rollback(); - -return $emsg, - (join ' | ', map { $_->[2] } @results), - [ @results ]; - - +<%attr> +multiple => 1 +maxambig => 5 + + +<%method sqlstmt> + SELECT islandname,islandid,archipelago + FROM islands WHERE islandname LIKE ? +UNION ALL SELECT DISTINCT archipelago,NULL,archipelago + FROM islands WHERE archipelago LIKE ? + + +<%method nomatch> + no island or arch matches "<% $ARGS{spec} |h %>" + + +<%method ambiguous> + ambiguous island or arch "<% $ARGS{spec} |h %>", + could be <% $ARGS{couldbe} |h %> + + +<%method manyambig> +   +