%D \module
%D   [     file=t-module-catcodes,
%D      version=2011.12.17,
%D        title=\CONTEXT\ User Module,
%D     subtitle=Module Catcodes,
%D       author=Aditya Mahajan,
%D         date=\currentdate,
%D    copyright=Aditya Mahajan,
%D        email=adityam <at> ieee <dot> org,
%D      license=Simplified BSD License]
%D
%D  MkII and MkIV use different names and values for commonly used catcode
%D  tables. So, I define a private copy of the catcode tables that are needed
%D  by the filter and vim modules.


\writestatus{loading}{Module Catcodes (ver: 2011.12.17)}

\startmodule    [module-catcodes]

\newcatcodetable   \modulecatcodes
\startcatcodetable \modulecatcodes % same as \prtcatcodes
    \catcode\tabasciicode       \spacecatcode
    \catcode\endoflineasciicode \endoflinecatcode
    \catcode\formfeedasciicode  \endoflinecatcode
    \catcode\spaceasciicode     \spacecatcode
    \catcode\endoffileasciicode \ignorecatcode
    \catcode\circumflexasciicode\superscriptcatcode
%   \catcode\underscoreasciicode\subscriptcatcode
    \catcode\underscoreasciicode\lettercatcode
    \catcode\ampersandasciicode \alignmentcatcode
    \catcode\backslashasciicode \escapecatcode
    \catcode\leftbraceasciicode \begingroupcatcode
    \catcode\rightbraceasciicode\endgroupcatcode
    \catcode\dollarasciicode    \mathshiftcatcode
    \catcode\hashasciicode      \parametercatcode
    \catcode\commentasciicode   \commentcatcode
    \catcode`\@                 \lettercatcode
    \catcode`\!                 \lettercatcode
    \catcode`\?                 \lettercatcode
    \catcode\tildeasciicode     \activecatcode
    \catcode\barasciicode       \activecatcode
\stopcatcodetable

\def\unprotectmodulecatcodes
    {\pushcatcodetable 
     \setcatcodetable\modulecatcodes}

\def\protectmodulecatcodes
    {\popcatcodetable}

\unprotectmodulecatcodes

%D The following catcode tables are used for reading
%D and writing to files

\newcatcodetable \externalfilter@read_catcodes
\newcatcodetable \externalfilter@minimal_catcodes
\newcatcodetable \externalfilter@verb_catcodes

\startcatcodetable \externalfilter@read_catcodes % same as typcatcodesa
    \catcode\tabasciicode        = \othercatcode
    \catcode\endoflineasciicode  = \othercatcode
    \catcode\formfeedasciicode   = \othercatcode
    \catcode\spaceasciicode      = \othercatcode
    \catcode\endoffileasciicode  = \othercatcode
    \catcode\leftbraceasciicode  = \begingroupcatcode
    \catcode\rightbraceasciicode = \endgroupcatcode
\stopcatcodetable

\startcatcodetable \externalfilter@minimal_catcodes % for reading t-vim output
    \catcode\backslashasciicode  = \escapecatcode
    \catcode\leftbraceasciicode  = \begingroupcatcode  
    \catcode\rightbraceasciicode = \endgroupcatcode
    \catcode\endoflineasciicode  = \activecatcode
    \catcode\formfeedasciicode   = \activecatcode
    \catcode\spaceasciicode      = \activecatcode
\stopcatcodetable 

\startcatcodetable \externalfilter@verb_catcodes % same as vrbcatcodes
    \catcode\tabasciicode       = \othercatcode
    \catcode\endoflineasciicode = \othercatcode
    \catcode\formfeedasciicode  = \othercatcode
    \catcode\spaceasciicode     = \othercatcode
    \catcode\endoffileasciicode = \othercatcode
\stopcatcodetable



\ifdefined \activeendoflinetoken \else
    % from catc-ini.mkiv
    \bgroup
        \catcode \tabasciicode       \activecatcode  \gdef\activetabtoken      {^^I}
                                                     \gdef\outputnewlinechar   {^^J}
        \catcode \formfeedasciicode  \activecatcode  \gdef\activeformfeedtoken {^^L}
        \catcode \endoflineasciicode \activecatcode  \gdef\activeendoflinetoken{^^M}
    \egroup
\fi

\protectmodulecatcodes
\stopmodule
