%D \module
%D   [       file=char-ini,
%D        version=2006.08.20,
%D          title=\CONTEXT\ Character Macros,
%D       subtitle=Character Support (Initialization),
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright=PRAGMA]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{Character Support (initialization)}

\registerctxluafile{char-def}{1.001} % let's load this one first
\registerctxluafile{char-ini}{1.001}
\registerctxluafile{char-cmp}{1.001} % maybe we will load this someplace else
\registerctxluafile{char-tok}{1.001} % maybe we will load this someplace else
\registerctxluafile{char-map}{1.001}
\registerctxluafile{char-syn}{1.001}

\unprotect

% \def\checkedchar#1% #2%
%   {\relax\iffontchar\font#1 \expandafter\firstoftwoarguments\else\expandafter\secondoftwoarguments\fi{\char#1}}
%
% impossible in math mode so there always fallback (till we have gyre):

\def\utfchar          #1{\ctxlua{tex.uprint(\number#1)}}
\def\checkedchar        {\relax\ifmmode\expandafter\checkedmathchar\else\expandafter\checkedtextchar\fi} % #1#2
\def\checkedmathchar#1#2{#2}
\def\checkedtextchar  #1{\iffontchar\font#1 \expandafter\firstoftwoarguments\else\expandafter\secondoftwoarguments\fi{\char#1}}
\def\setcclcuc #1 #2 #3 {\global\catcode#1=11 \global\lccode #1=#2 \global\uccode #1=#3 }

%D The codes are stored in the format, so we don't need to reinitialize
%D them (unless of course we have adapted the table).

\ctxlua{characters.setcodes()}

% obsolete
%
% \startruntimeluacode
%   \ctxlua{characters.setpdfunicodes()}% pdftounicode mappings can only be done runtime
% \stopruntimeluacode

%D There may be a problem with the turkisch patterns. By now it's taken care of in
%D ctxtools (thanks to Mojca). There seems to be a bug in the patterns (^^11 refers
%D to a double quote but it should be ^^19 since the original is in ec encoding).

% \setcclcuc "201C "201C "201C
% \setcclcuc "201D "201D "201D

% definitions

\startruntimectxluacode
    characters.context.rehash()
\stopruntimectxluacode

% \ctxlua{characters.context.rehash()}

\ctxlua {
    characters.context.define(
        {   % letter catcodes
            \number\texcatcodes,
            \number\ctxcatcodes,
            \number\notcatcodes,
            \number\mthcatcodes,
            \number\vrbcatcodes,
            \number\prtcatcodes,
            \number\xmlcatcodesn,
            \number\xmlcatcodese,
            \number\xmlcatcodesr,
            \number\typcatcodesa,
            \number\typcatcodesb,
        },
        {   % activate catcodes
            \number\ctxcatcodes,
            \number\notcatcodes,
            \number\xmlcatcodesn,
            \number\xmlcatcodese,
            \number\xmlcatcodesr,
        }
    )
}

\protect \endinput

% \ctxlua{characters.context.show(123)}
% \ctxlua{characters.context.show(0x7B)}
% \ctxlua{characters.context.show("7B")}

% \dostepwiserecurse{`A}{`Z}{1}
%   {\ctxlua{characters.context.show(\recurselevel)}}
