ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cfmaps/cfmapidx
(Generate patch)

Comparing cfmaps/cfmapidx (file contents):
Revision 1.8 by root, Thu Jun 21 12:30:10 2007 UTC vs.
Revision 1.12 by root, Thu Oct 22 08:19:16 2009 UTC

1#!/opt/bin/perl 1#!/opt/bin/perl
2 2
3# cfmap2idx - inverted index for crossfire maps 3# cfmap2idx - inverted index for deliantra maps
4# Copyright (C) 2005,2007 Marc Lehmann <cfmaps@schmorp.de> 4# Copyright (C) 2005,2007,2008 Marc Lehmann <cfmaps@schmorp.de>
5# 5#
6# CFMAPIDX is free software; you can redistribute it and/or modify 6# CFMAPIDX is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by 7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or 8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version. 9# (at your option) any later version.
15# 15#
16# You should have received a copy of the GNU General Public License 16# You should have received a copy of the GNU General Public License
17# along with cfmaps; if not, write to the Free Software 17# along with cfmaps; if not, write to the Free Software
18# Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18# Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 19
20our $VERSION = '0.912'; 20our $VERSION = '0.923';
21 21
22use Crossfire; 22use Deliantra;
23use Deliantra::Map;
24
25use Fcntl;
23use DB_File; 26use SDBM_File;
24 27
25sub escape_html($) { 28sub escape_html($) {
26 local $_ = shift; 29 local $_ = shift;
27 s/([<>&])/sprintf "&#%d;", ord $1/ge; 30 s/([<>&])/sprintf "&#%d;", ord $1/ge;
28 $_ 31 $_
29} 32}
30 33
31sub search { 34sub search {
32 my (@kw) = @_; 35 my (@kw) = @_;
33 36
34 tie %idx, DB_File, ".index.dat", O_RDONLY, 0, $DB_HASH 37 tie %idx, SDBM_File, ".index.dat", O_RDONLY, 0
35 or die ".index.dat: $!"; 38 or die ".index.dat: $!";
36 39
37 my $cnt; 40 my $cnt;
38 my %res; 41 my %res;
39 my @found; 42 my @found;
60 63
61 print "<?xml version='1.0' encoding='utf-8'?>", 64 print "<?xml version='1.0' encoding='utf-8'?>",
62 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">', 65 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
63 "<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>", 66 "<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>",
64 "<head>", 67 "<head>",
65 "<title>Crossfire Keyword Search</title>", 68 "<title>Deliantra Keyword Search</title>",
66 "<link rel='stylesheet' type='text/css' media='all' href='/common.css'/>\n", 69 "<link rel='stylesheet' type='text/css' media='all' href='/common.css'/>\n",
67 "</head>", 70 "</head>",
68 "<body>"; 71 "<body>";
69 72
70 print "<h1>Search results for '", (join "' &amp; '", map escape_html $_, @found), "'</h1>", 73 print "<h1>Search results for '", (join "' &amp; '", map escape_html $_, @found), "'</h1>",
82} 85}
83 86
84if ($ARGV[0] eq "-a") { 87if ($ARGV[0] eq "-a") {
85 shift; 88 shift;
86 89
87 tie %idx, DB_File, ".index.dat~", O_RDWR|O_CREAT, 0644, $DB_HASH 90 tie %idx, SDBM_File, ".index.dat~", O_RDWR|O_CREAT, 0644
88 or die ".index.dat~: $!"; 91 or die ".index.dat~: $!";
89 92
90 my %idx2; 93 my %idx2;
91 94
92 for my $path (@ARGV) { 95 for my $path (@ARGV) {
93 (my $base = $path) =~ s/\.map$//; 96 (my $base = $path) =~ s/\.map$//;
94 my $docnum = pack "n", ++$idx{Vdocnum}; 97 my $docnum = pack "n", ++$idx{Vdocnum};
95 $idx{"D$docnum"} = $base; 98 $idx{"D$docnum"} = $base;
96 my $meta = read_arch "$base.map"; 99 my $meta = Deliantra::Map->new_from_file ("$base.map");
97 100
98 for my $x (0 .. $meta->{width} - 1) { 101 for my $x (0 .. $meta->{width} - 1) {
99 for my $y (0 .. $meta->{height} - 1) { 102 for my $y (0 .. $meta->{height} - 1) {
100 for my $a (@{ $meta->{map}[$x][$y] }) { 103 for my $a (@{ $meta->{map}[$x][$y] }) {
101 for my $v (values %$a) { 104 for my $v (values %$a) {
116 119
117 while (my ($k, $v) = each %idx2) { 120 while (my ($k, $v) = each %idx2) {
118 $idx{$k} = pack "n*", keys %{ { map +($_ => 1), unpack "n*", $idx{$k}.$v } }; 121 $idx{$k} = pack "n*", keys %{ { map +($_ => 1), unpack "n*", $idx{$k}.$v } };
119 } 122 }
120 123
124 untie %idx;
125
121} elsif ($ARGV[0] eq "-s") { 126} elsif ($ARGV[0] eq "-s") {
122 shift; 127 shift;
123 128
124 search @ARGV; 129 search @ARGV;
125} else { 130} else {
126 # assume CGI 131 # assume CGI
127 chdir "/var/www/cfmaps.schmorp.de" or exit 69; 132# chdir "/var/www/maps.deliantra.net" or exit 69;
128 133
129 print <<EOF; 134 print <<EOF;
130Content-Type: application/xhtml+xml 135Content-Type: application/xhtml+xml
131 136
132EOF 137EOF

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines