3 # Wrapper script for creating search indices for htdig.
5 # This file is part of KHelpcenter.
7 # Copyright (C) 2002 SuSE Linux AG, Nuernberg
9 # Author: Cornelius Schumacher <cschum@suse.de>
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 my $htdigdata = "/srv/www/htdig/common/";
30 my $htdigbin = "/usr/bin";
31 my $kdeprefix = "@CMAKE_INSTALL_PREFIX@";
36 my ($indexdir, $docpath, $identifier, $lang, $help );
39 'indexdir=s' => \
$indexdir,
40 'docpath=s' => \
$docpath,
41 'identifier=s' => \
$identifier,
50 if ( !$indexdir || !$docpath || !$identifier ) {
51 print STDERR
"Missing arguments.\n";
55 &dbg
( "INDEXDIR: $indexdir" );
57 if ( !$lang ) { $lang = "en"; }
59 my $tmpdir = "$indexdir/$identifier.tmp";
64 print "Creating index for <b>'$identifier'</b>\n";
66 my $htdigconf = $indexdir;
67 my $htdigdb = $indexdir;
69 my $conffile = "$htdigconf/$identifier.conf";
71 my $commondir = "$htdigdata/$lang";
72 if ( !$lang || !-e
$commondir ) {
73 $commondir = "$htdigdata/en";
75 if ( !-e
$commondir ) { $commondir = $htdigdata; }
78 if ( $lang eq "de" ) { $locale = "de_DE"; }
79 else { $locale = $lang; }
81 my $startfile = "$tmpdir/index.html";
83 if ( !open( START
, ">$startfile" ) ) {
84 print STDERR
"Unable to open '$startfile' for writing.\n";
88 $ENV{ PATH
} = '/bin:/usr/bin';
92 my $findpath = "@HTML_INSTALL_DIR@/$lang/";
93 my $findcmd = "find $findpath -name index.docbook";
95 print STDERR
"FINDCMD: $findcmd\n";
97 if ( !open FIND
, "$findcmd|" ) {
98 print STDERR
"Unable to find docs.\n";
104 $path =~ /$findpath(.*)\/index
.docbook
$/;
106 print START
"<a href=\"help://$app/index.docbook\">$path</a>\n";
110 my $mimetypefile = "$tmpdir/htdig_mime";
111 if ( !open( MIME
, ">$mimetypefile" ) ) {
112 print STDERR
"Unable to open '$mimetypefile' for writing.\n";
121 my $parserfile = "$tmpdir/docbookparser";
122 if ( !open( PARSER
, ">$parserfile" ) ) {
123 print STDERR
"Unable to open '$parserfile' for writing.\n";
126 print PARSER
<< "EOT";
134 if test
"\$#" -gt 0; then
141 orig
=\
${orig
/help:\\//}
142 orig
=\
${orig
/\/index
.docbook
/}
143 cd
@HTML_INSTALL_DIR@
/en/\
$orig
153 #$kdeprefix/bin/meinproc --htdig "\$file"
154 $kdeprefix/bin/meinproc
4 --htdig
"\$file"
157 chmod 0755, $parserfile;
159 if ( !open( CONF
, ">$conffile" ) ) {
160 print STDERR
"Unable to open '$conffile' for writing.\n";
164 # htdig configuration for doc '$identifier'
166 # This file has been automatically created by KHelpcenter
167 common_dir
: $commondir
169 database_dir
: $htdigdb
170 database_base
: \
${database_dir
}/$identifier
171 local_urls
: help
://=@HTML_INSTALL_DIR@
/en/ file
://=/
172 local_urls_only
: true
173 limit_urls_to
: file
:// help
:/
176 robotstxt_name
: kdedig
178 template_map
: Long long
$kdeprefix/share/apps/khelpcenter/searchhandlers
/htdig/htdig_long
.html
179 search_algorithm
: exact
:1 prefix
:0.8
182 start_url
: file
://$tmpdir/index.html
183 external_parsers
: text
/docbook
$parserfile
184 valid_extensions
: .docbook
.html
185 mime_types
: $mimetypefile
189 my $ret = system( "$htdigbin/htdig", "-v", "-s", "-i", "-c", $conffile );
191 print STDERR
"htdig failed\n";
193 $ret = system( "$htdigbin/htmerge", "-c", $conffile );
194 if ( $ret != 0 ) { print STDERR
"htmerge failed\n"; }
198 my $existsfile = "$indexdir/$identifier.exists";
200 if ( !open( EXISTS
, ">$existsfile" ) ) {
201 print STDERR
"Unable to open '$existsfile' for writing.\n";
204 print EXISTS
"$identifier\n";
207 print "Finished successfully.\n";
214 $dbg && print STDERR
shift, "\n";
219 print "Usage: khc_docbookdig.pl --indexdir <indexdir> --docpath <path> ";
220 print "--identifier <identifier>\n";