#!/usr/athena/bin/perl
#Hebrifier perl script. Converts Hebrew text written
#by Mule and puts it in a form easily readable by Netscape.
#Author: Omri Schwarz Written December 1997
# Copyright: Omri Schwarz 1997.
#You may distribute freely, but only if you retain this attribution. 
# Also, check the pathname to your interpreter if you copy to your own box.
$infiler = @ARGV[0];
$big = @ARGV;
@helpmessage=("Hebrifier Perl Script, originally written by Omri Schwarz, MIT, 1997.\n\n","Converts Hebrew text from some outdated editors \050mule) to a\nform readable by Netscape or xterms using an ISO-8859-8 font.\n\n"," Format: hebrifier.pl [-help] file [file] [-nh (either)].\n\n","-help Gives this message and exits.\n\n","Not specifying a second filename dumps the output to your screen.\n-n Specifies that the text must be readable by Netscape.\n\n","-h Also gets the script to put in the standard set of \nHTML tags for a new file. \n\n","For bug-reports, flames, etc, email ocschwar\@mit.edu \nwith \042hebrifier\042 in the subject line.\n\n");
@htmltop=("<HTML>\n<HEAD>\n<meta http-equiv=\047Content-Type\047 content=\047text/html; charset=iso-8859-8\047>\n","<META NAME=\042editor\042 CONTENT=\042Hebrifier.pl\042>\n","<title>Hebrifier output page.</title>\n</head>\n","<body>\n<div align=right>\n<pre>\n");
$htmlbottom="</pre>\n</div>\n</body>\n</html>\n";
if ($big>1) {
    $outfiler= @ARGV[1];
}
else {
    $outfiler="-fileisSTDOUT";
    };
if ($big =3){
    $mode = @ARGV[2];}
else {
    $mode="none\n";}
if ($outfiler =~ /^-/) {
    $globref = STDOUT;}
else {
    open(OUTHANDLE,">>$outfiler") || die "Cannot create or open $outfiler . Eit!\n";
    $globref=OUTHANDLE;
}
print "Note: Hebrifying $infiler . \n";
if ($infiler eq "-help") {
    print "@helpmessage";
    exit;
}
open(INHANDLE,$infiler) || die "Cannot find $infiler . Eit!\n";
if ($outfiler =~ /^-/) {
    $mode=$outfiler;
} else {
    print "$mode $outfiler l\n";}
if (($mode =~ /^-/) && ($mode =~ /n/)) {$netscape=1;} else {$netscape=0;}
if ($netscape==1) {
    print "Note: Removing characters that xterms don\047t mind, but Netscape does.\n";}
if (($mode =~ /^-/) && ($mode =~ /h/)) {
    print "Note: Putting a set of HTML tags.\n";
    print $globref "@htmltop";}
while (<INHANDLE>) {
    chop($_);
    @aa=split(//,$_); #take each line, remove newline and flip
    @a=reverse @aa;
    $b=join('' , @a);
    if  ($netscape==1) {
	$b =~ s/\210//g;
	$b =~ s/\240\242\232/ /g;
	$b =~ s/\256\242\232/./g; 
	$b =~ s/\241\242\232/!/g;
	$b =~ s/\300\242\232/@/g;
	$b =~ s/\243\242\232/#/g;
	$b =~ s/\244\242\232/\$/g;
	$b =~ s/\245\242\232/%/g;
	$b =~ s/\336\242\232/^/g;
	$b =~ s/\246\242\232/&/g;
	$b =~ s/\252\242\232/*/g;
	$b =~ s/\250\242\232/(/g;
	$b =~ s/\251\242\232/(/g;
	$b =~ s/\274\242\232/</g;
	$b =~ s/\276\242\232/>/g;
	$b =~ s/\277\242\232/?/g;
	$b =~ s/\334\242\232/\134/g;
	$b =~ s/\273\242\232/;/g;
	$b =~ s/\255\242\232/-/g;
	$b =~ s/\247\242\232/\047/g;
	$b =~ s/\257\242\232/\057/g;
	$b =~ s/\374\242\232/\174/g;
	$b =~ s/\337\242\232/\137/g;
	$b =~ s/\273\242\232/;/g;
	$b =~ s/\376\242\232/\176/g;
	$b =~ s/\373\242\232/\173/g;
	$b =~ s/\375\242\232/\175/g;
	$b =~ s/\333\242\232/\133/g;
	$b =~ s/\335\242\232/\135/g;
	$b =~ s/\272\242\232/:/g;
	$b =~ s/\254\242\232/,/g;
	$b =~ s/\242\242\232/\042/g;
   }
    print $globref "$b\n"; #output
}
if (($mode =~ /^-/) && ($mode =~ /h/)) {
    print $globref "$htmlbottom";}
close(INHANDLE);
close(OUTHANDLE);
    exit;
