%D \module
%D   [      file=x-e-0000,
%D        version=2002.06.23,
%D          title=\EXAMPLE\ Base Files,
%D       subtitle=Request handler,
%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.

%D This is experimental code. Don't change it, don't rely on
%D this interface remaining the same, don't use tricks used
%D here but not described in manuals, so: assume that this
%D file does not exists.

% todo: \getEXAfilename{...}

%D Main structure

\defineXMLprocess [exa:request]
\defineXMLignore  [exa:reply]
\defineXMLignore  [exa:environment]
\defineXMLignore  [exa:process]

%D substructure

% \defineXMLprocess [exa:application]
% \defineXMLprocess [exa:client]
% \defineXMLprocess [exa:server]

\defineXMLenvironment [exa:application] \startXMLignore \stopXMLignore
\defineXMLenvironment [exa:client]      \startXMLignore \stopXMLignore
\defineXMLenvironment [exa:server]      \startXMLignore \stopXMLignore

%D info

% \defineXMLgsave  [exa:command]
% \defineXMLgsave  [exa:option]
% \defineXMLgsave  [exa:archive]

\defineXMLignore [exa:forwarded] % skipped anyway
\defineXMLignore [exa:comment]   % skipped anyway

\defineXMLgsave  [exa:output]
\defineXMLgsave  [exa:producer]
\defineXMLgsave  [exa:computer]
\defineXMLgsave  [exa:timestamp]
\defineXMLgsave  [exa:username]
\defineXMLgsave  [exa:filelist]
\defineXMLgsave  [exa:filename]
\defineXMLgsave  [exa:result]

%D Data

\defineXMLenvironment
  [exa:data]
  {\bgroup
   \defineXMLargument
     [exa:variable] [label=unknown]
     {\setEXAvariable{\XMLop{label}}}%
   \defineXMLsingular
     [exa:variable] [label=unknown]
     {\setEXAvariable{\XMLop{label}}{}}}
  {\egroup}

\unprotect

\def\@@exavar{@xv@}

\def\EXAtag#1{\@@exavar#1}

\def\loadEXArequest#1%
  {\processXMLfilegrouped{#1}}

\def\setEXAvariable#1#2%
  {\long\setgvalue{\@@exavar#1}{#2}}

\def\theEXAvarname#1%
  {\ifcsname\@@exavar#1\endcsname\@@exavar#1\else\s!empty\fi}

\def\getEXAvariable#1%
  {\csname\theEXAvarname{#1}\endcsname}

\def\showEXAvariable#1%
  {\showvalue{\theEXAvarname{#1}}}

\def\getEXAvariableXML#1%
  {\begingroup
   \resetXMLmapping
   \enableXML
   \scantokens\@EA\@EA\@EA{\csname\theEXAvarname{#1}\endcsname}%
%    \getEXAvariable{#1}%
   \endgroup}

\def\getEXAvariableTEX#1%
  {\begingroup
   \setnormalcatcodes
   \scantokens\@EA\@EA\@EA{\csname\theEXAvarname{#1}\endcsname}%
   \endgroup}

\def\@@doifelseEXAvariable#1#2#3#4%
  {\defconvertedvalue\!!stringa{\@@exavar#3}%
   \defconvertedargument\!!stringb{#4}%
   \ifx\!!stringa\!!stringb\@EA#1\else\@EA#2\fi}

\def\doifelseEXAvariable
  {\@@doifelseEXAvariable\firstoftwoarguments\secondoftwoarguments}

\def\doifEXAvariable
  {\@@doifelseEXAvariable\firstofoneargument\gobbleoneargument}

\def\doifnotEXAvariable
  {\@@doifelseEXAvariable\gobbleoneargument\firstofoneargument}

\def\@@doifelseEXAdefined#1#2#3%
  {\ifcsname\@@exavar#3\endcsname\@EA#1\else\@EA#2\fi}

\def\doifdefinedelseEXAvariable
  {\@@doifelseEXAdefined\firstoftwoarguments\secondoftwoarguments}

\def\doifdefinedEXAvariable
  {\@@doifelseEXAdefined\firstofoneargument\gobbleoneargument}

\def\doifundefinedEXAvariable
  {\@@doifelseEXAdefined\gobbleoneargument\firstofoneargument}

\def\loadEXAmodes#1%
 %{\readfile{#1}\donothing\donothing}
  {\processfile{#1}} % in case jobpath and runpath differ

%D Math

\def\displaymath#1{\getvalue{\e!start\v!formula}#1\getvalue{\e!stop\v!formula}}
\def\inlinemath #1{\mathematics{#1}}

\def\normalTEXtext#1%
  {\bgroup\setnormalcatcodes\scantokens{#1\ignorespaces}\egroup}

\def\displaytexmath#1{\normalTEXtext{\displaymath{#1}}}
\def\inlinetexmath #1{\normalTEXtext{\inlinemath {#1}}}

\defineXMLargument [displaytexmath] \displaytexmath
\defineXMLargument [inlinetexmath]  \inlinetexmath

\defineXMLsingular [p] \endgraf

\def\getEXAcalcmath#1% text:content
  {\doifdefinedelseEXAvariable{tex:#1}
     {\getEXAvariableXML{tex:#1}}
     {\getEXAvariableXML{tex:#1:calcmath}}}

\def\defaultEXAcontent#1% experimental
  {\ifnum\realpageno<\plustwo
     \ifdim\pagetotal>\zeropoint\else#1\fi
   \fi}

%D Filename

\let\theEXAfilename\empty
\let\theEXAfilelist\empty

\def\mainEXAfilename
  {\XMLflush{exa:filename}}

\def\mainEXAfilelist
  {\XMLflush{exa:filelist}}

\def\makeEXAfilename
  {\xdef\theEXAfilename{\XMLflush{exa:filename}}}

\def\makeEXAfilelist
  {\startnointerference
     \globallet\theEXAfilelist\empty
     \def\makeEXAfilelist##1{[##1]\doglobal\addtocommalist{##1}\theEXAfilelist}%
     \defineXMLargument[exa:entry]\makeEXAfilelist
     \enableXML\XMLflush{exa:filelist}%
   \stopnointerference}

%D Preparations

\def\prepareEXAvariables
  {\makeEXAfilename
   \makeEXAfilelist}

\protect \endinput
