%D \module
%D   [       file=core-mar,
%D        version=1997.03.31,
%D          title=\CONTEXT\ Core Macros,
%D       subtitle=Markings,
%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 / Markings}

\unprotect 

% voor 'interne' doeleinden zijn beschikbaar:
%
%   \fetchmark[naam][plaats]

% nog expansie in hoofdmarkering

% ook nog reset koppelen aan sectie

\def\hoofdmarkering#1%
  {\getvalue{\??mk#1\c!koppeling}}

\def\dodoresetmarkering#1%
  {\doifdefined{\??mk\hoofdmarkering{#1}}
     {\expandafter\resetmark\csname\??mk\hoofdmarkering{#1}\endcsname}}

\def\doresetmarkering[#1]%
  {\processcommalist[#1]\dodoresetmarkering}

\def\resetmarkering%
  {\dosingleargument\doresetmarkering}

\def\dostelmarkeringin[#1][#2]%
  {\getparameters[\??mk#1][#2]}

\def\stelmarkeringin%
  {\dodoubleargument\dostelmarkeringin}

\letvalue{\??mk \v!vorige}\gettopmark
\letvalue{\??mk \v!eerste}\getfirstmark
\letvalue{\??mk\v!laatste}\getbotmark

\def\dododefinieermarkering[#1][#2]%
  {\stelmarkeringin[#1]
     [% \c!expansie=\v!nee,  % saves a macro
        \c!scheider={ --- }, % watch the spaces
          \c!status=\v!start]%
   \ontkoppelmarkering[#1]%  % no coupling with sections
   \setevalue{\??mk#1\c!koppeling}{#2}%
   \expandafter\newmark\csname\??mk#2\endcsname
   \showmessage{\m!systems}{13}{#1,[#2]}}

\def\dodefinieermarkering[#1][#2]%
  {\doifelsenothing{#2}
     {\dododefinieermarkering[#1][#1]}
     {\dododefinieermarkering[#1][#2]}}

\def\definieermarkering%
  {\dodoubleempty\dodefinieermarkering}

\let\geenmarkering=\relax

%\def\fetchmark[#1][#2]% geen \def, anders problemen in \doif...
%   {\def\dofetchmark{\getvalue{\??mk#2}}%
%    \expandafter\dofetchmark\csname\??mk\hoofdmarkering{#1}\endcsname}

\def\dofetchmark#1#2% needed because we need to expand
  {\getvalue{\??mk#2}#1}

\def\fetchmark[#1][#2]% never \unexpanded
 %{\getvalue{\getvalue{\??mk#2}\??mk\hoofdmarkering{#1}}}
  {\expandafter\dofetchmark\csname\??mk\hoofdmarkering{#1}\endcsname{#2}}

\def\fetchtwomarks[#1]%
  {\doifsomething{\fetchmark[#1][\v!eerste]}
     {\fetchmark[#1][\v!eerste]%
      \doifsomething{\fetchmark[#1][\v!laatste]}
        {\doifnot{\fetchmark[#1][\v!eerste]}{\fetchmark[#1][\v!laatste]}
            {\getvalue{\??mk#1\c!scheider}\fetchmark[#1][\v!laatste]}}}}

\def\fetchallmarks[#1]%
  {\doifsomething{\fetchmark[#1][\v!eerste]}
     {\doifsomething{\fetchmark[#1][\v!vorige]}
        {\doifnot{\fetchmark[#1][\v!vorige]}{\fetchmark[#1][\v!eerste]}
           {\fetchmark[#1][\v!vorige]\getvalue{\??mk#1\c!scheider}}}}%
      \fetchtwomarks[#1]}

\def\dohaalmarkering[#1][#2]%
  {\doifvalue{\??mk#1\c!status}{\v!start}
     {\bgroup
      \def\geenmarkering##1{\unknown\ }%
      \setfullsectionnumber{\??mk#1}%
      \processaction
        [#2]
        [  \v!beide=>{\fetchtwomarks[#1]},
           \v!alles=>{\fetchallmarks[#1]},
         \s!default=>{\fetchmark[#1][\v!eerste]},
         \s!unknown=>{\fetchmark[#1][#2]}]%
      \egroup}}

\def\nohaalmarkering[#1][#2]%
  {}

\unexpanded\def\haalmarkering%
  {\dodoubleargument\dohaalmarkering}

\def\domarking[#1]#2%
  {\bgroup
   \doifelsevalue{\??mk#1\c!expansie}{\v!ja}
     {\expandmarkstrue}
     {\expandmarksfalse}%
% \honorunexpanded 
%   \getvalue{\??mk\hoofdmarkering{#1}}{#2}%
   \expandafter\setmark\csname\??mk\hoofdmarkering{#1}\endcsname{#2}%
   \egroup}

\def\marking%
  {\dosingleargument\domarking}

\protect \endinput
