%D \module
%D   [       file=syst-prm,
%D        version=1999.03.17,
%D          title=\CONTEXT\ System Macros,
%D       subtitle=Primitive Behavior,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\unprotect

%D Saved primitives are preceded by \type {\normal}, as in:

\let\normalfmtversion\fmtversion

%D When applicable, we also load the \ETEX\ source and
%D definition files.

\bgroup \obeylines

\ifx\eTeXversion\undefined

  \long\gdef\beginETEX#1\endETEX%
    {}

  \gdef\beginTEX%
    {\bgroup\obeylines\dobeginTEX}

  \gdef\dobeginTEX#1
    {\egroup}

  \global\let\endTEX\relax

\else

  \long\gdef\beginTEX#1\endTEX%
    {}

  \gdef\beginETEX%
    {\bgroup\obeylines\dobeginETEX}

%   \gdef\dobeginETEX#1
%     {\egroup\immediate\write16%
%        {system (E-TEX) : [line \the\inputlineno] \detokenize{#1}}}

  \gdef\dobeginETEX#1
    {\egroup}

  \global\let\endETEX\relax

\fi

\ifx\OmegaVersion\undefined

  \long\gdef\beginOMEGA#1\endOMEGA%
    {}

\else

  \gdef\beginOMEGA%
    {\bgroup\obeylines\dobeginOMEGA}

  \ifx\detokenize\undefined

    \gdef\dobeginOMEGA#1
      {\egroup\immediate\write16%
         {system (OMEGA) : [line \the\inputlineno] \string#1 }} % we assume an argument

  \else

    \gdef\dobeginOMEGA#1
      {\egroup\immediate\write16%
         {system (OMEGA) : [line \the\inputlineno] \detokenize{#1}}} % we assume aleph

  \fi

  \global\let\endOMEGA\relax

\fi

\ifx\XeTeXversion\undefined

  \long\gdef\beginXETEX#1\endXETEX%
    {}

\else

  \gdef\beginXETEX%
    {\bgroup\obeylines\dobeginXETEX}

  \gdef\dobeginXETEX#1
    {\egroup\immediate\write16%
       {system (XETEX) : [line \the\inputlineno] \detokenize{#1}}}

  \global\let\endXETEX\relax

\fi

\egroup

%D Let's get rid of this one:

\def\wlog#1{}

%D Just for tracing purposes we set:

\tracingstats=1

%D We don't like outer commands, and we always want access
%D to the original \type {\input} primitive.

\let\normalouter = \outer  \let\outer\relax
\let\normalinput = \input

%D We need to make sure that we start up in \DVI\ mode, so,
%D after testing for running \PDFTEX, we default to \DVI.

\ifx\pdftexversion\undefined \newcount\pdfoutput \fi \pdfoutput=0

%D To circumvent dependencies, we can postpone certain
%D initializations to dumping time, by appending them to the
%D \type {\everydump} token register.

\newtoks \everydump

\let\normaldump \dump

\def\dump{\the\everydump\normaldump}

%D Ligature prevention (for instance, ec encoding has ligatures
%D in mono spaced fonts). Alas, we need to do some testing in order
%S to get to the ptex'd one.

\def\checkpdftexprimitive #1
  {\expandafter\ifx\csname     #1\endcsname\relax
   \expandafter\ifx\csname  pdf#1\endcsname\relax
   \expandafter\ifx\csname ptex#1\endcsname\relax
     \expandafter\let\csname normal#1\endcsname            \undefined                   \else
     \expandafter\let\csname normal#1\expandafter\endcsname\csname ptex#1\endcsname \fi \else
     \expandafter\let\csname normal#1\expandafter\endcsname\csname  pdf#1\endcsname \fi \else
     \expandafter\let\csname normal#1\expandafter\endcsname\csname     #1\endcsname \fi}

\checkpdftexprimitive quitvmode
\checkpdftexprimitive noligatures
\checkpdftexprimitive setrandomseed
\checkpdftexprimitive uniformdeviate

\protect \endinput
