%D \module
%D   [       file=core-var,
%D        version=1998.02.21,
%D          title=\CONTEXT\ Core Macros,
%D       subtitle=Variables,
%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. 

\writestatus{loading}{Context Core Macros / Variables}

\unprotect

%D \macros 
%D   {every...}
%D
%D A few every's. 

\newevery \everyshipout        \relax
\newevery \everybeforeshipout  \relax
\newevery \everyaftershipout   \relax
\newevery \everylastshipout    \relax
\newevery \everybye            \relax   
\newevery \everygoodbye        \relax   
\newevery \everystarttext      \relax
\newevery \everystoptext       \relax
\newevery \everyforgetall      \relax

\newevery \everybeforepagebody \relax
\newevery \everyafterpagebody  \relax

\let \everypagebody \everybeforepagebody % backward compatible 

\newevery \everybeforeutilityread \relax 
\newevery \everyafterutilityread  \relax 

\newevery \everycleanupfeatures   \relax

\def\cleanupfeatures{\the\everycleanupfeatures}

\newevery \everyinsidefloat \relax

%D \macros 
%D   {trialtypesetting} 
%D
%D We disable trial typesetting in the output routine, 
%D just to be sure. 

\prependtoks 
  \trialtypesettingfalse
\to \everybeforepagebody 

%D \macros 
%D   {starttextdata}

\newtoks \collectedtextdata

\long\def\starttextdata#1\stoptextdata
  {\doglobal\appendtoks#1\to\collectedtextdata}

\def\flushtextdata
  {\vsmash{\the\collectedtextdata}%
   \global\collectedtextdata\emptytoks
   \globallet\flushtextdata\donothing}

%D \macros 
%D   {ifprocessingXML}
%D
%D We need this one even if no \XML\ is supported.  

\newif\ifprocessingXML

%D \macros
%D   {ifproductionrun}
%D
%D This boolean can be used to bypass certain 
%D initializations. 

\newif\ifproductionrun 

\appendtoks \productionruntrue \to \everydump

%D \macros 
%D   {everyboxedcontent, ifboxedcontent,
%D    startboxedcontent, stopboxedcontent}
%D
%D This one is relatively new and will be used as a more 
%D robust test for inner situations. 

\newif    \ifboxedcontent
\newevery \everyboxedcontent \relax

\appendtoks \boxedcontenttrue \to \everyboxedcontent

\def\startboxedcontent{\bgroup\the\everyboxedcontent}
\let\stopboxedcontent  \egroup

%D \macros 
%D   {fastmode}
%D
%D The command \type {\fastmode} disables some time consuming 
%D typesetting. 

\newevery \everyfastmode \relax

\newif\iffastmode 

\def\fastmode
  {\fastmodetrue 
   \the\everyfastmode}

\def\silentmode % ook hier \everysilentmode net als \fastmode
  {\showmessagesfalse
   \showwarningsfalse
   \let\writestatus\gobbletwoarguments}

%D \macros 
%D   {pdfoutput}
%D
%D There are some fundamental differences between producing
%D \DVI\ and \PDF\ output, especially when we use \PDFTEX, like
%D object reuse, one pass graphic inclusion and the lack of a
%D postprocessing stage. Because we must make sure that
%D \CONTEXT\ knows what it's up to, we always default to \DVI\
%D mode, even when users explicitly ask for \PDF\ output in the
%D \PDFTEX\ configuration file. 

\ifx\pdfoutput\undefined \else

  \prependtoks \pdfoutput=0 \to \everyjob 

\fi

%D \macros
%D   {setvariables,getvariable}
%D
%D \starttyping 
%D \setvariables[xx][titel=]
%D \setvariables[xx][titel=test test]
%D \setvariables[xx][titel=test $x=1$ test]   % fatal error reported
%D \setvariables[xx][titel=test {$x=1$} test]
%D \setvariables[xx][titel]                   % fatal error reported
%D \setvariables[xx][titel=e]
%D \stoptyping 

\def\??vars{@@vars}

\def\setvariables {\dotripleargument\dosetvariables[\getrawparameters ]}
\def\setevariables{\dotripleargument\dosetvariables[\getraweparameters]}
\def\setgvariables{\dotripleargument\dosetvariables[\getrawgparameters]}
\def\setxvariables{\dotripleargument\dosetvariables[\getrawxparameters]}

\def\globalsetvariables % obsolete 
  {\dotripleargument\dosetvariables[\globalgetrawparameters]}

\def\dosetvariables[#1][#2][#3]%
  {\errorisfataltrue
   \def\currentvariableclass{#2}%
   #1[\??vars:#2:][#3]%
   \errorisfatalfalse}

\beginTEX

\def\getvariable#1#2% to be sped up
  {\csname
     \ifundefined{\??vars:#1:#2}\s!empty\else\??vars:#1:#2\fi
   \endcsname}

\endTEX

\beginETEX \ifcsname

\def\getvariable#1#2% to be sped up
  {\csname
     \ifcsname\??vars:#1:#2\endcsname\??vars:#1:#2\else\s!empty\fi
   \endcsname}

\endETEX

\def\showvariable#1#2%
  {\showvalue{\ifundefined{\??vars:#1:#2}\s!empty\else\??vars:#1:#2\fi}}

\let\currentvariableclass\empty

%D We store some original meanings, maybe in \type 
%D {math-ini}. 

\let\normalin             \in
\let\normalover           \over
\let\normalabove          \above
\let\normalatop           \atop
\let\normaloverwithdelims \overwithdelims
\let\normalabovewithdelims\abovewithdelims
\let\normalatopwithdelims \atopwithdelims

%D Add-ons: 

\let\startlayoutcomponent\gobbletwoarguments
\let\stoplayoutcomponent \relax

\protect \endinput
