#!/bin/perl

$date = `date`;
$FAQ = "MacFAQ.txt";
$parse = '';	# very globalized var.

	if ($ENV{'QUERY_STRING'} eq '')	{ # is NULL then
		&HeaderInfo;
	}
	else	{
		&ParseString;
		&RetrievePages;
	}

sub ParseString	{
	read(STDIN, $pstring, $ENV{'CONTENT_LENGTH'});
	@pstring = split(/&/, $pstring);

	foreach $i (0 .. $#pstring)	{ # from 0 -> sizeof(pstring)
		$pstring[$i] =~ s/\+/ /g;  # substitute +'s for spaces
		($key, $val) = split(/=/, $pstring[$i]); #get key/values
		$key =~ s/%(..)/pack("c",hex($1))/ge;
		$val =~ s/%(..)/pack("c",hex($1))/ge;
		$parse{$key} .= "\0" if (defined($parse{$key}));
		$parse{$key} .= $val;
	}
}

sub RetrievePages	{
	if ($parse{'page-type'} =~ 'MacGeneral')	{
		$return_page = "MacFaqGeneral.html";
	}
	elsif ($parse{'page-type'} =~ 'MacHardware')	{
			$return_page = "MacFaqHardware.html";
		}
	else	{
		$return_page = "MacFaqSoftware.html";
	}


	print "Content-type: text/html\n\n";
	print "Location: $return_page\n";
}

sub HeaderInfo	{

	print "Content-type: text/html\n\n";
	print <<"EOTX";

	<HTML>
		<HEAD>
			<TITLE>CSite MACINTOSH Frequently Asked Questions
			</TITLE>
		</HEAD>

		<BODY>
			<H2>Ok, you asked and now you shall recieve</H2>
			<P>
			<P>General Problems:</P>
			<P>Hardware Specific:</P>
			<P>Software Specific:</P>
		</BODY>
	</HTML>
EOTX
exit;
}

