Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / runtime / khelpcenter / searchhandlers / khc_docbookdig.pl.cmake
blob5693c86f1df93ae643f1bddb144554a876d4e073
1 #!/usr/bin/perl
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
25 use strict;
27 use Getopt::Long;
29 my $htdigdata = "/srv/www/htdig/common/";
30 my $htdigbin = "/usr/bin";
31 my $kdeprefix = "@CMAKE_INSTALL_PREFIX@";
32 chomp $kdeprefix;
34 my $dbg = 1;
36 my ($indexdir, $docpath, $identifier, $lang, $help );
38 GetOptions (
39 'indexdir=s' => \$indexdir,
40 'docpath=s' => \$docpath,
41 'identifier=s' => \$identifier,
42 'lang=s' => \$lang,
43 'help' => \$help,
46 if ( $help ) {
47 usage();
50 if ( !$indexdir || !$docpath || !$identifier ) {
51 print STDERR "Missing arguments.\n";
52 usage();
55 &dbg( "INDEXDIR: $indexdir" );
57 if ( !$lang ) { $lang = "en"; }
59 my $tmpdir = "$indexdir/$identifier.tmp";
60 if ( ! -e $tmpdir ) {
61 mkdir $tmpdir;
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; }
77 my $locale;
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";
85 exit 1;
88 $ENV{ PATH } = '/bin:/usr/bin';
89 $ENV{ CDPATH } = '';
90 $ENV{ ENV } = '';
92 my $findpath = "$kdeprefix/share/doc/HTML/$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";
99 exit 1;
101 while ( <FIND> ) {
102 chomp;
103 my $path = $_;
104 $path =~ /$findpath(.*)\/index.docbook$/;
105 my $app = $1;
106 print START "<a href=\"help://$app/index.docbook\">$path</a>\n";
108 close START;
110 my $mimetypefile = "$tmpdir/htdig_mime";
111 if ( !open( MIME, ">$mimetypefile" ) ) {
112 print STDERR "Unable to open '$mimetypefile' for writing.\n";
113 exit 1;
115 print MIME << "EOT";
116 text/html html
117 text/docbook docbook
119 close MIME;
121 my $parserfile = "$tmpdir/docbookparser";
122 if ( !open( PARSER, ">$parserfile" ) ) {
123 print STDERR "Unable to open '$parserfile' for writing.\n";
124 exit 1;
126 print PARSER << "EOT";
127 #! /bin/sh
129 file=\$1
130 shift
131 mime=\$1
132 shift
134 if test "\$#" -gt 0; then
135 orig=\${1/file:\\//}
136 shift
139 case "\$orig" in
140 help:/*)
141 orig=\${orig/help:\\//}
142 orig=\${orig/\/index.docbook/}
143 cd $kdeprefix/share/doc/HTML/en/\$orig
144 file=index.docbook
147 file=\$orig
148 cd `dirname \$orig`
150 esac
152 echo "t apptitle"
153 $kdeprefix/bin/meinproc --htdig "\$file"
155 close PARSER;
156 chmod 0755, $parserfile;
158 if ( !open( CONF, ">$conffile" ) ) {
159 print STDERR "Unable to open '$conffile' for writing.\n";
160 exit 1;
162 print CONF << "EOT";
163 # htdig configuration for doc '$identifier'
165 # This file has been automatically created by KHelpcenter
166 common_dir: $commondir
167 locale: $locale
168 database_dir: $htdigdb
169 database_base: \${database_dir}/$identifier
170 local_urls: help://=$kdeprefix/share/doc/HTML/en/ file://=/
171 local_urls_only: true
172 limit_urls_to: file:// help:/
173 ignore_noindex: true
174 max_hop_count: 4
175 robotstxt_name: kdedig
176 compression_level: 6
177 template_map: Long long $kdeprefix/share/apps/khelpcenter/searchhandlers/htdig/htdig_long.html
178 search_algorithm: exact:1 prefix:0.8
179 maximum_pages: 1
180 matches_per_page: 10
181 start_url: file://$tmpdir/index.html
182 external_parsers: text/docbook $parserfile
183 valid_extensions: .docbook .html
184 mime_types: $mimetypefile
186 close CONF;
188 my $ret = system( "$htdigbin/htdig", "-v", "-s", "-i", "-c", $conffile );
189 if ( $ret != 0 ) {
190 print STDERR "htdig failed\n";
191 } else {
192 $ret = system( "$htdigbin/htmerge", "-c", $conffile );
193 if ( $ret != 0 ) { print STDERR "htmerge failed\n"; }
196 if ( $ret == 0 ) {
197 my $existsfile = "$indexdir/$identifier.exists";
199 if ( !open( EXISTS, ">$existsfile" ) ) {
200 print STDERR "Unable to open '$existsfile' for writing.\n";
201 exit 1;
203 print EXISTS "$identifier\n";
204 close EXISTS;
206 print "Finished successfully.\n";
209 exit $ret;
211 sub dbg($)
213 $dbg && print STDERR shift, "\n";
216 sub usage()
218 print "Usage: khc_docbookdig.pl --indexdir <indexdir> --docpath <path> ";
219 print "--identifier <identifier>\n";
220 exit 1;