#!/usr/bin/perl
#AVWL.pl - displays words from academic word list in bold from form
read (STDIN,$data,$ENV{'CONTENT_LENGTH'});
$data =~ s/\+/ /g;
@valuepairs = split(/&/,$data);
($name,$subscript)=split(/=/,$valuepairs[0]);
print ("Content-type:text/html\n\n");
print ("<HTML>\n<HEAD>\n<TITLE>AWL Highlighter></TITLE>\n</HEAD>\n<BODY>\n");
# Find level of checkfile
$checkfile = "AcademicWordList";
$checkfile = $checkfile . $subscript;
print ("<H2>File produced at level $subscript</H2>\n");
($name,$line)=split(/=/,$valuepairs[1]);
$line =~ s/%0D%0A/ \n<P> /g;
$line =~ s/%0A//g;
$line =~ s/%22/"/g;
$line =~ s/%26/\&/g;
$line =~ s/%27/'/g;
$line =~ s/%28/(/g;
$line =~ s/%29/)/g;
$line =~ s/%2A/*/g;
$line =~ s/%2C/,/g;
$line =~ s/%2E/./g;
$line =~ s/%2F/\//g;
$line =~ s/%3A/:/g;
$line =~ s/%3C/&lt;/g;
$line =~ s/%3E/&gt;/g;
$line =~ s/%3F/?/g;
$line =~ s/%60/\&#39;/g;
$line =~ s/%7E/~/g;
$line =~ s/%A0/\&nbsp;/g;
$line =~ s/%A1/\&iexcl;/g;
$line =~ s/%A2/\&cent;/g;
$line =~ s/%A3/\&pound;/g;
$line =~ s/%C0/\&Agrave;/g;
$line =~ s/%C1/\&Aacute;/g;
$line =~ s/%C2/\&Acirc;/g;
$line =~ s/%C3/\&Atilde;/g;
$line =~ s/%C4/\&Auml;/g;
$line =~ s/%C5/\&Aring;/g;
$line =~ s/%C6/\&AElig;/g;
$line =~ s/%C7/\&Ccedil;/g;
$line =~ s/%C8/\&Egrave;/g;
$line =~ s/%C9/\&Eacute;/g;
$line =~ s/%CA/\&Ecirc;/g;
$line =~ s/%CB/\&Euml;/g;
$line =~ s/%CC/\&Igrave;/g;
$line =~ s/%CD/\&Iacute;/g;
$line =~ s/%CE/\&Icirc;/g;
$line =~ s/%CF/\&Iuml;/g;
$line =~ s/%D0/\&ETH;/g;
$line =~ s/%D1/\&Ntilde;/g;
$line =~ s/%D2/\&Ograve;/g;
$line =~ s/%D3/\&Oacute;/g;
$line =~ s/%D4/\&Ocirc;/g;
$line =~ s/%D5/\&Otilde;/g;
$line =~ s/%D6/\&Ouml;/g;
$line =~ s/%D7/\&times;/g;
$line =~ s/%D8/\&Oslash;/g;
$line =~ s/%D9/\&Ugrave;/g;
$line =~ s/%DA/\&Uacute;/g;
$line =~ s/%DB/\&Ucirc;/g;
$line =~ s/%DC/\&Uuml;/g;
$line =~ s/%DD/\&Yacute;/g;
$line =~ s/%DE/\&THORN;/g;
$line =~ s/%DF/\&szlig;/g;
$line =~ s/%E0/\&agrave;/g;
$line =~ s/%E1/\&aacute;/g;
$line =~ s/%E2/\&acirc;/g;
$line =~ s/%E3/\&atilde;/g;
$line =~ s/%E4/\&auml;/g;
$line =~ s/%E5/\&aring;/g;
$line =~ s/%E6/\&aelig;/g;
$line =~ s/%E7/\&ccedil;/g;
$line =~ s/%E8/\&egrave;/g;
$line =~ s/%E9/\&eacute;/g;
$line =~ s/%EA/\&ecirc;/g;
$line =~ s/%EB/\&euml;/g;
$line =~ s/%EC/\&igrave;/g;
$line =~ s/%ED/\&iacute;/g;
$line =~ s/%EE/\&icirc;/g;
$line =~ s/%EF/\&iuml;/g;
$line =~ s/%F0/\&eth;/g;
$line =~ s/%F1/\&ntilde;/g;
$line =~ s/%F2/\&ograve;/g;
$line =~ s/%F3/\&oacute;/g;
$line =~ s/%F4/\&ocirc;/g;
$line =~ s/%F5/\&otilde;/g;
$line =~ s/%F6/\&ouml;/g;
$line =~ s/%F7/\&divide;/g;
$line =~ s/%F8/\&oslash;/g;
$line =~ s/%F9/\&ugrave;/g;
$line =~ s/%FA/\&uacute;/g;
$line =~ s/%FB/\&ucirc;/g;
$line =~ s/%FC/\&uuml;/g;
$line =~ s/%FD/\&yacute;/g;
$line =~ s/%FE/\&thorn;/g;
$line =~ s/%FF/\&yuml;/g;
$line =~ s/%92/'/g;
$line =~ s/%3B/\;/g;

$line =~ s/%93/\"/g;
$line =~ s/%94/\"/g;

# split line into separate words
{   @vars = split(/ /,$line);
# check each word in list against word list
    foreach $member(@vars)
    {   open (WORDFILE,"<$checkfile") or die "Could not open word list file\n";
        $found = 0;
        $checkword = <WORDFILE>;
        chomp ($checkword);
# make a lower case copy of $member and remove punctuation
        $checkmember = $member;
        $checkmember =~ tr/A-Z/a-z/;
        $checkmember =~ s/[^a-z-]//g;
        while ($checkword ne "")
        {   if ($checkword eq $checkmember)
            {   $found = 1;
            }
            $checkword = <WORDFILE>;
            chomp ($checkword);
        }
        if ($found == 1)
        {   print  ("<B>$member </B>");
        }
        else
        {   print  ("$member ");
        }
    }
    print  ("\n<P>")
}
# add HTML closing statements
print ("<HR>");

 print  ("</BODY>\n</HTML>\n");
