--- cfmaps/cfmapidx 2005/11/22 17:54:41 1.2
+++ cfmaps/cfmapidx 2005/11/23 09:07:21 1.3
@@ -17,7 +17,7 @@
# along with gvpe; if not, write to the Free Software
# Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-our $VERSION = '0.0';
+our $VERSION = '0.91';
use Storable;
use DB_File;
@@ -28,6 +28,59 @@
$_
}
+sub search {
+ my (@kw) = @_;
+
+ tie %idx, DB_File, ".index.dat", O_RDONLY, 0, $DB_HASH
+ or die ".index.dat: $!";
+
+ my $cnt;
+ my %res;
+ my @found;
+
+ for (map lc, @kw) {
+ if (exists $idx{$_}) {
+ $cnt++;
+ $res{$_}++ for unpack "n*", $idx{$_};
+ push @found, $_;
+ #warn "$_ found\n";#d#
+ } else {
+ #warn "$_ not found\n";#d#
+ }
+ }
+
+ my @paths;
+
+ while (my ($k, $v) = each %res) {
+ next unless $v == $cnt;
+ push @paths, $idx{"D" . pack "n", $k};
+ }
+
+ binmode STDOUT, ":utf8";
+
+ print "",
+ '',
+ "",
+ "
",
+ "Crossfire Keyword Search",
+ "\n",
+ "",
+ "";
+
+ print "Search results for '", (join "' & '", map escape_html $_, @found), "'
",
+ "", (scalar @paths), " results found, up to 200 results shown.
",
+ "";
+
+ pop @paths while @paths > 200;
+
+ for (sort @paths) {
+ print "- $_
";
+ }
+
+ print "
",
+ "";
+}
+
if ($ARGV[0] eq "-a") {
shift;
@@ -46,12 +99,12 @@
for my $a (@{ $meta->{map}[$x][$y] }) {
for my $v (values %$a) {
$v = lc $v;
- $v =~ y/a-zA-Z0-9_\-./ /c;
+ $v =~ y/a-zA-Z0-9_\-.\// /c;
for (split /\s+/, $v) {
$idx2{$_} .= $docnum;
- if (/_\-\./) {
- $idx2{$_} .= $docnum for (split /[_\-\.]/)
+ if (/[_\-\.\/]/) {
+ $idx2{$_} .= $docnum for (split /[_\-\.\/]/)
}
}
}
@@ -67,161 +120,16 @@
} elsif ($ARGV[0] eq "-s") {
shift;
- tie %idx, DB_File, ".index.dat", O_RDONLY, 0, $DB_HASH
- or die ".index.dat: $!";
-
- my $cnt;
- my %res;
-
- for (map lc, @ARGV) {
- if (exists $idx{$_}) {
- $cnt++;
- $res{$_}++ for unpack "n*", $_;
- } else {
- warn "$_ not found\n";#d#
- }
- }
-
- while (my ($k, $v) = each %res) {
- next unless $v == $cnt;
- my $path = $idx{"D" . pack "n", $k};
- warn "found in doc $path\n";
- }
-
-# print STDERR "$path\n";
- die;
-
- open my $fh, ">:utf8", "$path.xhtml"
- or die "$path.xhtml: $!";
-
- select $fh;
-
- my $W = $meta->{width} * $T;
- my $H = $meta->{height} * $T;
-
- my $W2 = $W + 600;
-
- my (@path) = split /\//, $path;
-
- print "",
- '',
- "",
- "",
- "Crossfire Map \"$path\"",
- "\n",
- "\n",
- "\n",
- "",
- "",
- "";
-
- print "",
- "",
- "Crossfire Map ",
- "";
- print "/ ";
- for (0 .. $#path - 1) {
- print "$path[$_] / ";
- }
-
- my @dir = qw(none up right down left);
- my @tile = map {
- $meta->{info}{"tile_path_$_"}
- ? " "
- : ""
- } 1..4;
- #"}"# vim misparses without this comment
-
- print "$path[-1]",
- "",
- "[more about cfmaps.schmorp.de] ",
- " | ",
- " | $tile[0] | |
",
- "$tile[3] | ",
- "![map thumbnail](@path[-1].jpg) | ",
- "$tile[1] |
",
- " | $tile[2] | |
",
- "
";
-
- my $W1 = $W + 600;
-
- print "",
- escape_html $meta->{info}{msg},
- "
";
-
- print "";
-
- my %ignore = map +($_ => 1), qw(name _name x y);
- my %is_exit = map +($_ => 1), 41, 57, 66;
-
- for my $y (0.. $meta->{height} - 1) {
- print "";
- for my $x (0.. $meta->{width} - 1) {
- if (my $as = $meta->{map}[$x][$y]) {
- my @class;
-
- push @class, "fishy" if grep $_->{invisible} || $_->{face} || exists $_->{no_pass}, @$as;
- push @class, "exit" if grep $is_exit{$arch->{$_->{_name}}{type}} && $_->{slaying}, @$as;
- push @class, "dialog" if grep $_->{msg} =~ /^\@match/m, @$as;
-
- print "";
- print "";
-
- print join "\n", map " $_",
- reverse sort { (length $a) <=> (length $b) or $b <=> $a }
- grep $_, map $_->{connected}, @$as;
-
- print " ($x|$y)";
-
- sub print_archs {
- print " ";
- for my $a (@{$_[0]}) {
- my $o = $arch->{$a->{_name}};
- my $type = $a->{type} || $o->{type};
- my $aname = escape_html $a->{_name};
- my $name = escape_html $a->{name} || $o->{name};
-
- print "- $aname \"$name\"\n";
- for (sort keys %$a) {
- next if $ignore{$_};
- my $v = escape_html $a->{$_};
-
- if ($_ eq "slaying" && $is_exit{$type}) { # door, teleporter, player_changer
- $a->{msg} =~ /^final_map\s*(\S+)\s*$/m, $v = $1
- if $v eq "/!"; # random map
-
- print "slaying => $v\n";
- } elsif ($_ eq "other_arch") {
- print "$_ => $v\n";
- } elsif ($_ eq "inventory") {
- print "inventory =>\n";
- print_archs ($a->{$_});
- } elsif ($_ eq "msg") {
- print "
$v ";
- } else {
- print "$_ => $v\n";
- }
- }
- print " ";
- }
- print " ";
- }
-
- print_archs $as;
- print " | ";
- } else {
- print " | ";
- }
- }
- print "
";
- }
-
- print "
",
- "";
-
- close $fh;
+ search @ARGV;
+} else {
+ # assume CGI
+ chdir "/var/www/cfmaps.schmorp.de" or exit 69;
+
+ print <