#!/usr/bin/perl -w
package main;
use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);
print "Content-type: text/html\n\n";
if (param){
$x=param("ano");
$x=~s/@//g;

open (F3,"< /tmp/prno.txt");
@t=<F3>;
$tt=$t[0];
close(F3);

open (F3,"< /tmp/file4.txt");
@y=<F3>;
$z=$y[0];
close(F3);

$prname="<".$z.">";
$prname1="<\/".$z.">";
$aname="<aXyAyaH-$x>";
$aname1="<\/aXyAyaH-$x>";
$ctr1=0;
open(H1, "> /tmp/output.txt");
open(H2, "< $tt");
@in = <H2>;
chomp(@in);
foreach $a(@in)
{
if($a=~/[0-9]ab$/){$a=~s/ab$//g;}
if($a=~/[0-9]a$/){$a=~s/a$//g;}
if($a=~/[0-9]b$/){$a=~s/b$//g;}
if($a=~/[0-9]c$/){$a=~s/c$//g;}
if($a=~/[0-9]d$/){$a=~s/d$//g;}
if($a=~/[0-9]e$/){$a=~s/e$//g;}
for ($ctr=1; $ctr<=31; $ctr++)
{
if($a=~ s/\{$ctr\}//g){}
if($a=~ s/\{\/$ctr\}//g){}
}

	if($a=~/$prname/){
	$ctr1=1;
		if($a=~/$aname/){
		$count1=1;
		$a=~ s/$aname//g;
		$a=~s/ [0-9].*//g;
		print H1 $a."\n";
		}
		elsif ($count1==1){
			if($a=~/$aname1/){$count1=0;}
			else{
			$a=~ s/$aname1//g;
			$a=~s/ [0-9].*//g;
			print H1 $a."\n";
			}
		}
	}
	elsif($ctr1==1){
		if($a=~/$prname1/){
		$ctr1=0;
		}
		else{
		$a=~ s/$prname1//g;
			if($a=~/$aname/){
			$a=~ s/$aname//g;
			$count1=1;
			$a=~s/ [0-9].*//g;
			print H1 $a."\n";
			}
			elsif ($count1==1){
				if($a=~/$aname1/){
				$count1=0;
				}
				else{
				$a=~ s/$aname1//g;
				$a=~s/ [0-9].*//g;
				print H1 $a."\n";
				}
			}
		}
	}
}
close(H1);
close(H2);
}

open (F3,"< /tmp/file1.txt");
@y=<F3>;
$z=$y[0];
close(F3);

print "<html>";
print "<title>Adhyaya Page</title>";
print "<meta http-equiv='Content-Type' content='text/html; charset= UTF-8'>";
print "<body bgcolor='FFFFCB' alink='blue' vlink='blue'>";
print "<center><h1><font color='darkbrown'>&#2358;&#2381;&#2352;&#2368;&#2350;&#2361;&#2366;&#2349;&#2366;&#2352;&#2340;&#2350;&#2381;<br>$z</h1></font></center>";
print "<table align='center'>";
system("./ri </tmp/output.txt >/tmp/output1.txt");
system("./iscii_nuktaZ.out </tmp/output1.txt >/tmp/output2.txt");
system("./QL.out </tmp/output2.txt >/tmp/output3.txt");
system("./iscii2utf8.py 1 </tmp/output3.txt >/tmp/output4.txt");

open (TMP,"< /tmp/output4.txt");
@in=<TMP>;
foreach $x(@in){
if($x=~/</){$x=~s/$x//g;}
if($x=~/,/){$x=~s/,/ /g;}
if($x=~/##/){$x=~s/##/@/g;}
print "<tr><td><font size=5>$x</font></td></tr>";
}
close(TMP);
print "</table></body></html>";
