%D \module
%D   [       file=x-e-0101,
%D        version=2002.12.16,
%D          title=\EXAMPLE\ Base Files,
%D       subtitle=Status Report,
%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.
%D
%D Although \unknown\ this file may learn users a few style
%D tricks.
%D
%D \starttyping
%D texexec --use=e-0101 --pdf [--mode=error] report.exa
%D \stoptyping

% todo: all saves in e-0100 and here setups

%D Layout:

\usemodule[e-0100]

\setupwhitespace[none] \setuptabulate[before=,after=]

%D Normally we will use the \type {exa} namespace, but we
%D are tolerant:

\autoXMLnamespace[exa]

%D Reports:

\defineXMLenvironment
  [exa:report]
  {\starttext}
  {\subject{Status}
   \setups[status]
   \expanded{\doiffileelse{\XMLflush{exa:requestfile}}}
     {\subject{Request}
      \processXMLfilegrouped{\XMLflush{exa:requestfile}}}
     {}
   \expanded{\doiffileelse{\XMLflush{exa:replyfile}}}
     {\subject{Reply}
      \processXMLfilegrouped{\XMLflush{exa:replyfile}}}
     {}
   \stoptext}

\defineXMLsave [exa:time]
\defineXMLsave [exa:address]
\defineXMLsave [exa:port]
\defineXMLsave [exa:requestfile]
\defineXMLsave [exa:replyfile]
\defineXMLsave [exa:comment]

\startsetups [status]

  \starttabulate[|l|lpT|]
  \NC time     \NC \XMLflush {exa:time}        \NC \NR
  \NC address  \NC \XMLflush {exa:address}     \NC \NR
  \NC port     \NC \XMLflush {exa:port}        \NC \NR
  \NC version  \NC \contextversion             \NC \NR % we cheat a bit
  \doifsomething{\XMLflush {exa:requestfile}}
    {\NC request  \NC \XMLflush {exa:requestfile} \NC \NR}
  \doifsomething{\XMLflush {exa:replyfile}}
    {\NC reply    \NC \XMLflush {exa:replyfile}   \NC \NR}
  \NC comment \NC \XMLflush {exa:comment}      \NC \NR
  \stoptabulate

\stopsetups

%D Replies:

\defineXMLpickup
  [exa:reply]
  {\startXMLmapping[reply]\starttabulate[|l|lpT|]}
  {\stoptabulate\stopXMLmapping}

\startXMLmapping [reply]

  \defineXMLpickup [exa:result]    {\NC result    \NC} {\NC \NR}
  \defineXMLpickup [exa:status]    {\NC status    \NC} {\NC \NR}
  \defineXMLpickup [exa:comment]   {\NC comment   \NC} {\NC \NR}
  \defineXMLpickup [exa:producer]  {\NC producer  \NC} {\NC \NR}

  \defineXMLpickup [exa:computer]  {\NC computer  \NC} {\NC \NR} %%
  \defineXMLpickup [exa:timestamp] {\NC timestamp \NC} {\NC \NR} %%
  \defineXMLpickup [exa:username]  {\NC username  \NC} {\NC \NR} %%
  \defineXMLignore [exa:forwarded]

\stopXMLmapping

%D Requests:

% \defineXMLenvironment
%   [exa:request]
%   {\startXMLmapping[request]}
%   {\stopXMLmapping}

% \startXMLmapping [request]

%   \defineXMLpickup
%     [exa:application]
%     {\subsubject{Application Block}
%      \starttabulate[|l|pT|]}
%     {\stoptabulate}

%   \defineXMLpickup
%     [exa:client]
%     {\subsubject{Client Block}
%      \starttabulate[|l|pT|]}
%     {\stoptabulate}

%   \defineXMLpickup
%     [exa:server]
%     {\subsubject{Server Block}
%      \starttabulate[|l|pT|]}
%     {\stoptabulate}

%   \defineXMLpickup
%     [exa:data]
%     {\subsubject{Data Block}
%      \start
%      \veryraggedright
%      \ignorespaces}
%     {\endgraf
%      \stop}

%   \defineXMLpickup [exa:command]   {\NC command   \NC} {\NC \NR}
%   \defineXMLpickup [exa:option]    {\NC option    \NC} {\NC \NR}
%   \defineXMLpickup [exa:output]    {\NC output    \NC} {\NC \NR}
%   \defineXMLpickup [exa:filename]  {\NC filename  \NC} {\NC \NR}
%   \defineXMLpickup [exa:filelist]  {\NC filelist  \NC} {\NC \NR}
%   \defineXMLpickup [exa:archive]   {\NC archive   \NC} {\NC \NR}
%   \defineXMLpickup [exa:producer]  {\NC producer  \NC} {\NC \NR}

%   \defineXMLpickup [exa:computer]  {\NC computer  \NC} {\NC \NR}
%   \defineXMLpickup [exa:timestamp] {\NC timestamp \NC} {\NC \NR}
%   \defineXMLpickup [exa:domain]    {\NC domain    \NC} {\NC \NR}
%   \defineXMLpickup [exa:project]   {\NC project   \NC} {\NC \NR}
%   \defineXMLpickup [exa:username]  {\NC username  \NC} {\NC \NR}
%   \defineXMLignore [exa:context]
%   \defineXMLignore [exa:forwarded]
%   \defineXMLignore [exa:password]

%   \defineXMLargument
%     [exa:variable] [label=]
%    %{{\tttf\expanded{\hyphenatedurl{\XMLop{label}}}\space}}% split hack
%     {{\tttf\XMLop{label}\space}% split hack
%      \gobbleoneargument}

% \stopXMLmapping

% %%%%%%%%%%%%%%

\defineXMLenvironment
  [exa:request]
  {\start \startXMLignore \setups[request]}
  {\stopXMLignore \stop}

\startsetups [request]

  \defineXMLpickup
    [exa:application]
    {\subsubject{Application Block}}
    {\setups[request:flush]}

  \defineXMLpickup
    [exa:client]
    {\subsubject{Client Block}}
    {\setups[request:erase]
     \setups[request:flush]}

  \defineXMLpickup
    [exa:server]
    {\subsubject{Server Block}}
    {\setups[request:erase]
     \setups[request:flush]}

  \defineXMLpickup
    [exa:data]
    {\subsubject{Data Block}
     \start
     \veryraggedright
     \ignorespaces}
    {\endgraf
     \stop}

   \defineXMLargument
     [exa:variable] [label=]
     {{\tttf\XMLop{label}\space}% split hack
      \gobbleoneargument}

  \defineXMLsave [exa:command]
  \defineXMLsave [exa:option]
  \defineXMLsave [exa:output]
  \defineXMLsave [exa:filename]
  \defineXMLsave [exa:filelist]
  \defineXMLsave [exa:archive]
  \defineXMLsave [exa:producer]

  \defineXMLsave [exa:computer]
  \defineXMLsave [exa:timestamp]
  \defineXMLsave [exa:domain]
  \defineXMLsave [exa:project]
  \defineXMLsave [exa:username]

  \startlocalsetups[request:erase]

    \XMLerase {exa:filename}
    \XMLerase {exa:filelist}

  \stoplocalsetups

  \startlocalsetups[request:flush]

    \starttabulate[|l|lpT|]

      \doifsomething {\XMLflush{exa:command}}   {\NC command   \NC \XMLflush{exa:command}   \NC \NR}
      \doifsomething {\XMLflush{exa:option}}    {\NC option    \NC \XMLflush{exa:option}    \NC \NR}
      \doifsomething {\XMLflush{exa:output}}    {\NC output    \NC \XMLflush{exa:output}    \NC \NR}
      \doifsomething {\XMLflush{exa:filename}}  {\NC filename  \NC \XMLflush{exa:filename}  \NC \NR}
      \doifsomething {\XMLflush{exa:filelist}}  {\NC filelist  \NC \XMLflush{exa:filelist}  \NC \NR}
      \doifsomething {\XMLflush{exa:archive}}   {\NC archive   \NC \XMLflush{exa:archive}   \NC \NR}
      \doifsomething {\XMLflush{exa:producer}}  {\NC producer  \NC \XMLflush{exa:producer}  \NC \NR}

      \doifsomething {\XMLflush{exa:computer}}  {\NC computer  \NC \XMLflush{exa:computer}  \NC \NR}
      \doifsomething {\XMLflush{exa:timestamp}} {\NC timestamp \NC \XMLflush{exa:timestamp} \NC \NR}
      \doifsomething {\XMLflush{exa:domain}}    {\NC domain    \NC \XMLflush{exa:domain}    \NC \NR}
      \doifsomething {\XMLflush{exa:project}}   {\NC project   \NC \XMLflush{exa:project}   \NC \NR}
      \doifsomething {\XMLflush{exa:username}}  {\NC username  \NC \XMLflush{exa:username}  \NC \NR}

    \stoptabulate

  \stoplocalsetups

\stopsetups

%D The file:

\processXMLfile{\inputfilename} % \processXMLfile{report.exa}
