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 | |
20 | our $VERSION = '0.912'; |
20 | our $VERSION = '0.913'; |
21 | |
21 | |
22 | use Crossfire; |
22 | use Deliantra; |
|
|
23 | use Deliantra::Map; |
23 | use DB_File; |
24 | use DB_File; |
24 | |
25 | |
25 | sub escape_html($) { |
26 | sub escape_html($) { |
26 | local $_ = shift; |
27 | local $_ = shift; |
27 | s/([<>&])/sprintf "&#%d;", ord $1/ge; |
28 | s/([<>&])/sprintf "&#%d;", ord $1/ge; |
… | |
… | |
60 | |
61 | |
61 | print "<?xml version='1.0' encoding='utf-8'?>", |
62 | 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">', |
63 | '<!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'>", |
64 | "<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>", |
64 | "<head>", |
65 | "<head>", |
65 | "<title>Crossfire Keyword Search</title>", |
66 | "<title>Deliantra Keyword Search</title>", |
66 | "<link rel='stylesheet' type='text/css' media='all' href='/common.css'/>\n", |
67 | "<link rel='stylesheet' type='text/css' media='all' href='/common.css'/>\n", |
67 | "</head>", |
68 | "</head>", |
68 | "<body>"; |
69 | "<body>"; |
69 | |
70 | |
70 | print "<h1>Search results for '", (join "' & '", map escape_html $_, @found), "'</h1>", |
71 | print "<h1>Search results for '", (join "' & '", map escape_html $_, @found), "'</h1>", |
… | |
… | |
91 | |
92 | |
92 | for my $path (@ARGV) { |
93 | for my $path (@ARGV) { |
93 | (my $base = $path) =~ s/\.map$//; |
94 | (my $base = $path) =~ s/\.map$//; |
94 | my $docnum = pack "n", ++$idx{Vdocnum}; |
95 | my $docnum = pack "n", ++$idx{Vdocnum}; |
95 | $idx{"D$docnum"} = $base; |
96 | $idx{"D$docnum"} = $base; |
96 | my $meta = read_arch "$base.map"; |
97 | my $meta = Deliantra::Map->new_from_file ("$base.map"); |
97 | |
98 | |
98 | for my $x (0 .. $meta->{width} - 1) { |
99 | for my $x (0 .. $meta->{width} - 1) { |
99 | for my $y (0 .. $meta->{height} - 1) { |
100 | for my $y (0 .. $meta->{height} - 1) { |
100 | for my $a (@{ $meta->{map}[$x][$y] }) { |
101 | for my $a (@{ $meta->{map}[$x][$y] }) { |
101 | for my $v (values %$a) { |
102 | for my $v (values %$a) { |
… | |
… | |
122 | shift; |
123 | shift; |
123 | |
124 | |
124 | search @ARGV; |
125 | search @ARGV; |
125 | } else { |
126 | } else { |
126 | # assume CGI |
127 | # assume CGI |
127 | chdir "/var/www/cfmaps.schmorp.de" or exit 69; |
128 | chdir "/var/www/maps.deliantra.net" or exit 69; |
128 | |
129 | |
129 | print <<EOF; |
130 | print <<EOF; |
130 | Content-Type: application/xhtml+xml |
131 | Content-Type: application/xhtml+xml |
131 | |
132 | |
132 | EOF |
133 | EOF |