%D \module
%D   [       file=syst-ltx,
%D        version=2009.10.13,
%D          title=\CONTEXT\ System Macros,
%D       subtitle=General,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%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 The bib module assumes that sometimes this command is used but
%D in \MKIV\ we no longer assume that.
%D
%D \macros
%D   {newcommand}
%D
%D This module replaces \type {t-bibltx} and implements the
%D \LATEX\ newcommand (sort of). This command is not to be
%D used directly but only is there for the occasional
%D \BIBTEX\ file that uses it.
%D
%D \starttyping
%D \newcommand\oeps             {oeps}
%D \newcommand\oeps[6]          {oeps[#1]#6}
%D \newcommand\oeps[6][whatever]{oeps[#1]#6}
%D \stoptyping

\unprotect

\def\newcommand#1%
  {\dotripleempty\donewcommand[#1]}

\def\donewcommand
  {\ifthirdargument
     \expandafter\donewcommandtwo
   \else\ifsecondargument
     \expandafter\expandafter\expandafter\donewcommandone
   \else
     \expandafter\expandafter\expandafter\donewcommandzero
   \fi\fi}

\def\donewcommandzero[#1][#2][#3]%
  {\long\def#1}

\def\donewcommandone[#1][#2][#3]%
  {\scratchtoks{\long\def#1}%
   \dorecurse{#2}{\scratchtoks\expandafter{\the\scratchtoks######1}}%
   \the\scratchtoks}

\def\donewcommandtwo[#1][#2][#3]%
  {\long\def#1{\doifnextcharelse[{\getvalue{>>\string#1>>}}{\getvalue{>>\string#1>>}[#3]}}%
   \scratchtoks{\long\setvalue{>>\string#1>>}[##1]}%
   \dostepwiserecurse{2}{#2}{1}{\scratchtoks\expandafter{\the\scratchtoks######1}}%
   \the\scratchtoks}

\protect \endinput
