| 1 |
adcroft |
1.1 |
#!/usr/local/bin/perl -w |
| 2 |
|
|
=pod |
| 3 |
|
|
|
| 4 |
|
|
If this text is displayed on your browser then your web server |
| 5 |
|
|
is not configured to run .cgi programs. |
| 6 |
|
|
|
| 7 |
|
|
=cut |
| 8 |
|
|
|
| 9 |
|
|
use strict; |
| 10 |
|
|
use CGI; |
| 11 |
|
|
|
| 12 |
|
|
my $swish_binary = './swish-e'; |
| 13 |
|
|
|
| 14 |
|
|
my $q = CGI->new; |
| 15 |
|
|
|
| 16 |
|
|
|
| 17 |
|
|
print $q->header, |
| 18 |
|
|
header(), |
| 19 |
|
|
$q->start_form, |
| 20 |
|
|
'<p><center>', |
| 21 |
|
|
$q->textfield( |
| 22 |
|
|
-name => 'query', |
| 23 |
|
|
-size => 40, |
| 24 |
|
|
-maxlength => 60, |
| 25 |
|
|
), |
| 26 |
|
|
' ', |
| 27 |
|
|
$q->submit, |
| 28 |
|
|
'</center><p>', |
| 29 |
|
|
$q->end_form; |
| 30 |
|
|
|
| 31 |
|
|
show_results( $q ) if $q->param('query'); |
| 32 |
|
|
|
| 33 |
|
|
print footer(); |
| 34 |
|
|
|
| 35 |
|
|
|
| 36 |
|
|
#============================================ |
| 37 |
|
|
sub show_results { |
| 38 |
|
|
my $q = shift; |
| 39 |
|
|
|
| 40 |
|
|
my $query = $q->param('query') || ''; |
| 41 |
|
|
|
| 42 |
|
|
for ( $query ) { |
| 43 |
|
|
s/^\s+//; |
| 44 |
|
|
s/\s+$//; |
| 45 |
|
|
tr/\0//d; |
| 46 |
|
|
} |
| 47 |
|
|
|
| 48 |
|
|
return unless $query; |
| 49 |
|
|
|
| 50 |
|
|
|
| 51 |
|
|
my $pid; |
| 52 |
|
|
|
| 53 |
|
|
if ( $pid = open( SWISH, '-|' ) ) { |
| 54 |
|
|
my @rows; |
| 55 |
|
|
|
| 56 |
|
|
while (<SWISH>) { |
| 57 |
|
|
|
| 58 |
|
|
next unless /^\d/; |
| 59 |
|
|
chomp; |
| 60 |
|
|
|
| 61 |
|
|
my ($rank,$url,$title,$size) = split /::/; |
| 62 |
|
|
|
| 63 |
|
|
my $link = $q->a({ href => $url}, ($title || 'no title') ); |
| 64 |
|
|
|
| 65 |
|
|
push( @rows, |
| 66 |
|
|
$q->td( {align=>'right'}, $rank ) . |
| 67 |
|
|
$q->td( {align=>'left'}, $link ) . |
| 68 |
|
|
$q->td( {align=>'right'}, $size ) |
| 69 |
|
|
); |
| 70 |
|
|
} |
| 71 |
|
|
if ( @rows ) { |
| 72 |
|
|
print '<h2 align=center>Found: ', |
| 73 |
|
|
scalar @rows, |
| 74 |
|
|
(scalar @rows > 1) ? ' hits' : ' hit', |
| 75 |
|
|
'</h2>'; |
| 76 |
|
|
|
| 77 |
|
|
unshift @rows, $q->th(['Rank','Title','Length']); |
| 78 |
|
|
print $q->table({align=>'center'}, $q->Tr( \@rows ) ); |
| 79 |
|
|
} else { |
| 80 |
|
|
print '<h2 align=CENTER>Failed to find any results</h2>'; |
| 81 |
|
|
} |
| 82 |
|
|
} else { |
| 83 |
|
|
unless ( defined $pid ) { |
| 84 |
|
|
print "<h2 align=CENTER>Failed to Fork: $!</h2>"; |
| 85 |
|
|
return; |
| 86 |
|
|
} |
| 87 |
|
|
|
| 88 |
|
|
|
| 89 |
|
|
exec $swish_binary, |
| 90 |
|
|
'-w', $query, |
| 91 |
|
|
'-d','::'; |
| 92 |
|
|
|
| 93 |
|
|
die "Failed to exec '$swish_binary' Error:$!"; |
| 94 |
|
|
} |
| 95 |
|
|
} |
| 96 |
|
|
|
| 97 |
|
|
sub header { |
| 98 |
|
|
return <<EOF; |
| 99 |
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> |
| 100 |
|
|
|
| 101 |
|
|
<html> |
| 102 |
|
|
<head> |
| 103 |
|
|
<title>SWISH-Enhanced</title> |
| 104 |
|
|
<link href="style.css" rel=stylesheet type="text/css" title="refstyle"> |
| 105 |
|
|
</head> |
| 106 |
|
|
|
| 107 |
|
|
<body> |
| 108 |
|
|
|
| 109 |
|
|
<h1 class="banner"> |
| 110 |
|
|
<img src="images/swish.gif" alt="Swish Logo"><br> |
| 111 |
|
|
<img src="images/swishbanner1.gif"><br> |
| 112 |
|
|
<img src="images/dotrule1.gif"><br> |
| 113 |
|
|
<img src="images/swish2.gif" alt="SwishE2 Logo"> |
| 114 |
|
|
</h1> |
| 115 |
|
|
|
| 116 |
|
|
<center> |
| 117 |
|
|
<a href="index.html">Table of Contents</a> |
| 118 |
|
|
</center> |
| 119 |
|
|
|
| 120 |
|
|
<p> |
| 121 |
|
|
EOF |
| 122 |
|
|
} |
| 123 |
|
|
|
| 124 |
|
|
sub footer { |
| 125 |
|
|
return <<EOF; |
| 126 |
|
|
|
| 127 |
|
|
<P ALIGN="CENTER"> |
| 128 |
|
|
<IMG ALT="" WIDTH="470" HEIGHT="10" SRC="images/dotrule1.gif"></P> |
| 129 |
|
|
<P ALIGN="CENTER"> |
| 130 |
|
|
|
| 131 |
|
|
<div class="footer"> |
| 132 |
|
|
<BR>SWISH-E is distributed with <B>no warranty</B> under the terms of the |
| 133 |
|
|
<A HREF="http://www.fsf.org/copyleft/gpl.html">GNU Public License</A>,<BR> |
| 134 |
|
|
Free Software Foundation, Inc., |
| 135 |
|
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA<BR> |
| 136 |
|
|
Public questions may be posted to |
| 137 |
|
|
the <A HREF="http://swish-e.org/Discussion/">SWISH-E Discussion</A>. |
| 138 |
|
|
</div> |
| 139 |
|
|
|
| 140 |
|
|
</body> |
| 141 |
|
|
</html> |
| 142 |
|
|
EOF |
| 143 |
|
|
} |
| 144 |
|
|
|
| 145 |
|
|
|
| 146 |
|
|
|