#!/usr/bin/perl use warnings; use strict; use lib 'module/'; use BSD::BSDoogle; use CGI; use POSIX qw(ceil); my $cgi = new CGI; # Read the input passed to the script. my ( $pkg, $keyword, $page,$OS) = ( $cgi->param('pkgname'), $cgi->param('desc'), $cgi->param('page'),$cgi->param('OS') ); # Open the BSD INDEX file. if($OS eq 'FreeBSD') { openindex(INDEX_FILE => 'database/freebsd.txt') or die("$!"); } # open the FreeBSD INDEX file. elsif($OS eq 'NetBSD') { openindex(INDEX_FILE => 'database/netbsd.txt') or die("$!"); } # open the NetBSD INDEX file. # Search the BSD pkgsrc tree with the search() function, included in BSD::BSDoogle. my($packages,$descriptions,$locations) = search(TITLE => $pkg, KEYWORD => $keyword, CASE_SENSITIVE => 'no'); # Deference the results from search(). my (@packages) = @{$packages}; my (@descriptions) = @{$descriptions}; my (@locations) = @{$locations}; # print our header. print $cgi->header(); # print the .. start_html(-title => "BSDoogle :: Search results for ".$OS, -style => { -src => '../../../includes/bsdoogle/bsdoogle_results.css' }, -meta => { 'keywords' => 'Search BSD ports,BSD ports,BSD,search pkgsrc,pkgsrc,search the ports,search BSD ports,search BSD pkgsrc,search BSD ports online,search BSD pkgsrc online', 'description' => 'BSDoogle is an online tool you can use to search the Free,Net, and OpenBSD pkgsrc tree' }, -dtd => 'HTML' ); # print if @packages is undefined, or there were no search results. if(not defined(@packages) ) { # place the bsdoogle logo at the top of the page print '
'; print $cgi->img({-src =>'../../../../projects/bsdoogle/imgs/bsdoogle.jpg'}); print '
'; # ** raw HTML, unable to use CGI module for this snippet. print '
Nothing found.
We are sorry, but bsdoogle was unable to return any matche\'s for your search
'; # print print $cgi->end_html(); # exit with 0. exit(); } # $perpage holds the amount of results to display per page. my $perpage; # Attempt to read a cookie, if we cant read a cookie set $perpage to the default of 10 results perpage. if(my $cookie = $cgi -> cookie('bsdoogle') ) { (undef,$perpage) = split(/=/,$cookie,2); } else { $perpage = '10'; } # Divide $perpage into $#packages, giving us the total number of pages that can be browsed. my $total_pages = ceil($#packages / $perpage); # Now what do I do ???? print $total_pages; print @packages;