%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% casyltex.sty  (CASylTeX:  Macros for Cree/Inuktitut)
% 15 September 2007
% Version 2.00
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ivan A Derzhanski
% Department of Mathematical Linguistics
% Institute for Mathematics and Computer Science
% Bulgarian Academy of Sciences
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \CASylTeX {C{\sc a}Syl\TeX }

\font \syll@fount=casyll10

\newcount \s@ll
\newcount \w@ll
\newcount \z@ll
\newcount \r@lett
\newcount \T@lett
\def \Rone {\r@lett=114} \Rone
\def \Rtwo {\r@lett=123}
\def \Tone {\T@lett=117} \Tone
\def \Ttwo {\T@lett=120}
\def \Zone {\z@ll=0} \Zone
\def \Ztwo {\z@ll=32}
\newif \ifwfront \wfrontfalse
\chardef \cree@h="08

\def \syll@write {\relax
 \ifnum \s@ll=96%
   \ifnum \w@ll=1w\fi
 \else \ifnum 128>\s@ll \advance \s@ll by-\z@ll \fi
   \ifnum \w@ll=1%
     \ifwfront W\symbol {\s@ll }%
     \else \symbol {\s@ll }W%
     \fi
   \else \symbol {\s@ll }%
   \fi
 \fi
 \s@ll=96\w@ll=0}

\def \syll@long {%
  \ifnum \w@ll=1%
    \ifwfront W\symbol {\s@ll}\llap'%
    \else \symbol {\s@ll}\llap'W%
    \fi
  \else \symbol {\s@ll}\llap'%
  \fi
% \symbol {\s@ll}\llap'%
%   \ifnum \w@ll=1W\fi
 \s@ll=96\w@ll=0}

\expandafter \def \csname syll@'\endcsname {%
 \ifnum \s@ll=96%
   \ifnum \w@ll=1w\w@ll=0\fi
 \else \syll@long
 \fi }

\def \if@syll@write {\ifnum 127<\s@ll \syll@write \fi}

\def \syll@A {\if@syll@write \advance \s@ll by128\syll@long }
\def \syll@E {\if@syll@write \advance \s@ll by32\syll@long }
\def \syll@I {\if@syll@write \advance \s@ll by64\syll@long }
\def \syll@O {\if@syll@write \advance \s@ll by96\syll@long }
\def \syll@U {\if@syll@write \advance \s@ll by96\syll@long }

\def \syll@a {\if@syll@write \advance \s@ll by128}
\def \syll@e {\if@syll@write \advance \s@ll by32}
\def \syll@i {\if@syll@write \advance \s@ll by64}
\def \syll@o {\if@syll@write \advance \s@ll by96}
\def \syll@u {\if@syll@write \advance \s@ll by96}

\def \syll@@ {\syll@write  \s@ll=96}
\def \syll@c {\syll@write  \s@ll=99}
\def \syll@f {\syll@write \s@ll=113}
\def \syll@g {\syll@write  \s@ll=99}
\def \syll@h {\syll@write \cree@h}
\def \syll@j {\syll@write \s@ll=121}
\def \syll@k {\syll@write \s@ll=107}
\def \syll@K {\syll@write  \s@ll=11}
\def \syll@l {\syll@write \s@ll=108}
\def \syll@L {\syll@write \s@ll=100}
\def \syll@m {\syll@write \s@ll=109}
\def \syll@M {\syll@write  \s@ll=13}
\def \syll@n {\syll@write \s@ll=110}
\def \syll@p {\syll@write \s@ll=112}
\def \syll@q {%
  \syll@write
  \s@ll=114\advance \s@ll by-\z@ll
  \symbol {\s@ll}\s@ll=107}
\def \syll@r {\syll@write \s@ll=\r@lett }
\def \syll@R {\syll@write \ifnum \r@lett=114\s@ll=123\else \s@ll=114\fi }
\def \syll@s {\syll@write \s@ll=115}
\def \syll@S {\syll@write \s@ll=102}
\def \syll@t {\syll@write \s@ll=116}
\def \syll@T {\syll@write \s@ll=\T@lett }
\def \syll@v {\syll@write \s@ll=113}
\def \syll@x {\syll@write  \s@ll=24}
\def \syll@y {\syll@write \s@ll=121}

\def \syll@N {\syll@write
  \s@ll=110\advance \s@ll by-\z@ll \raise .24ex\hbox {\symbol {\s@ll}}%
\kern-.15em%
  \s@ll=99 \advance \s@ll by-\z@ll \lower .24ex\hbox {\symbol {\s@ll}}%
  \s@ll=96}

\def \syll@w {%
  \ifnum 127<\s@ll \syll@write \fi
  \w@ll=1}

\long \def \@syll #1{%
 \ifx #1\end \syll@write \let \next \end
 \else \ifcat \noexpand #1\par
   \syll@write #1\def \next {\futurelet \n@xt \@syll }%
 \else \ifx \@sptoken \n@xt
     \syll@write \relax \space \s@ll=96\w@ll=0%
 \else \ifx .\n@xt
     \syll@write \relax .\s@ll=96\w@ll=0\fi\fi
   \csname syll@#1\endcsname
   \def \next {\futurelet \n@xt \@syll }%
 \fi\fi \next }

\def \syllab {% Cree/Inuktitut environment
  \syll@fount
  \s@ll=96%
  \w@ll=0%
  \@syll }

\def \endsyllab {}

\def \sylla #1{\begin{syllab}#1\end{syllab}}
