1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
#!/usr/bin/perl
#
# Wrapper script for creating search indices for htdig.
#
# This file is part of KHelpcenter.
#
# Copyright (C) 2002 SuSE Linux AG, Nuernberg
#
# Author: Cornelius Schumacher <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
use strict;
use Getopt::Long;
my $htdigdata = "/srv/www/htdig/common/";
my $htdigbin = "/usr/bin";
my $kdeprefix = "@prefix@";
chomp $kdeprefix;
my $dbg = 1;
my ($indexdir, $docpath, $identifier, $lang, $help );
GetOptions (
'indexdir=s' => \$indexdir,
'docpath=s' => \$docpath,
'identifier=s' => \$identifier,
'lang=s' => \$lang,
'help' => \$help,
);
if ( $help ) {
usage();
}
if ( !$indexdir || !$docpath || !$identifier ) {
print STDERR "Missing arguments.\n";
usage();
}
&dbg( "INDEXDIR: $indexdir" );
if ( !$lang ) { $lang = "en"; }
my $tmpdir = "$indexdir/$identifier.tmp";
if ( ! -e $tmpdir ) {
mkdir $tmpdir;
}
print "Creating index for <b>'$identifier'</b>\n";
my $htdigconf = $indexdir;
my $htdigdb = $indexdir;
my $conffile = "$htdigconf/$identifier.conf";
my $commondir = "$htdigdata/$lang";
if ( !$lang || !-e $commondir ) {
$commondir = "$htdigdata/en";
}
if ( !-e $commondir ) { $commondir = $htdigdata; }
my $locale;
if ( $lang eq "de" ) { $locale = "de_DE"; }
else { $locale = $lang; }
my $startfile = "$tmpdir/index.html";
if ( !open( START, ">$startfile" ) ) {
print STDERR "Unable to open '$startfile' for writing.\n";
exit 1;
}
$ENV{ PATH } = '/bin:/usr/bin';
$ENV{ CDPATH } = '';
$ENV{ ENV } = '';
my $findpath = "$kdeprefix/share/doc/HTML/$lang/";
my $findcmd = "find $findpath -name index.docbook";
print STDERR "FINDCMD: $findcmd\n";
if ( !open FIND, "$findcmd|" ) {
print STDERR "Unable to find docs.\n";
exit 1;
}
while ( <FIND> ) {
chomp;
my $path = $_;
$path =~ /$findpath(.*)\/index.docbook$/;
my $app = $1;
print START "<a href=\"help://$app/index.docbook\">$path</a>\n";
}
close START;
my $mimetypefile = "$tmpdir/htdig_mime";
if ( !open( MIME, ">$mimetypefile" ) ) {
print STDERR "Unable to open '$mimetypefile' for writing.\n";
exit 1;
}
print MIME << "EOT";
text/html html
text/docbook docbook
EOT
close MIME;
my $parserfile = "$tmpdir/docbookparser";
if ( !open( PARSER, ">$parserfile" ) ) {
print STDERR "Unable to open '$parserfile' for writing.\n";
exit 1;
}
print PARSER << "EOT";
#! /bin/sh
file=\$1
shift
mime=\$1
shift
if test "\$#" -gt 0; then
orig=\${1/file:\\//}
shift
fi
case "\$orig" in
help:/*)
orig=\${orig/help:\\//}
orig=\${orig/\/index.docbook/}
cd $kdeprefix/share/doc/HTML/en/\$orig
file=index.docbook
;;
*)
file=\$orig
cd `dirname \$orig`
;;
esac
echo "t apptitle"
$kdeprefix/bin/meinproc --htdig "\$file"
EOT
close PARSER;
chmod 0755, $parserfile;
if ( !open( CONF, ">$conffile" ) ) {
print STDERR "Unable to open '$conffile' for writing.\n";
exit 1;
}
print CONF << "EOT";
# htdig configuration for doc '$identifier'
#
# This file has been automatically created by KHelpcenter
common_dir: $commondir
locale: $locale
database_dir: $htdigdb
database_base: \${database_dir}/$identifier
local_urls: help://=$kdeprefix/share/doc/HTML/en/ file://=/
local_urls_only: true
limit_urls_to: file:// help:/
ignore_noindex: true
max_hop_count: 4
robotstxt_name: kdedig
compression_level: 6
template_map: Long long $kdeprefix/share/apps/khelpcenter/searchhandlers/htdig/htdig_long.html
search_algorithm: exact:1 prefix:0.8
maximum_pages: 1
matches_per_page: 10
start_url: file://$tmpdir/index.html
external_parsers: text/docbook $parserfile
valid_extensions: .docbook .html
mime_types: $mimetypefile
EOT
close CONF;
my $ret = system( "$htdigbin/htdig", "-v", "-s", "-i", "-c", $conffile );
if ( $ret != 0 ) {
print STDERR "htdig failed\n";
} else {
$ret = system( "$htdigbin/htmerge", "-c", $conffile );
if ( $ret != 0 ) { print STDERR "htmerge failed\n"; }
}
if ( $ret == 0 ) {
my $existsfile = "$indexdir/$identifier.exists";
if ( !open( EXISTS, ">$existsfile" ) ) {
print STDERR "Unable to open '$existsfile' for writing.\n";
exit 1;
}
print EXISTS "$identifier\n";
close EXISTS;
print "Finished successfully.\n";
}
exit $ret;
sub dbg($)
{
$dbg && print STDERR shift, "\n";
}
sub usage()
{
print "Usage: khc_docbookdig.pl --indexdir <indexdir> --docpath <path> ";
print "--identifier <identifier>\n";
exit 1;
}
|