#!/usr/local/bin/perl

sub ReadParse {
  local (*n) = @_ if @_;
  local ($i, $key, $val);
if (&MethGet) {
    $in = $ENV{'QUERY_STRING'};
} elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
  read(STDIN, $in, $ENV{'CONTENT_LENGTH'});
}
@in = split(/&/, $in);
foreach $i (0 .. $#in) {
  $in[$i] =~ s/\+/ /g;
  ($key, $val) = split(/=/, $in[$i],2);
  $key =~ s/%(..)/pack("c",hex($1))/ge;
  $val =~ s/%(..)/pack("c",hex($1))/ge;
  $in{$key} .= "\0" if (defined($in{$key}));
  $in{$key} .= $val;
  }
  return length($in);
}

sub PrintHeader {
   return "Content-type: text/html\n\n";
}

sub MethGet {
  return ($ENV{'REQUEST_METHOD'} eq "GET");
}
1;
