delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / runtime / khelpcenter / searchhandlers / khc_docbookdig.pl.cmake
blobcf5c6a543b50e7c26e538dd9c2b2c25593355866
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 = "@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";
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 @HTML_INSTALL_DIR@/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"
154 $kdeprefix/bin/meinproc4 --htdig "\$file"
156 close PARSER;
157 chmod 0755, $parserfile;
159 if ( !open( CONF, ">$conffile" ) ) {
160 print STDERR "Unable to open '$conffile' for writing.\n";
161 exit 1;
163 print CONF << "EOT";
164 # htdig configuration for doc '$identifier'
166 # This file has been automatically created by KHelpcenter
167 common_dir: $commondir
168 locale: $locale
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:/
174 ignore_noindex: true
175 max_hop_count: 4
176 robotstxt_name: kdedig
177 compression_level: 6
178 template_map: Long long $kdeprefix/share/apps/khelpcenter/searchhandlers/htdig/htdig_long.html
179 search_algorithm: exact:1 prefix:0.8
180 maximum_pages: 1
181 matches_per_page: 10
182 start_url: file://$tmpdir/index.html
183 external_parsers: text/docbook $parserfile
184 valid_extensions: .docbook .html
185 mime_types: $mimetypefile
187 close CONF;
189 my $ret = system( "$htdigbin/htdig", "-v", "-s", "-i", "-c", $conffile );
190 if ( $ret != 0 ) {
191 print STDERR "htdig failed\n";
192 } else {
193 $ret = system( "$htdigbin/htmerge", "-c", $conffile );
194 if ( $ret != 0 ) { print STDERR "htmerge failed\n"; }
197 if ( $ret == 0 ) {
198 my $existsfile = "$indexdir/$identifier.exists";
200 if ( !open( EXISTS, ">$existsfile" ) ) {
201 print STDERR "Unable to open '$existsfile' for writing.\n";
202 exit 1;
204 print EXISTS "$identifier\n";
205 close EXISTS;
207 print "Finished successfully.\n";
210 exit $ret;
212 sub dbg($)
214 $dbg && print STDERR shift, "\n";
217 sub usage()
219 print "Usage: khc_docbookdig.pl --indexdir <indexdir> --docpath <path> ";
220 print "--identifier <identifier>\n";
221 exit 1;