#!/usr/bin/perl -w require 5; use strict; $ENV{PATH}='/usr/local/bin:/bin:/usr/bin'; $ENV{IFS}=" \t\n"; # Grab paragraphs from rfc-index matching pattern. # It's pretty cheap right now. # BEGIN { unshift @INC, "/home/kragen/public_html"; } use lib '/home/kragen/public_html'; use CGI; my $query = new CGI; my $searching = defined $query->param('pattern'); my $pattern; if ($searching) { $pattern = $query->param('pattern'); $pattern = quotemeta $pattern unless $query->param('regexp'); $pattern = "(?i)$pattern" if ((not defined ($query->param('case_sensitive'))) or $query->param('case_sensitive') ne 'yes'); } my $title = $searching ? "RFCs matching $pattern" : "Search RFC index"; print <$title

$title

eoh print $query->startform(-action => $ENV{'SCRIPT_NAME'}, -method=>'GET'), "\n", "

Last updated 2001-10-16\n

", "Search pattern: ", $query->textfield('pattern'), "\n", $query->checkbox(-name => 'case_sensitive', -label => 'Case sensitive', -value => 'yes'), "\n", $query->checkbox(-name => 'regexp', -label => 'Regular Expression search', -value => 'yes', -checked => 1), "\n", $query->submit, "\n", $query->endform, "\n"; if ($searching) { my $records = 0; $/ = ""; # paragraphs open INPUT, "gzip -dc /home/kragen/public_html/rfc-index-entries.txt.gz |"; while () { if (/$pattern/o) { /^([\s]*)(\d+)(.*)/ or warn "Can't find the number: $_"; my $number = $2; $number =~ s/^0*//; /\(Format(?::[\s\n]*|=)([^)]*)\)/ or /\(Not online\)/ or warn "Can't find the format: $_"; my $formats = $1; my @formats = split /,\s*/, $formats; my $format; # This is pretty ugly. foreach $format (@formats) { # The format changed recently. It used to be # (Format=.txt, .ps); now it's (Format: TXT=1824 bytes, # PS=1 bytes). if ($format =~ /^\.[a-z]*$/) { #$_ .= qq(rfc$number$format ); #$_ .= qq(rfc$number$format ); #$_ .= qq(rfc$number$format ); #$_ .= qq(rfc$number$format ); } elsif ($format =~ /^([A-Z]+)=\d+/) { my $ext = $1; $ext =~ tr/A-Z/a-z/; # $_ .= qq(rfc$number.$ext ); #$_ .= qq(rfc$number.$ext ); $_ .= qq(rfc$number.$ext ); } } $_ = "

$_\n"; print; $records++; } } print "


Found $records RFCs."; } print < eof