#!/usr/bin/perl -w

## 
# This script converts text with text in SLP1 and formatting codes of the
# type {st ...} (as described in Embed.pm) into an RTF document with Sanskrit
# text in Manjushree CSX. Text flagged with {sd ...} is output in Devanagari,
# using Peter Freund's Vedic font.
#
# 2006-10-09 by mdh
##

use Sanskrit::Embed;

my $lf = "\n";

my $prolog = '{\rtf1\mac\ansicpg10000' . '{\fonttbl\f0\froman\fcharset77 Times-Roman;\f1\fnil\fcharset77 ManjushreeCSX;\f2\fnil\fcharset77 Vedic;' . $lf . '}' . $lf . '{\colortbl;\red255\green255\blue255;}' . $lf . '\margl1440\margr1440\vieww22080\viewh16120\viewkind0' . $lf . '\pard\ql\qnatural\pardirnatural';

my $epilog = '}' . $lf;

print "Enter name of input file: ";
my $infile = <STDIN>; chomp $infile;
open IN, $infile or die "$0: couldn't open $infile\n";

print "Enter name for output file: ";
my $outfile = <STDIN>; chomp $outfile;
open OUT, ">$outfile" or die "$0: couldn't open $outfile\n";

print OUT $prolog;

while (<IN>) {
    $_ = embed_X($_);
    s/\\(?!')/\\\\/g;
    s/\{v/{\\f2\\fs48/g;
    s/\{ci/{\\f1\\i/g;
    s/\{c/{\\f1/g;
    s/\{(?:bi|ib)/{\\b\\i/g;
    s/\{([bi])/{\\$1/g;
    print OUT "\\f0 $_\\par";
}

print OUT $epilog;
close OUT; close IN;

