This file is indexed.

/usr/sbin/dwww-find is in dwww 1.13.1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
#!/usr/bin/perl
# vim:ft=perl:cindent:ts=4:sts=4:sw=4:et:fdm=marker:cms=\ #\ %s
#
# Find all docs related to one program or find matching entries in Debian Doc. Menu
# "$Id: dwww-find 552 2011-02-08 21:59:22Z robert $"
#

use strict;

use Debian::Dwww::Utils;
use Debian::Dwww::Common;
use Debian::Dwww::Initialize;
use Debian::Dwww::DocBase;
use File::Basename qw(basename dirname);


my $dwwwvars            = &DwwwInitialize("/etc/dwww/dwww.conf");

my $dwww_quickfind_db   = $dwwwvars->{'DWWW_QUICKFIND_DB'};
my $dwww_menu_dir       = $dwwwvars->{'DWWW_DOCROOTDIR'} . "/dwww/menu";
my $dwww_swish_index    = "/var/cache/dwww/dwww.swish++.index";
my $dwww_swish_conf     = "/usr/share/dwww/swish++.conf";
my $dwww_regdocs_cache  = $dwwwvars->{'DWWW_REGDOCS_DB'};
$dwww_regdocs_cache     = undef if "$dwww_regdocs_cache" eq "" and not  ( -r "$dwww_regdocs_cache" );


my $templates_dir  = "/usr/share/dwww/templates";
my $template_start = "$templates_dir/dwww-find.start";
my $template_end   = "$templates_dir/dwww-find.end";


my $dpkgwwwcgi = "/usr/lib/cgi-bin/dpkg";



my $dpkg="dpkg-query";
if ( -x "/usr/bin/dlocate" && -s "/var/lib/dlocate/dlocatedb"
    && -s "/var/lib/dlocate/dpkg-list" ) {
    $dpkg="dlocate";
}
my $aptcache="/usr/bin/apt-cache";

sub Usage()
{
    print STDERR "usage: dwww-find [--package|--menu|--documentation|--docfile|--doc-base-list]\n" .
                 "         [--skip=number] searcharg\n";
}

#########################################################################
#
# Main program
#

if (! defined $ARGV[0]) {
    &Usage;
}

my $mode="p";
my $skip=0;
while ($ARGV[0] =~ m/^--(.*)$/) {
    shift @ARGV;
    if ($1 eq "package") { $mode = "p"; }
    elsif ($1 eq "menu") { $mode = "m"; }
    elsif ($1 eq "documentation") { $mode = "d"; }
    elsif ($1 eq "docfile") { $mode = "f"; }
    elsif ($1 eq "doc-base-list") { $mode = "b"; }
    elsif ($1 =~ m/^skip=(\d+)$/) { $skip=$1 ; }
    elsif (not $1) { last; }
    else {
        &Usage;
        exit(1);
    }
}

my $f_cnt     = 0;
my $srchvalue = "";
@ARGV = map { my @split = split(' ',$_); @split } @ARGV;
my $srchfor   = join(' ', @ARGV);
if ($mode eq "f") {
    # Check if we can show file
    $srchfor = &CheckAccess( $dwwwvars, $srchfor, $srchfor );
    die "Internal error" if $srchfor eq ""; # CheckAccess should have written the error message and exited.
} elsif ($mode ne "b") {
    $srchvalue = &HTMLEncode($srchfor);
}

undef %{$dwwwvars};

&PrintHeaders();

print &TemplateFile($template_start, { 'TITLE'    => 'Search results',
                                       'VALUE'    =>  $srchvalue,
                                       'MCHECKED' => $mode eq "m" ? 'checked' : '',
                                       'PCHECKED' => $mode eq "p" ? 'checked' : '',
                                       'DCHECKED' => $mode eq "d" ? 'checked' : ''
                                    });

if ($mode eq "p") {
    $f_cnt = &SearchPackage(@ARGV);
} elsif ($mode eq "m") {
    $f_cnt = &SearchMenus($dwww_menu_dir, $srchfor, @ARGV);
} elsif ($mode eq "d") {
    $f_cnt = &SearchRegisteredDocumentation($srchfor, $skip, 50);
} elsif ($mode eq "f") {
    $f_cnt = &SearchDocFile($srchfor);
} elsif ($mode eq "b") {
    $f_cnt = &SearchDocBaseList($srchfor);
}

print "<strong>Not found!</strong>\n" unless $f_cnt;


print &TemplateFile($template_end, { } );



#########################################################################
#
# Local functions
#
sub PrintHeaders() { # {{{
    print "Content-type: text/html; charset=UTF-8\n";
    print "\n";
} # }}}

sub AddSeparator { # {{{
    my $cnt = shift;
    return unless $cnt;
    print "<hr class=\"w15c\">\n";
} # }}}


sub SearchDocFile { # {{{
    my $arg = shift;
    my $f_cnt = 0;
    my $type = -d $arg ? 'dir' : 'file';
    my $pkgs = &FindPkg($arg, "docfile");
    my @packages = sort keys %{$pkgs};
    @packages = grep { $_ ne "VIRTUAL" } @packages;



    if ($#packages > 0) {
        print "<h2>Found " . ($#packages + 1) . " packages, which contain <em>" .
            "<a href=\"" . &GetURL($type, $arg) . "\">" .
            &HTMLEncode($arg) . "</a></em>:</h2>\n";
    } else {
        print "<h2>Documentation for packages, which contain <em>" .
            "<a href=\"" . &GetURL($type, $arg) . "\">" .
            &HTMLEncode($arg) . "</a></em>:</h2>\n";
    }


    if ($#packages > 5) {
        my $table = &BeginTable(\*STDOUT, "Found packages:", 4);

        foreach my $pkg (@packages) {
            &AddToTable(\*STDOUT, $table,
                        "<a href=\"" . &GetURL('search', $pkg) . "\">"
                    .   &HTMLEncode($pkg) . "</a>");
            $f_cnt++;
        };
        &EndTable(\*STDOUT, $table);
    } else {
        foreach my $pkg (@packages) {
            &AddSeparator($f_cnt);
            $f_cnt += &ShowPkgInfo( $pkg, $pkgs->{$pkg} )
        };
    }
    return $f_cnt;
} # }}}




sub ShowPkgInfo { # {{{
    my $pkg    = shift;
    my @src    = split (' ', shift);
    my $f_cnt  = 0;


    print "<h3><strong>Package:</strong> ";
    if ( -x "$dpkgwwwcgi" ) {
        print "<a href=\"" . &GetURL('dpkg', $pkg) . "\">"
            . &HTMLEncode($pkg) . "</a>";
    } else {
        print &HTMLEncode($pkg);
    }
    print "</h3>\n";

    $f_cnt += &PkgDescription($pkg);
    my @filelist = sort &GetPkgFileList($pkg);
    $f_cnt += &BasePkgFiles ($pkg, @filelist);
    $f_cnt += &RegisteredDocBaseInPkg(@filelist);
    $f_cnt += &MansInPkg(@filelist);
    $f_cnt += &InfosInPkg (@filelist);
    $f_cnt += &DocsInPkg (@filelist);
    $f_cnt += &SrcPkgLinks(@src);

    return $f_cnt;
} # }}}

#########   Package search functions   ###################################
#

sub FindPkg { # {{{
    my $searchfor = shift;
    my $type      = shift;
    my $ret       = {};

    if ( not defined $type and -r $dwww_quickfind_db ) {
        open (FINDPKG, "-|", ("dwww-quickfind", "--", $searchfor, $dwww_quickfind_db));
        while (<FINDPKG>) {
            chomp();
            my ($pkg, $src) = split(/:\s+/, $_, 2);
            $ret->{$pkg} = $src;
        }
    } else {
        (my $quotedsearchfor = $searchfor) =~ s/[\.\^\$\|\(\)\[\]\{\}\*\+\?\\]/\\$&/g;
        my @searchargs = ($dpkg, "-S", $quotedsearchfor);
        open (FINDPKG, "-|", @searchargs)
            or die "can't open $dpkg -S: $!\n";
        while (<FINDPKG>) {
            chomp();
            my ($pkg, $file) = split(/:\s*/, $_, 2);

            my @pkgsplit = split(/, /, $pkg);  # hanlde list of packages dpkg -S /usr/share/doc
            foreach my $pkg (@pkgsplit) {
                next if $pkg =~ /\s/;      # skip divertions
                    print STDERR $pkg, "::",  $file , "\n";

                if ($type eq "docfile") {
                    $ret->{$pkg} = undef if $file eq $searchfor;
                }
                elsif ($pkg eq $searchfor) {
                    $ret->{$pkg} = undef;
                }
                elsif ( $file =~ m/^.*\/(usr\/games|s?bin)\/$searchfor$/o ) {
                    $ret->{$pkg} = undef;
                }
            }
        }
    }
    delete $ret->{'VIRTUAL'};
    close FINDPKG;
    return $ret;
} # }}}

sub SearchPackage { # {{{
    my @args  = @_;
    my $f_cnt = 0;

    foreach my $arg (@args) {
        print "<h2>Documentation related to <em>" . &HTMLEncode("$arg") . "</em></h2>\n";
        my $packages = &FindPkg($arg);
        foreach my $pkg (sort keys%{$packages}) {
            &AddSeparator($f_cnt);
            $f_cnt += &ShowPkgInfo( $pkg, $packages->{$pkg} );
        }
        $f_cnt += &Apropos ($arg);
    }
    return $f_cnt;
} # }}}

sub GetPkgFileList { # {{{
    my $pkg = shift;
    my @ret = ();


    open (FILELIST, "-|", ($dpkg, "-L", $pkg));
    while (<FILELIST>) {
        chomp();
        push(@ret, $_);
    }
    close FILELIST;
    return @ret;
} # }}}

sub MansInPkg { # {{{
    my @files       = @_;
    my $res     = 0;
    my $table       = undef;

    foreach $_ (@files) {
        next unless m/\/man\/man[1-9n]\//;
        next unless ( -f "$_");
        if (!$res) {
            $res = 1;
            $table = &BeginTable(\*STDOUT, "Manual pages:", 3);
        }
        my $uri = $_;
        s/^.*\///;
        s/\.(gz|bz2)$//;
        s/\.([^.]*)$/($1)/;
        &AddToTable(\*STDOUT, $table,
                    "<a href=\"" . &GetURL('man', $uri) . "\">$_</a>");
    }
    if ($res) {
        &EndTable(\*STDOUT, $table);
    }
    return $res;
} # }}}


sub InfosInPkg() { # {{{
    my @files       = @_;
    my $res     = 0;
    my $table       = undef;

    foreach $_ (@files) {
        next unless m/\/info\/.*\.info(\.gz)?$/;
        next unless ( -f "$_");
        if (!$res) {
            $res = 1;
            $table = &BeginTable(\*STDOUT, "Info files:", 3);
        }
        my $uri = $_;
        s/^.*\///;
        s/^\..*//;
        s/\.gz$//;
        &AddToTable(\*STDOUT, $table,
                    "<a href=\"" . &GetURL('info', $uri). "\">$_</a>");
    }
    if ($res) {
        &EndTable(\*STDOUT, $table);
    }
    return $res;
} # }}}

sub RegisteredDocBaseInPkg { # {{{
    my @files       = @_;
    my $res     = 0;
    my $table       = undef;
    my @docb_files  = ();

    return 0 unless defined $dwww_regdocs_cache;

    foreach $_ (@files) {
        next unless m/\/usr\/share\/doc-base\/([^\/]+)/;
        next unless ( -f "$_");
        push (@docb_files, $1);
    }

    return 0 unless $#docb_files > -1;
    return 0 unless open (CACHE, "<$dwww_regdocs_cache");

    while (<CACHE>) {
        my ($name,$section,$menulink,$link,$doctitle)  = split(/\001/, $_, 5);
        foreach my $i (0 .. $#docb_files) {
            if ($docb_files[$i] eq $name) {
                if (!$res) {
                    $res = 1;
                    $table = &BeginTable(\*STDOUT, "Registered documentation:", 1);
                }
                &AddToTable(\*STDOUT, $table,
                            "<a href=\"" . $link ."\">" . &HTMLEncode($doctitle) . "</a>" .
                            " &nbsp; <small><em>(menu section: <a href=\"" . &GetURL('menu',  $menulink, $TRUE) . "\">" .
                    &HTMLEncode($section) . "</a>)</em><small>" );
                delete $docb_files[$i];
                last;
            }
        }
        last if $#docb_files < 0;
    }
    close CACHE;

    if ($res) {
        &EndTable(\*STDOUT, $table);
    }
    return $res;
} # }}}

 sub BasePkgFiles { # {{{
    my $package     = shift;
    my @files       = @_;
    my $res     = 0;

    my @basicdocs = ("copyright", "changelog", "NEWS", "README", "FAQ");
    my %docs;
    my @updocs = ("","","","","");
    my @debdocs = ("","","","");

    foreach $_ (@files) {
        next unless m/^\/usr\/share\/doc\/\Q$package\E\/([cNRF][^\/]+)$/;
        my $base = $1;
        $base =~ s/\.(gz|bz2)$//;
        my $debian = ($base =~ s/\.Debian$//) ? "Debian " : "";
        next unless ( -f $_);
        for ( my $i = 0; $i <= $#basicdocs; $i++) {
            if ($basicdocs[$i] eq $base) {
                $docs{$debian . $base} = $_;
                last;
            }
        }
    }

    foreach $_ (@basicdocs) {
        foreach my $debian ("", "Debian ") {
            next unless defined $docs{$debian . $_};
            if (!$res) {
                $res = 1;
                print STDOUT "<small><br>";
            } else {
                print STDOUT " | ";
            }
            print STDOUT "<a href=\"" . &GetURL('file', $docs{$debian . $_}) . "\">$debian$_</a>";
        }
    }
    if ($res) {
        print STDOUT "</small>\n";
    }
    return $res;
} # }}}

sub SrcPkgLinks($) { # {{{
    my @src     = @_;
    my $res     = 0;
    my $table       = undef;
    my $colcnt      = $#src <= 3 ? 3 : ($#src >= 5 ? 5 : $#src) ;


    foreach $_ (@src) {
        if (!$res) {
            $res = 1;
            $table = &BeginTable(\*STDOUT, "Other packages built from the same source:", $colcnt);
        }
        my $uri = &URLEncode($_);
        &AddToTable(\*STDOUT, $table,
                    "<a href=\"" . &GetURL('pkgsearch', $_) . "\">$_</a>");
    }
    if ($res) {
        &EndTable(\*STDOUT, $table);
    }
    return $res;
} # }}}

sub DocsInPkg { # {{{
    my @files       = @_;
    my $res     = 0;
    my $table       = undef;

    foreach $_ (@files) {
        next unless m/^\/usr(\/share)?\/doc\//;
        next unless ( -d "$_");
        if (!$res) {
            $res = 1;
            $table = &BeginTable(\*STDOUT, "Other documents:", 2);
        }
        my $uri = &URLEncode($_);
        &AddToTable(\*STDOUT, $table,
                    "<a href=\"" . &GetURL('dir', $_) . "\">$_</a>");
    }
    if ($res) {
        &EndTable(\*STDOUT, $table);
    }
    return $res;
 } # }}}

sub Apropos { # {{{
    my $searchfor   = shift;
    my @apropos     = ();
    my $res     = 0;
    my $table       = undef;
    my @searchargs  = ("apropos", "--", $searchfor);

    open (APROPOS, "-|", @searchargs)
        or die "can't open apropos: $!\n";
    while (<APROPOS>) {
        chomp();
        push (@apropos, $_);
    }
    close APROPOS;

    foreach $_ (sort @apropos) {
        chomp();
## Example "apropos" output that we are trying to parse:
## a2p (1)          - Awk to Perl translator
## #include <qslider.h> (3qt) [qslider] - Vertical or horizontal slider
##
        next unless (/^(.*?)\s\(([1-9]\S*)\)(\s*\[.*\])?\s+- .*$/);
        my $man  = "$1";
        my $sect = "$2";
        my $tmp  = defined $3 ? "$3" : "";
        if ($tmp =~  /\s*\[(.*)\]\s*/) {
            $_ = "$1/$sect";
        } else {
            $_ = "$man/$sect";
        }
        if (!$res) {
            $res = 1;
            print STDOUT "<h3>Manual page search:</h3>\n";
            $table = &BeginTable(\*STDOUT, "", 3);
        }

        my $uri = $_;
        $_ = &HTMLEncode("$man($sect)");
        &AddToTable(\*STDOUT, $table,
                   "<a href=\"" . &GetURL('runman', $uri) . "\">$_</a>");
    }

    if ($res) {
        &EndTable(\*STDOUT, $table);
    }
    return $res;
} # }}}

sub PkgDescription () { # {{{
    my $pkg         = shift;
    my $descr       = '';    # long description
    my $synopsis    = undef; # short description
    my $hpage       = undef; # homepage
    my $fdescr      = 0;
    my $res         = 0;
    my $table       = undef;

    return 0 unless (-x $aptcache);
    open PKGDESC, "-|", ($aptcache, "show", "-o", "APT::Cache::AllVersions=0", "--", $pkg);
    while (<PKGDESC>) {
        next if /^Description-md5:/;
        if (!$synopsis && !$fdescr && s/^Description(-[^:]+)?:\s+//) {
            chomp();
            $synopsis = $_;
            $fdescr = 1;
        } elsif ($fdescr && ! /^ /) {
            $fdescr = 0;
        } elsif ($fdescr) {
            $descr .= $_;
        }
        if (!$fdescr && s/^Homepage:\s+//) {
            chomp();
            $hpage = $_;
            last if $fdescr;
        }


    }
    close PKGDESC;

    return 0 unless defined $synopsis;
    print '<strong>Description:</strong> ' . &HTMLEncode($synopsis);
    print "\n<br>";
    print &HTMLEncodeAbstract($descr);
    if (defined $hpage) {
        $hpage = &HTMLEncode($hpage);
        print "\n<br><em>Homepage:</em> ";
        print '<a href="' . $hpage  . '">' . $hpage . '</a>';
    }
    return 1;
} # }}}


#########   Menu search functions   #######################################
#
sub SearchMenus { # {{{
    my $dir        = shift;
    my $searchfor  = shift;
    my @patterns   = @_;
    my $match_cnt  = 0;

    print "<h2>Menu entries related to <em>" . &HTMLEncode("$searchfor") . "</em></h2>\n";

    if (not opendir DOCBASEDIR, $dir) {
        print "Can't open directory $dir: $!\n";
        return $match_cnt;
    }

    # quote special regexp characters
    @patterns = map { s/[\.\^\$\|\(\)\[\]\{\}\*\+\?\\]/\\$&/g; $_ } @patterns;

    while (my $f = readdir(DOCBASEDIR)) {
        next if -d $f;
        next unless $f =~ /^s.*\.html$/;

        $match_cnt += &SearchinMenuFile($dir, $f, @patterns);
    }
    return $match_cnt;
} # }}}

sub SearchinMenuFile() { # {{{
    my $dir       = shift;
    my $file      = shift;
    my @patterns  = @_;
    my $sec       = undef;
    my $res       = undef;
    my $entry     = undef;
    my $srch      = undef;
    my $inentry   = 0;
    my $found     = 0;
    my $match_cnt = 0;
#my @patterns  = split(/\s+/, $searchfor);

    open FILE, "<$dir/$file" or die "Can't open file";

    while (<FILE>) {
        if (!defined $sec) {
            $sec = $1 if m/^<!-- Section: (.*) -->$/;
        } elsif (m/^<!-- begin entry -->/) {
            $inentry = 1;
            $srch    = '';
            $entry   = '';
            $found   = 0;
        } elsif (m/^<!-- end entry -->/) {
            $inentry = 0;
            $found   = 1;
            $_       = $srch;
            foreach my $pat (@patterns) {
                if (not $srch =~ m/$pat/i) {
                    $found = 0;
                    last;
                }
            }
            $res .= $entry if ($found);
            $match_cnt++ if ($found);
            $srch    = '';
        } elsif ($inentry) {
            $entry .= $_;
            next if s/^<br><b>Formats:.*//;
            s/<[^>]*>//g;
            $srch .= $_;
        }
    }


    if (defined $res) {
        print "<h2>Section: <a href=\"" . &GetURL('menu', $file) ."\">$sec</a></h2>\n";
        print "<dl>\n";
        print $res;
        print "</dl>\n";
    }
    return $match_cnt;
} # }}}


#########   Registered docs search functions   #############################
#
sub PrintRegDocsPages { # {{{
    my $searchfor  = shift;
    my $startwith  = shift;
    my $maxperpage = shift;
    my $resultcnt  = shift;
    my $max    = 10;
    my ($first, $last);

    return unless (defined $resultcnt and defined $startwith and defined $maxperpage
            and $resultcnt > $maxperpage and $maxperpage > 0);

    my $pagescnt = int ($resultcnt / $maxperpage);
    my $pageno   = int ($startwith / $maxperpage);
    $first       = 0;
    $last    = $pagescnt + 1;

    # kv5r: removed <center> (deprecated)
    print "<p class='c'>\n";

    if ($pagescnt > $max) {
        $first = (int ($pageno / $max)) * $max - 1;
        $last  = $first +  $max + 1;
        $last  = $pagescnt + 1 if $last > $pagescnt;
    }

#       print STDERR '$f, $l, $pn,$pc,$res = ' . "$first,$last,$pageno,$pagescnt,$resultcnt\n";

    for (my ($i, $skip) = ($first, $first * $maxperpage);
            $i <= $last;
            $i++, $skip += $maxperpage) {
        next if $i < 0 or $i > $pagescnt;
        if ($i == $pageno) {
            print "[<strong>" . ($i + 1) . "</strong>]\n"
        }
        else {
            print "[<a href=\"" .  &GetURL('search',  $searchfor) . "&amp;skip=" .
                $skip . "&amp;searchtype=d\">";

            if ($i == $first) {
                print "&lt;&lt;";
            }
            elsif ($i == $last) {
                print "&gt;&gt;";
            }
            else {
                print ($i + 1);
            }

            print "</a>]\n";
        }
    }
    print "</p>\n";
} # }}}

sub SearchRegisteredDocumentation { # {{{
    my $searchfor  = shift;
    my $startwith  = shift;
    my $maxperpage = shift;
    my @searchargs = ("/usr/bin/search++");
    my $resultcnt  = undef;
    my $desc       = '';

    if (not -x $searchargs[0]) {
        print "<strong>Error:</strong> Can't find <em>search++</em> program.\n";
        print "<br>Please install <a href=\"http://packages.debian.org/swish%2b%2b\">"
            . "swish++</a> package.\n";
        return 1 ;
    }

    if (not -r $dwww_swish_index) {
        print "<strong>Error:</strong> Can't find generated index file\n";
        print "<br>Please check if <a href=\"" . &GetURL('runman', "dwww-index++/8") . "\">"
            . "dwww-index++(8)</a> has been run.\n";
        return 1;
    }

    if (defined $startwith and defined $maxperpage) {
        $startwith = $maxperpage * int ($startwith/$maxperpage);
    }

    push(@searchargs, "--config-file=$dwww_swish_conf");
    push(@searchargs, "--index-file=$dwww_swish_index");
    push(@searchargs, "--skip-results=$startwith") if defined ($startwith);
    push(@searchargs, ("-m", "$maxperpage")) if defined ($maxperpage);
    push(@searchargs, "--");
    push(@searchargs, $searchfor);

    # Swish++ WWW module
    use lib '/usr/lib/swish++';
    my $use_www = eval "require WWW";


    open (SEARCH, "-|", @searchargs)
        or die "can't open search++: $!\n";

    print "<h2>Registered documents related to <em>" . &HTMLEncode($searchfor) . "</em></h2>\n";
    print "<dl>\n";

    while (<SEARCH>) {
        if (/^# ignored: /) {
            print "Following words were ignored: " . &HTMLEncode($') . "<br>\n";
            next;
        }
        if (/^# not found: /) {
            print "Following words weren't found: " . &HTMLEncode ($') . "<br>\n";
            next;
        }
        if (/^# results: /) {
            $resultcnt = $';
            # print "Result count: $'<br>\n";
            &PrintRegDocsPages($searchfor, $startwith, $maxperpage, $resultcnt);
            next;
        }
        next if (/^#/);

        my($rank, $file, $size, $title ) = split( /__--__/, $_, 4);
        print "<dt><a href=\"" . &GetURL('file' , $file)
               . "\">" . &HTMLEncode($title) . "</a> <em>($rank%)</em></dt>\n";

        if ($use_www and -r $file) {
            $desc = &WWW::extract_description($file);
            &WWW::hyperlink($desc);
        }
        $desc = &HTMLEncode($title) if $desc eq '';

        print "<dd>" . $desc . "</dd>\n";
        print "<dt><br></dt>\n";

    }
    print "</dl>\n";

    &PrintRegDocsPages($searchfor, $startwith, $maxperpage, $resultcnt);

    close SEARCH;

    return $resultcnt;

} # }}}


#########   Docs base list search functions   #############################
#
sub SearchDocBaseList { # {{{
    my $searchfor  = shift;

    my ($fmt, $db_id);
    if ($searchfor =~ m|^([^/]+)/([^/]+)$|)
    {
        ($fmt, $db_id) = ($1, $2);
    }
    else
    {
        print "Invalid input string: <em>" . &HTMLEncode($searchfor) . "</em>\n";
        return 1;
    }

    my $db_file = "/var/lib/doc-base/documents/" . $db_id;
    my $db_entry = &ParseDocBaseFile($db_file) if -r $db_file;
    my $fmt_entry = $db_entry->{'formats'}->{$fmt} if $db_entry;
    my @files = glob($fmt_entry->{'files'}) if $fmt_entry && $fmt_entry->{'files'};
    if (!$fmt_entry || $#files < 0) {
        print "Cannot find any registered files in format <em>" . &HTMLEncode($fmt) .
              "</em> for document <em>" . &HTMLEncode($db_id) . "</em>\n";
        return 1;
    }

    my $title = $db_entry->{'title'};
    $title = $db_id unless $title;
    print "<h2>Registered <em>". &HTMLEncode($fmt) . "</em> files for document \`<em>".
             &HTMLEncode($title) . "'</em></h2>\n";

    my %bydirs;
    foreach my $file (@files) {
        $bydirs{dirname($file)}->{basename($file)} = 1;
    }

    foreach my $dir (sort keys %bydirs) {
        my $table = &BeginTable(\*STDOUT, "Files in directory: " . &HTMLEncode($dir) .
                                ' &nbsp; &nbsp;<small><em>[<a href="' . GetURL('dir', $dir) 
                                . '">show directory contents</a>]</em></small>',
                               , 3);

        foreach my $file (sort keys %{$bydirs{$dir}}) {
            &AddToTable(\*STDOUT, $table,
                         "<a href=\"" . &GetURL($fmt, $dir . '/' . $file) . "\">"
                        .   &HTMLEncode($file) . "</a>");
        };
        &EndTable(\*STDOUT, $table);
    }
    return 1;
} # }}}