#!/usr/bin/perl

# Convert ISCII 1991 text to CSX
# Thanks to Antoine Leca for corrections and improvements

$cons = "[kKgGcCjJtTdDnpPbBmyrlvsh]";

while (<>) {
   #
   # Force single-char representation (so we can use tr)
   #
   s///g;					# Avagraha
   s///g;					# Long vocalic r (matra)
   s///g;					# Vocalic l (matra)
   s///g;					# Long vocalic l (matra)
   s///g;					# Long vocalic r (initial)
   s///g;					# Vocalic l (initial)
   s///g;					# Long vocalic l (initial)
   #
   # Ignore unknown chars
   #
   s/[竮]//g;
   s///g;					# remaining nuktas
   #
   # Now do the conversion
   #
   tr[泴آ]
     [iueokKgGcCjJtTdDnpPbBmyrlvshaiueo'.];
   #
   # Inherent a
   #
   s/($cons)(?!([iueo]|([^iueo]|$)))/$1a/g;
   s///g;					# halant
   #
   # Clean up
   #
   s/([KGCJTDPB])/\l$1h/g;
   s//h/g;
   s//h/g;
   s//ai/g;
   s//au/g;
   s/'/'/g;
   print;
}
