#!/usr/bin/perl
# rat2html.pl
# Copyright 1996, Andrew Daviel, Vancouver-Webpages.com
# you may freely use this program
# Converts a very limited subset of PICS ratings files to an HTML form
# Usage: rat2html.pl < service.rat > service.gen.html
#
# define CGI script to handle the generated form
$action = "/cgi-bin/mk-PICS.pl" ;
#$log = 1 ;
$| = 1 ;
#$debug = 1 ;
while () {
chop ; $line = $_ ;
if ($debug) { print "$_\n"; }
if (/\(\s*PICS-version/i) {
s/.*PICS-version\s+//i ; s/\).*// ; $PICS_version = $_ ;
if ($log) { print STDERR "Got PICS version $PICS_version\n"; }
}
if (/\(\s*rating-system\s+\"/i) {
s/.*rating-system\s+\"//i ; s/\".*// ; $rating_system = $_ ;
if ($log) { print STDERR "Got rating-system \"$rating_system\"\n"; }
}
if (/\(\s*rating-service\s+\"/i) {
s/.*rating-service\s+\"//i ; s/\".*// ; $rating_service = $_ ;
if ($log) { print STDERR "Got rating-service \"$rating_service\"\n"; }
}
if (/\(\s*category/) {
&do_category ;
}
if (!$category) {
if (/\(\s*name\s+\"/) {
s/.*\(\s*name\s+\"// ; s/\".*// ; $rating_name = $_ ;
if ($log) { print STDERR "Got rating name \"$rating_name\"\n"; }
}
if (/\(\s*description\s+\"/) {
s/.*\(\s*description\s+\"// ; s/\".*// ; $rating_description = $_ ;
if ($log) { print STDERR "Got rating description \"$rating_description\"\n"; }
}
if (/\(\s*icon\s+\"/) {
s/.*\(\s*icon\s+\"// ; s/\".*// ; $rating_icon = $_ ;
if ($log) { print STDERR "Got rating icon \"$rating_icon\"\n"; }
}
} else { # category
$_ = $line ; if (/\(\s*label\s+/) {
$label++ ;
}
if ($label) {
$_ = $line ; if (/\(\s*name\s+\"/) {
s/.*\(\s*name\s+\"// ; s/\".*// ; $name[$label]=$_ ;
if ($log) { print STDERR "Got label name \"$_\"\n"; }
}
$_ = $line ; if (/\(\s*value\s+/) {
s/.*\(\s*value\s+// ; s/\).*// ; $value[$label]=$_ ;
if ($log) { print STDERR "Got label value \"$_\"\n"; }
}
$_ = $line ; if (/\(\s*description\s+\"/) {
s/.*\(\s*description\s+\"// ; s/\".*// ; $description[$label]=$_ ;
if ($log) { print STDERR "Got label description \"$_\"\n"; }
}
} else { # if label
$_ = $line ; if (/\(\s*name\s+\"/) {
s/.*\(\s*name\s+\"// ; s/\".*// ; $name = $_ ;
if ($log) { print STDERR "Got category name \"$name\"\n"; }
}
$_ = $line ; if (/\(\s*description\s+\"/) {
s/.*\(\s*description\s+\"// ; s/\".*// ; $description = $_ ;
if ($log) { print STDERR "Got category description \"$description\"\n"; }
}
$_ = $line ; if (/\(\s*transmit-as\s+\"/) {
s/.*\(\s*transmit-as\s+\"// ; s/\".*// ; $transmit_as= $_ ;
if ($log) { print STDERR "Got transmit-as \"$transmit_as\"\n"; }
}
$_ = $line ; if (/\(\s*min\s+/) {
s/.*\(\s*min\s+// ; s/\).*// ; $min = $_ ;
if ($log) { print STDERR "Got min \"$min\"\n"; }
}
$_ = $line ; if (/\(\s*max\s+/) {
s/.*\(\s*max\s+// ; s/\).*// ; $max = $_ ;
if ($log) { print STDERR "Got max \"$max\"\n"; }
}
} # !label
} # category
}
& do_category ;
print <