#!/usr/local/bin/perl
#This is a program to generate 53 html files

open (READ, "data");
$line = <READ>;
$count = 0;
while($line ne ""){
  #The following if loop is to check the beginning of each html file 
  if(($line eq "aa\n")||($line eq "aai\n")||($line eq "aau\n")||($line eq "aam\n")||($line eq "aan\n")||($line eq "aang\n")||($line eq "aap\n")||($line eq "aat\n")||($line eq "aak\n")||($line eq "ai\n")||($line eq "au\n")||($line eq "am\n")||($line eq "an\n")||($line eq "ang\n")||($line eq "ap\n")||($line eq "at\n")||($line eq "ak\n")||($line eq "ei\n")||($line eq "eng\n")||($line eq "ek\n")||($line eq "e\n")||($line eq "i\n")||($line eq "iu\n")||($line eq "im\n")||($line eq "in\n")||($line eq "ing\n")||($line eq "ip\n")||($line eq "it\n")||($line eq "ik\n")||($line eq "ou\n")||($line eq "o\n")||($line eq "oi\n")||($line eq "on\n")||($line eq "ong\n")||($line eq "ot\n")||($line eq "ok\n")||($line eq "oe\n")||($line eq "eoi\n")||($line eq "eon\n")||($line eq "oeng\n")||($line eq "eot\n")||($line eq "oek\n")||($line eq "u\n")||($line eq "ui\n")||($line eq "un\n")||($line eq "ung\n")||($line eq "ut\n")||($line eq "uk\n")||($line eq "yu\n")||($line eq "yun\n")||($line eq "yut\n")||($line eq "m\n")||($line eq "ng\n")){

    #The followint if loop is to end the html files  
    if ($count!=0){
        print WRITE ("</TABLE>\n</BODY>\n</HTML>\n");
      }

    chop($line);
    $name=$line;

    $line=$line.".html";
    open (WRITE, ">/can/finals/$line");

    print WRITE ("<HTML>\n");
    print WRITE ("<BODY background=\"/Img/matt3b.jpg\" BGCOLOR=moccasin>\n");
    print WRITE ("<table border=0 width=100%><tr><td>\n");
    print WRITE ("<img src=\"/Img/redtri.gif\"><font size=+2 color=red> $name</font>\n");   
    print WRITE ("<td align=right><a href=\"/Lexis/Canton/finals/53finals.html\"><img src=\"/Img/top.gif\" align=right border=0></a></table>\n");     
    print WRITE ("<p>\n");
    print WRITE ("<table cellpadding=5 border=1>\n"); 

    $count++;
    $line = <READ>;
    }

#The following else loop is to print out the content of each html file
 
  else{
      chop($line); 
      #The following statement is to split the line into 2 elements
      @array=split(/:/,$line);
      chop($array[1]);
      #The followint is to split the 2nd element into Chinese characters
      @word=split(/ +/,$array[1]);
      
      print WRITE ("<tr><td valign=top><b>$array[0]</b><td valign=top><a href=\"/Lexis/Canton/sound/$array[0].wav\"><img src=\"/Img/sounder.gif\" hspace=3 border=0></a>\n");

      print WRITE ("<td>");
      $number=1;

      while($word[$number] ne ""){

           #The if loop is to cancel "," this can not be used in the last word in the "data" file
           if ($word[$number] ne "­ó"){
              chop($word[$number]);
              }

           #The following is to get the lower byte of Chinese character
           $sub2=substr($word[$number],1,1);
         
           #get the decimal of the ascii 
           $char1=ord($word[$number]);
           $char2=ord($sub2);

           #get the heximal of the decimal number
           $hexa1=sprintf("%x", $char1);
           $hexa2=sprintf("%x", $char2);
 
           print WRITE ("<a href=\"/cgi-bin/canton-f2.pl?query=%$hexa1%$hexa2\">$word[$number]</a>, \n");
           $number++;
            }


      print WRITE ("</tr>\n"); 

      $line = <READ>;

      if ($line eq ""){
          print WRITE ("</TABLE>\n</BODY>\n</HTML>\n");
          } 
    
      }
    }
close(READ);
close(WRITE);  
