% 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.

\ifx\inputencoding\undefined\else\expandafter\endinput\fi
\chardef\atcatcode=\catcode`\@ \catcode`\@=11

% load definitions from BABEL's plain.def (\adddialect should now be defined)
\ifx\adddialect\undefined\let\adddialect\relax\let\protect\relax\fi
\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\LastDeclaredEncoding{#1}}
% special math setup is unneeded if only one font encoding is used
\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\@xdef\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}}
% only glyphs present in LCY are defined, because only LCY is fully supported
\def\@uclclist{\oe\OE\o\O\ae\AE\dh\DH\dj\DJ\l\L\ng\NG\ss\SS\th\TH
\cyra\CYRA\cyrb\CYRB\cyrv\CYRV\cyrg\CYRG\cyrd\CYRD\cyre\CYRE
\cyrzh\CYRZH\cyrz\CYRZ\cyri\CYRI\cyrishrt\CYRISHRT\cyrk\CYRK
\cyrl\CYRL\cyrm\CYRM\cyrn\CYRN\cyro\CYRO\cyrp\CYRP\cyrr\CYRR
\cyrs\CYRS\cyrt\CYRT\cyru\CYRU\cyrf\CYRF\cyrh\CYRH\cyrc\CYRC
\cyrch\CYRCH\cyrsh\CYRSH\cyrshch\CYRSHCH\cyrhrdsn\CYRHRDSN
\cyrery\CYRERY\cyrsftsn\CYRSFTSN\cyrerev\CYREREV\cyryu\CYRYU
\cyrya\CYRYA\cyryo\CYRYO\cyrgup\CYRGUP\cyrie\CYRIE\cyrii\CYRII
\cyryi\CYRYI\cyrushrt\CYRUSHRT}
\def\PROTECT{%
  \let\uppercase\uppercas@\let\lowercase\lowercas@
  \let\edef\protected@edef\let\xdef\protected@xdef}
\def\UNPROTECT{%
  \let\uppercase\@uppercase\let\lowercase\@lowercase
  \let\edef\@edef\let\xdef\@xdef}
\PROTECT

\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
    \immediate@\org@write\the\count@{#1}%
  \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}

% for inputenc files
\def\makeatletter{\catcode`\@11\relax}
\def\makeatother{\catcode`\@12\relax}

\ifx\Orb\undefined
  \message{^^J* Please get newer version of plain.tex from^^J%
  * CTAN:systems/knuth/lib/plain.tex^^J* Aborting.^^J^^J}\end
\fi
\def\textcircled#1{{\ooalign{\hfil\raise.07ex\hbox{#1}\hfil\crcr\Orb}}}
%\let\textlatin\rm

\def\fontencoding#1{\catcode`\@=11
  \UNPROTECT % \lowercase for \DeclareTextComposite
  \@lowercase{\input{#1enc.def}}%
  \PROTECT
  \@edef\cf@encoding{\@uppercase{\def\noexpand\cf@encoding{#1}}}%
  \cf@encoding
  \catcode`\@=12 }
\input inputenc.sty
\let\org@inputencoding\inputencoding
\def\inputencoding#1{\UNPROTECT % \uppercase, \edef
  \org@inputencoding{#1}%
  \PROTECT}

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

\endinput
