3
# Copyright 2002 by Stefan Hornburg (Racke) <racke@linuxia.de>
5
# Based on a sample implementation of Chris Tillman
6
# <tillman@azstarnet.com>.
8
# This program is free software; you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation; either version 2 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public
19
# License along with this program; if not, write to the Free
20
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28
use File::Temp qw(tempfile);
33
# version (replaced on packaging time)
34
my $version = '__VERSION__';
37
chomp(my $msg = shift );
38
print STDERR $msg, "\n";
43
# process commandline options
45
my $whandler = $SIG{__WARN__};
46
$SIG{__WARN__} = sub {print STDERR "$0: @_";};
47
unless (GetOptions(\%opts,
51
fatal_error(pod2usage(1));
57
} elsif ($opts{version}) {
58
print "dhelp version $version\n";
62
my $searchterm = shift;
64
# home directory of the current user
67
if (exists $ENV{'HOME'} && -d $ENV{'HOME'}) {
68
$homedir = $ENV{'HOME'};
70
$homedir = (getpwent()) [7];
73
# always use sensible-browser
74
my $browser = "/usr/bin/sensible-browser";
76
my $httpd_running = '';
78
unless ($opts{file}) {
79
# check if there is a CGI capable WWW server running on the localhost
80
my $testdoc = "/doc/HTML/index.html";
83
my $sock = IO::Socket::INET->new('127.0.0.1:80');
87
print $sock "HEAD $testdoc HTTP/1.0$eol";
88
print $sock "Host: localhost" . $blank;
90
while (my $line = <$sock>) {
91
if ($line =~ s/^Server: //) {
92
$httpd_running = $line;
93
$httpd_running =~ s/\r?\n?//go;
98
if ($httpd_running =~ /dhttpd/) {
99
# this server is not CGI capable
107
if ($httpd_running) {
108
# we can query the web server directly
110
$document="http://localhost/cgi-bin/dsearch?search=$searchterm";
112
$document="http://localhost/doc/HTML/index.html";
114
print "Starting browser (using HTTP $httpd_running) ...\n";
117
my ($basedir) = File::Spec->tmpdir();
118
my ($fh, $tmpfile) = tempfile ('dhelp' . 'X' x 6,
122
print "Starting dsearch for $searchterm\n";
124
open (DSEARCH, "/usr/lib/cgi-bin/dsearch file=1 search=$searchterm|");
128
close (DSEARCH) || fatal_error "$0: dsearch failed\n";
129
system ( "$browser $tmpfile" ) and fatal_error( "${browser}: Failed to open $tmpfile: $!\n" );
132
$document="/usr/share/doc/HTML/index.html";
133
print "Starting browser (using local filesystem) ...\n";
137
system ( "$browser $document" ) and fatal_error( "${browser}: Failed to open $document: $!\n" );
144
dhelp - Accessing Debian Online Help System
148
dhelp [ -h | -v | search-term ]
157
Direct the browser to use the local file system instead of
158
contacting the local WWW server.
162
Show a brief help message and exit.
164
=item B<-v, --version>
166
Show the program version number and exit.
172
B<dhelp> presents a list of installed html documentation. The
173
list can be browsed directly with Lynx, or if a web server
174
is installed then any web browser can be used.
176
In addition, you can search for terms indexed in the documentation
177
using B<dhelp search-term> .