% This file is part of the TeluguTeX Software Package.
%Copyright (c) 1991 Lakshmankumar Mukkavilli
%
%The TeluguTeX Software Package is distributed in the hope that
%it will be useful,but WITHOUT ANY WARRANTY.  No author or distributor
%accepts responsibility to anyone for the consequences of using it
%or for whether it serves any particular purpose or works at all,
%unless he says so in writing.  Refer to the TeluguTeX Software Package
%General Public License for full details.
%
%Everyone is granted permission to copy, modify and redistribute
%the TeluguTeX Software Package, but only under the conditions described in the
%TeluguTeX Software Package General Public License.   A copy of this license is
%supposed to have been given to you along with TeluguTeX Software Package so you
%can know your rights and responsibilities.  It should be in a
%file named CopyrightLong.  Among other things, the copyright notice
%and this notice must be preserved on all copies.  
%%%%%%%%%%%%
%Since most terminals used for text entry can accept only
%english input, we have developed a transliteration scheme
%for inputting Telugu text.
%This file contains macros to process transliteration of Telugu
%in English. Most of the english letters are preempted for use
%in transliteration. What that means is that most of the letters
%are assigned special meaning. So they cannot be used for any other
%purpose. That is why we have used some meaningless names(e.g.
%\z, \zz, \zzCBF etc.). We have to make do with very few characters
%that are not used in transliteration.
%If you want to change the transliteration scheme then you should
%rewrite the macros in this file.
%***************************
%In the transliteration scheme that we use here each letter in Telugu
%is assigned one or two letter equivalents in English. while scanning
%transliterated text we can identify a letter by one character lookahead.
%Main device that is used to implement the translitaeration is concept
%of active characters. All the letters that can start a Telugu letter
%are declared as active characters. An active character is like a control
%sequence but does not need the escape character. Each active character
%could be a macro. We use this facility a great deal. We can not use 
%active characters in a control sequence(of course unless the control
%sequence is the character itself). Hence we redefine the control
%sequences that we use after defining active characters. 
\let\z=\catcode
\let\Z=\active
\let\zzzz=\futurelet
\let\zzzzzz=\def
\let\zzBJJ=\relax
\let\zBz=\endinput
\let\zzBCBB=\chardef
\let\zQB=\tracingmacros
\let\zQQB=\tracingcommands
\let\zzBBBC=\tlvoe
\let\zzBBBF=\tlvoi
\let\zzBBBJ=\tlcbm
\let\zzBBCB=\tlcbs
\let\zzBBCC=\tlvou
\let\zzBBCF=\tlcbv
\let\zzBBCJ=\tlvoy
\let\zzBBFB=\tlvoA
\let\zzBBFC=\tlvoE
\let\zzBBFF=\tlcbH
\let\zzBBFJ=\tlvoI
\let\zzBBJB=\tlvoO
\let\zzBBJC=\tlvoU
\let\zzBBJF=\tlcbY
%Following definitions refer to some rarely used symbols. These
%names are used in the input.
\let\zzBB=\tluaav
\let\zzFF=\tluaag
\let\zzBF=\tlacuo
\let\zzBJ=\tlacut
\let\zzFJ=\tlacan
\let\zzCC=\tlcbdt
\let\zzCF=\tlcbnp
\let\zzCJ=\tlcbvg
\let\zzJB=\tlccvpu
\let\zzJC=\tlccvpU
\let\zzJF=\tlccvphu
\let\zzQB=\tlccvphU
% Following three macros print a box of ink(\tlcbbb), an outline
% box(\tlcbob) and an empty box (\tlcbeb) respectively. useful for 
% for demonstration of vowel modifiers, consonant conjuncts and accents
% They basically act as a consonant base. They begin a syllable.
\let\zzJJ=\tlcbbb
\let\zzQF=\tlcbob
\let\zzQC=\tlcbeb
%
\let\zzFB=\tlptob
\let\zzFC=\tlpttb
%\let\zzQJ=\tl  %for future use
%\tleat macro does what it says. It swallows the next token. In our case
%the token is a letter.
\def\tleat#1{}%
\def\tltranslate#1#2#3{\if\noexpand\zzzzz#1#2\expandafter\tleat\else#3\fi}%
% #1 indicates the letter that can appear next.
%    if #1 does occur next then the letter is #2
%          does not occur then the letter is #3
%\tltranslate is invoked when a letter that begins two transliteration
%codes is read. This macro looks at the next letter to identify
%which Telugu letter is meant. \zzzzz contains the next character.
% For example suppose the letter 'd' is read. 'dh' and 'd' indicate
%two different letters in Telugu. When 'd' is read \zzCBF is invoked.
%'d' is declared as an active character and the macro that is named 'd'
%looks ahead (using \futurelet) and places the next character in \zzzzz.
%Then \zzCBF checks(via \tltranslate) if nextchar is 'h'.
%Following macros follow similar pattern as \zzCBF.
\def\zzBJF{\tltranslate{h}{\tluavi}{\tlvoa}}%  visarga or a
\def\zzBCF{\tltranslate{h}{\tlcbbh}{\tlcbb}}%
\def\zzBFC{\tltranslate{h}{\tlcbch}{\tlcbc}}%
\def\zzCBF{\tltranslate{h}{\tlcbdh}{\tlcbd}}%
\def\zzCFB{\tltranslate{h}{\tlcbgh}{\tlcbg}}%
\def\zzFBC{\tltranslate{h}{\tlcbjh}{\tlcbj}}%
\def\zzFCB{\tltranslate{h}{\tlcbkh}{\tlcbk}}%
\def\zzBJC{\tltranslate{x}{\tlvolx}{\tlcbl}}%
\def\zzBCJ{\tltranslate{x}{\tlcbnx}{\tlcbn}}%
\def\zzCJB{\tltranslate{w}{\tlvoow}{\tlvoo}}%
\def\zzCBJ{\tltranslate{h}{\tlcbph}{\tlcbp}}%
\def\zzJBC{\tltranslate{x}{\tlvorx}{\tlcbr}}%
\def\zzJCB{\tltranslate{h}{\tlcbth}{\tlcbt}}%
\def\zzBBB{\tltranslate{h}{\tlcbDh}{\tlcbD}}%
\def\zzBBC{\tltranslate{x}{\tlvoLx}{\tlcbL}}%
\def\zzBFF{\tltranslate{h}{\tluaas}{\tluasu}}%  arasunna or sunna
\def\zzBCC{\tltranslate{G}{\tlcbNG}{\tlcbN}}%
\def\zzCBB{\tltranslate{x}{\tlvoRx}{\tlcbR}}%
\def\zzCCB{\tltranslate{h}{\tlcbSh}{\tlcbS}}%
\def\zzCBC{\tltranslate{h}{\tlcbTh}{\tlcbT}}%
\def\zzBCB{\tltranslate{h}{\tlcbXh}{\tlvoX}}%
%
%Declare the characters used in transliteration as letters
%useful for restoring the status of the letters
%\Q is useful for using control sequences within Telugu
%text. Usage: {\Qcontrol sequence}
%If this macro is not used then the control sequence may not
%be recognised. This macro resets the catcodes of letters
%and digits..
\def\Q{%
\z`a=11 \z`b=11 \z`c=11 \z`d=11 \z`e=11 \z`g=11 \z`i=11 \z`j=11
\z`k=11 \z`l=11 \z`m=11 \z`n=11 \z`o=11 \z`p=11 \z`r=11 \z`s=11
\z`t=11 \z`u=11 \z`v=11 \z`y=11 \z`A=11 \z`D=11 \z`E=11 \z`H=11
\z`I=11 \z`L=11 \z`M=11 \z`N=11 \z`O=11 \z`R=11 \z`S=11 \z`T=11
\z`U=11 \z`X=11 \z`Y=11
\z`0=12 \z`1=12 \z`2=12 \z`3=12 \z`4=12 \z`5=12
\z`6=12 \z`7=12 \z`8=12 \z`9=12
}%
%Declare active characters
\def\QQQ{%
\z`a=\Z \z`b=\Z \z`c=\Z \z`d=\Z \z`e=\Z \z`g=\Z \z`i=\Z \z`j=\Z
\z`k=\Z \z`l=\Z \z`m=\Z \z`n=\Z \z`o=\Z \z`p=\Z \z`r=\Z \z`s=\Z
\z`t=\Z \z`u=\Z \z`v=\Z \z`y=\Z \z`A=\Z \z`D=\Z \z`E=\Z \z`H=\Z
\z`I=\Z \z`L=\Z \z`M=\Z \z`N=\Z \z`O=\Z \z`R=\Z \z`S=\Z \z`T=\Z
\z`U=\Z \z`X=\Z \z`Y=\Z
}%
%
%Following definitions are used to implement telugu/roman digits.
\def\zzBCBJ#1{\advance#1by1}% macro to increment by one
\def\zzBC{\input tlteldigits }% use this macro to switch to telugu digits
\def\zzCB{%use this macro to switch to roman digits
\z`0=12 \z`1=12 \z`2=12 \z`3=12 \z`4=12 \z`5=12
\z`6=12 \z`7=12 \z`8=12 \z`9=12}%
%
\QQQ%
%
%Next come the macros to handle active characters. There are two
%types of letters. First kind are those that identify telugu
%letters without lookahead. ( like  'a', 'e', 'i' etc) 
%Second kind are those that need to look ahead. (eg. 'b','c','d' etc.)
%Control sequence name are redefined so that no active characters
%appear within them. See the \let definitions at the start of thius file
%to understand what \zzzz, \zzzzzz mean
\zzzzzz a{\zzzz\zzzzz\zzBJF}%
\zzzzzz b{\zzzz\zzzzz\zzBCF}%
\zzzzzz c{\zzzz\zzzzz\zzBFC}%
\zzzzzz d{\zzzz\zzzzz\zzCBF}%
\zzzzzz e{\zzBBBC}%
\zzzzzz g{\zzzz\zzzzz\zzCFB}%
\zzzzzz i{\zzBBBF}%
\zzzzzz j{\zzzz\zzzzz\zzFBC}%
\zzzzzz k{\zzzz\zzzzz\zzFCB}%
\zzzzzz l{\zzzz\zzzzz\zzBJC}%
\zzzzzz m{\zzBBBJ}%
\zzzzzz n{\zzzz\zzzzz\zzBCJ}%
\zzzzzz o{\zzzz\zzzzz\zzCJB}%
\zzzzzz p{\zzzz\zzzzz\zzCBJ}%
\zzzzzz r{\zzzz\zzzzz\zzJBC}%
\zzzzzz s{\zzBBCB}%
\zzzzzz t{\zzzz\zzzzz\zzJCB}%
\zzzzzz u{\zzBBCC}%
\zzzzzz v{\zzBBCF}%
\zzzzzz y{\zzBBCJ}%
\zzzzzz A{\zzBBFB}%
\zzzzzz D{\zzzz\zzzzz\zzBBB}%
\zzzzzz E{\zzBBFC}%
\zzzzzz H{\zzBBFF}%
\zzzzzz I{\zzBBFJ}%
\zzzzzz L{\zzzz\zzzzz\zzBBC}%
\zzzzzz M{\zzzz\zzzzz\zzBFF}%
\zzzzzz N{\zzzz\zzzzz\zzBCC}%
\zzzzzz O{\zzBBJB}%
\zzzzzz R{\zzzz\zzzzz\zzCBB}%
\zzzzzz S{\zzzz\zzzzz\zzCCB}%
\zzzzzz T{\zzzz\zzzzz\zzCBC}%
\zzzzzz U{\zzBBJC}%
\zzzzzz X{\zzzz\zzzzz\zzBCB}%
\zzzzzz Y{\zzBBJF}%
