% This is the file CNS.chr of the CJK package
%   for using asiatic logographs (Chinese/Japanese/Korean) with LaTeX2e
%
% created by Werner Lemberg <a7621gac@awiuni11.bitnet>
%
% Version 2.5 (10-Apr-1995)

\def\fileversion{2.5}
\def\filedate{1995/04/10}
\ProvidesFile{CNS.chr}[\filedate\space\fileversion]


% define macros for handling CNS subfonts and characters.

\def\CNS@ch#1#2#3{
  {\ifnum #3 < \CNS@min
     \CJK@errx
   \else
     \ifnum #3 > \CNS@max
       \CJK@errx
     \else
       \CJK@testLastKern

       \@tempcnta #3
       \advance\@tempcnta #2
       \edef\CJK@plane{#1}
       \usefont{U}{\CNS@enc}{\CNS@series}{\CNS@shape}
       \symbol{\@tempcnta}
     \fi
   \fi}}

% the same, but the plane crosses the font file boundary.

\def\CNS@chx#1#2#3#4{
  {\ifnum #4 < \CNS@min
     \CJK@errx
   \else
     \ifnum #4 > \CNS@max
       \CJK@errx
     \else
       \CJK@testLastKern

       \@tempcnta #4
       \@tempcntb 256
       \advance\@tempcnta #3
       \advance\@tempcntb -#3
       \chardef\@temp \@tempcntb
       \ifnum #4 < \@temp
         \edef\CJK@plane{#1}
         \usefont{U}{\CNS@enc}{\CNS@series}{\CNS@shape}
         \symbol{\@tempcnta}
       \else
         \advance\@tempcnta -256
         \edef\CJK@plane{#2}
         \usefont{U}{\CNS@enc}{\CNS@series}{\CNS@shape}
         \symbol{\@tempcnta}
       \fi
     \fi
   \fi}}

% for punctuation.

\def\CNS@punctch#1#2#3#4{
  {\ifnum #4 < \CNS@min
     \CJK@errx
   \else
     \ifnum #4 > \CNS@max
       \CJK@errx
     \else
       \CJK@numbToHex{\CNS@temp}{#4}
       \CJK@ifNotPostPunct{\CNS@enc}{#1}{\CNS@temp}
         \CJKglue
       \fi

       \@tempcnta #4
       \advance\@tempcnta #3
       \edef\CJK@plane{#2}
       \usefont{U}{\CNS@enc}{\CNS@series}{\CNS@shape}
       \symbol{\@tempcnta}

       \CJK@ifNotPrePunct{\CNS@enc}{#1}{\CNS@temp}
       \else
         \CJK@kern
       \fi
     \fi
   \fi}}

% for Big 5 encoded characters in plane `0'

\def\CNS@BigFivech#1#2{
  {\ifnum "0#1 < \CNS@BigFiveFirstMin
     \CJK@err
   \else
     \ifnum "0#1 > \CNS@BigFiveFirstMax
        \CJK@err
     \else
       \ifnum #2 < \CNS@BigFiveSecondMin
         \CJK@errx
       \else
         \ifnum #2 > \CNS@BigFiveSecondMax
           \CJK@errx
         \else
           \CJK@numbToHex{\CJK@temp}{#2}
           \CJK@ifNotPostPunct{Bg5}{#1}{\CJK@temp}
             \CJKglue
           \fi

           \@tempcnta "0#1
           \@tempcntb #2
           \advance\@tempcnta -161
           \ifnum #2 < 161
             \advance\@tempcntb -64
           \else
             \advance\@tempcntb -98
           \fi
           \multiply\@tempcnta 157
           \advance\@tempcnta \@tempcntb

           \@tempcntb \@tempcnta
           \divide\@tempcnta 256
           {\advance\@tempcnta 1
            \CJK@numbToHex{\CNS@temp}{\@tempcnta}}
           \multiply\@tempcnta 256
           \advance\@tempcntb -\@tempcnta

           \edef\CJK@plane{\CNS@temp}
           \usefont{U}{Bg5}{\CNS@BigFiveSeries}{\CNS@BigFiveShape}
           \symbol{\@tempcntb}

           \CJK@ifNotPrePunct{Bg5}{#1}{\CJK@temp}
           \else
             \CJK@kern
           \fi
         \fi
       \fi
     \fi
   \fi}}

\endinput
