#!/usr/bin/perl use strict; BEGIN { require 'common.pl' } require Encode; my $max_result = 30; sub decode_url ($) { my $s = shift; $s =~ tr/+/ /; $s =~ s/%([0-9A-Fa-f]{2})/pack 'C', hex $1/ge; return Encode::decode ('utf-8', $s); } # decode_url sub htescape ($) { my $s = shift; $s =~ s/&/&/g; $s =~ s/</g; $s =~ s/>/>/g; $s =~ s/"/"/g; return $s; } # htescape my $param = {}; for (split /[&;]/, $ENV{QUERY_STRING} || '') { my ($name, $value) = split /=/, $_, 2; $param->{decode_url ($name)} = decode_url ($value); } my $pattern = quotemeta normalize $param->{word}; my $eword = htescape $param->{word}; print qq[Content-Type: text/html ; charset=utf-8
No match found.]; } sub unescape_patterns ($) { my $pattern_data = shift; my $new_data = {}; for (keys %$pattern_data) { my $w = $_; my $v = $_; $v =~ s/\(\.\+\)/*/g; $v =~ s/\\([\s\S])/$1/g; $new_data->{$v} = $pattern_data->{$w}; } return $new_data; } # unescape_patterns sub print_matches ($$$) { my ($file_name, $exact_data, $pattern_data) = @_; my $file_id = $file_name; if ($file_name =~ /([0-9A-Za-z-]+)\.dat$/) { $file_id = $1; } my $has_match; my $r = qq[
@{[htescape $file_id]}
"...] and last if ++$result == $max_result; } } $result = 0; my %ja2en = reverse %en2ja; for (sort {$a cmp $b} keys %ja2en) { if (/$pattern/) { next if $added->{$ja2en{$_}}; $has_match = 1; $r .= get_match_text ($ja2en{$_}, $_, $pattern); $r .= q[ | |
...] and last if ++$result == $max_result; } } $r .= q[ |