% This is the file plainenc.tex of the T2 package.
%
% This file defines some commands for Plain TeX, so that it is able to
% read (and interpret accordingly) some LaTeX files (unchanged), such as
% inputenc.sty, font encoding definition files (lcyenc.def, t2aenc.def,
% etc.), and various input encoding definition files (koi8-r.def,
% cp866.def, etc.).
%
% These definitions are the `minimal' possible.  Probably, some
% extensions will be needed.

\chardef\atcatcode=\catcode`\@ \catcode`\@=11

% load definitions from BABEL's plain.def (\adddialect is now defined)
\input plain.def

\def\NeedsTeXFormat#1[#2]{}
\def\ProvidesFile#1{%
  \begingroup
    \catcode`\ 10 %
    \@ifnextchar[{\@providesfile{#1}}{\@providesfile{#1}[]}}
\def\@providesfile#1[#2]{%
    \wlog{File: #1 #2}%
    \expandafter\xdef\csname ver@#1\endcsname{#2}%
  \endgroup}
\let\ProvidesPackage\ProvidesFile % better than #1[#2] -> {}
%\def\DeclareOption#1#2{\def\@OptionBody{#2}}
%\def\ProcessOptions{\@OptionBody}
\def\DeclareOption#1#2{}
\def\ProcessOptions{}
\newlinechar`\^^J
\def\MessageBreak{^^J}

\def\PackageWarningNoLine#1#2{\immediate\write16{Package `#1' warning: #2}}
%\def\@latex@error#1{\immediate\write16{Error: #1}}
\def\@latex@info#1{\wlog{Info: #1}}

\def\DeclareFontEncoding#1#2#3{%
  \expandafter\let\csname#1-cmd\endcsname\@current@cmd
  \expandafter\let\csname#1-tmcmd\endcsname\@current@tmcmd}
\def\@current@cmd#1{%
   \ifx\protect\@typeset@protect
   \else
      \noexpand#1\expandafter\@gobble
   \fi}
\def\DeclareFontSubstitution#1#2#3#4{}
\def\DeclareErrorFont#1#2#3#4#5{}
\def\DeclareSymbolFont#1#2#3#4#5{}
\def\SetSymbolFont#1#2#3#4#5#6{}
\def\DeclareSymbolFontAlphabet#1#2{}
\def\DeclareMathAlphabet#1#2#3#4#5{}
\def\SetMathAlphabet#1#2#3#4#5#6{}
\def\DeclareMathSymbol#1#2#3#4{% simplified definition
 \count@=#4 \advance\count@ "7000 \mathchardef#1\count@}

\def\@unexpandable@protect{\noexpand\protect\noexpand}
%\let\protect\@typeset@protect

\def\protected@edef{%
   \let\@@protect\protect
   \let\protect\@unexpandable@protect
   \afterassignment\restore@protect
   \@edef
}
\def\protected@xdef{%
   \let\@@protect\protect
   \let\protect\@unexpandable@protect
   \afterassignment\restore@protect
   \@xdef
}
\def\restore@protect{\let\protect\@@protect}

\let\@edef\edef
\let\edef\protected@edef
\let\@xdef\xdef
\let\xdef\protected@xdef

% redefine \input to be compatible with LaTeX (for inputenc.sty)
\ifx\@@input\@undefined\let\@@input\input\fi
\def\input{\@ifnextchar\bgroup\@iinput\@@input}
\def\@iinput#1{\@@input#1 } % This is a simplified definition

% this is used in cyrillic encoding definition files
\def\@ifundefined#1{%
  \expandafter\ifx\csname#1\endcsname\relax
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}
\long\def\@secondoftwo#1#2{#2}

% support for uppercase/lowercase
\let\@uppercase\uppercase
\let\@lowercase\lowercase
\newtoks\@uclctoks
\DeclareRobustCommand\uppercas@{\afterassignment\upperc@se\@uclctoks}
\DeclareRobustCommand\lowercas@{\afterassignment\lowerc@se\@uclctoks}
\def\upperc@se{{%
      \def\i{I}\def\j{J}%
      \def\reserved@a##1##2{\let##1##2\reserved@a}%
      \expandafter\reserved@a\@uclclist\reserved@b{\reserved@b\@gobble}%
      \protected@edef\reserved@a{\@uppercase\expandafter{\the\@uclctoks}}%
      \reserved@a
   }}
\def\lowerc@se{{%
      \def\reserved@a##1##2{\let##2##1\reserved@a}%
      \expandafter\reserved@a\@uclclist\reserved@b{\reserved@b\@gobble}%
      \protected@edef\reserved@a{\@lowercase\expandafter{\the\@uclctoks}}%
      \reserved@a
   }}
\def\@uclclist{\oe\OE\o\O\ae\AE
      \dh\DH\dj\DJ\l\L\ng\NG\ss\SS\th\TH}
\let\org@dump\orig@dump % from plain.def
\def\orig@dump{\let\uppercase\uppercas@\let\lowercase\lowercas@\org@dump}

\let\org@write\write
\let\org@immediate\immediate
\DeclareRobustCommand\write{\afterassignment\write@a\count@}
\def\immediate#1{\ifx#1\write\def\immediate@{\org@immediate}\fi\org@immediate#1}
\let\immediate@\empty
\long\def\write@a#1{%
  \begingroup
    \let\thepage\relax
    \let\protect\@unexpandable@protect
    \@edef\reserved@a{\expandafter\noexpand\immediate@\org@write\the\count@{#1}}%
    \reserved@a
  \endgroup
  \let\immediate@\empty}

% make handling of protected commands within whatsits correct:
\let\org@shipout\shipout
\def\shipout#1#2{\begingroup\setbox0=#1{#2}\let\protect\noexpand\org@shipout\box0\endgroup}

% avoid problems in references with russian letters (e.g. in texinfo)
% (experimental code):
%\def\DeclareTextSymbol#1#2#3{%
%   \@dec@text@cmd\chardef@hack#1{#2}#3\relax
%}
%\def\chardef@hack#1#2{%
%  \bgroup
%    \lccode`\0=#2
%    \lowercase{
%  \egroup
%    \let#1=0
%    }
%  \show#1
%}

% this is used in cyrillic enc.def files for textmath.ltx check
\def\@ifl@aded#1#2{%
  \expandafter\ifx\csname ver@#2.#1\endcsname\relax
    \expandafter\@secondoftwo
  \else
    \expandafter\@firstoftwo
  \fi}

\def\textcircled#1{{\ooalign{\hfil\raise.07ex\hbox{#1}\hfil\crcr\Orb}}}
\let\textlatin\rm

\def\fontencoding#1{\catcode`\@=11
  \@lowercase{\input{#1enc.def}}%
  \@edef\cf@encoding{\@uppercase{\def\noexpand\cf@encoding{#1}}}%
  \cf@encoding
  \catcode`\@=12 }
\input inputenc.sty

\catcode`\@=\atcatcode \let\atcatcode\undefined

\endinput
