%%
%% This is file `circ.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% circ.dtx  (with options: `code')
%% Copyright 1997-98  Sebastian Tannert / Andreas Tille
%% 
%% This file is part of the CIRC package
%% -------------------------------------
%%   This package is distributed in the hope that it will be useful,
%%   but WITHOUT ANY WARRANTY; without even the implied warranty of
%%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
%% 
%%   For error reports concerning UNCHANGED versions of this file no
%%   more than one year old, see CIRC.DVI.
%% 
%% IMPORTANT COPYRIGHT NOTICE:
%% 
%% You are NOT ALLOWED to distribute this file alone.
%% 
%% You are allowed to distribute this file under the condition that it
%% is distributed together with all the files listed in circ.txt.
%% 
%% If you receive only some of these files from someone, complain!
%% 
%% You are NOT ALLOWED to change this file.
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesClass{circ}
    [1997/04/23 v1.0d for typeset circuit diagrams]
\DeclareOption*{\InputIfFileExists{\CurrentOption.def}{}%
  {\PackageError{CIRC}{File \CurrentOption.def not found.}%
                {Check spelling or think about the
                location of file.\MessageBreak
                I tried to load macros for the CIRC package.}}}
\def\freecirc{\chardef\CIRCinternals\the\catcode`\*\catcode`\*=11
              \chardef\cc@lb\the\catcode`\[
              \chardef\cc@rb\the\catcode`\]
              \chardef\cc@at\the\catcode`\@
              \catcode`\[=11\catcode`\]=11\catcode`\@=11 }
\def\protectcirc{\catcode`\[=\cc@lb\catcode`\]=\cc@rb\catcode`\@=\cc@at
                 \catcode`\*=\CIRCinternals\relax}
\freecirc
\newif\ifshowpoints
\showpointsfalse
\newif\iflab*
\lab*true
\newif\ifval*
\val*true
\newif\ifld*
\ld*false
\newif\ifcc*
\cc*false
\newif\ifpin
\pintrue
\newif\ifxoutofgrid
\newif\ifyoutofgrid
\xoutofgridfalse
\youtofgridfalse
\newif\ifcen*
\cen*false
\newif\ifhvcen*
\hvcen*false
\newif\ifcheck*
\newdimen\X*max
\newdimen\X*min
\newdimen\*X*
\newdimen\*Y*
\newdimen\**X
\newdimen\**Y
\newdimen\***X
\newdimen\***Y
\newbox\*bbox
\newbox\box*
\newdimen\ic*
\newdimen\ht*
\newdimen\wd*
\newdimen\dp*
\newcount\cc*
\newdimen\*spc
\newtoks\ldd*   %linke untere Beschriftung
\newtoks\rud*   %rechte obere Beschriftung
\newtoks\llpos*
\newtoks\ldpos*
\newtoks\rlpos*
\newtoks\rdpos*
\newtoks\ulpos*
\newtoks\udpos*
\newtoks\dlpos*
\newtoks\ddpos*
\newcount\cnta*
\newcount\cntb*
\newtoks\name*  %Bauelementname
\newtoks\ld*pin   %Bezeichnung linker Anschlu"s
\newtoks\ru*pin   % ...
\newtoks\m*pin    % ...
\newtoks\rmacros
\newdimen\outerspace
\newtoks\*Ilist
\newtoks\*Olist

\newdimen\pin*spc
\newdimen\pin*ind
\newdimen\io*ind
\newdimen\mid*ind
\newdimen\pinnum*spc
\def\CIRCredef{}
\def\safedef#1{\expandafter\ifx\csname#1\endcsname\relax
\toks0{\expandafter\def\csname#1\endcsname}\else
\edef\CIRCredef{\CIRCredef\expandafter\string\csname#1\endcsname\space}%
\toks0{\expandafter\def\csname.#1.\endcsname}\rmacros
\expandafter{\the\rmacros\let}\rmacros\expandafter\expandafter\expandafter
{\expandafter\the\expandafter\rmacros\csname#1\endcsname}\rmacros\expandafter
\expandafter\expandafter
{\expandafter\the\expandafter\rmacros\csname.#1.\endcsname}\fi
\the\toks0}
\def\safedefs#1{\expandafter\ifx\csname#1\endcsname\relax
\toks0{\expandafter\def\csname#1\endcsname}\else
\edef\CIRCredef{\CIRCredef\expandafter\string\csname#1\endcsname\space}%
\toks0{\expandafter\def\csname.#1.\endcsname}\rmacros
\expandafter{\the\rmacros\let}\rmacros\expandafter\expandafter\expandafter
{\expandafter\the\expandafter\rmacros\csname#1\endcsname}\rmacros\expandafter
\expandafter\expandafter
{\expandafter\the\expandafter\rmacros\csname.#1.\endcsname}\fi
\the\toks0 }
\def\getc*#1 {\advance\cc* by #1%
  \ifcc*
     \toks0\ldd*\ldd*\rud*\rud*\toks0
     \ifval*
       \iflab*\val*true\else\val*false\fi
       \lab*true
     \else
       \iflab*\val*true\else\val*false\fi
      \lab*false
     \fi
  \fi
  \global\setbox\box*=\hbox{\char\cc*\/\global\ic*=\lastkern\unkern}%
  \global\ht*\ht\box*\global\wd*\wd\box*\global\dp*\dp\box*}
\def\check*max#1{\dimen0=#1\advance\dimen0\*X*
               \ifdim\dimen0>\X*max\global\X*max\dimen0\fi}
\def\check*X{\ifcheck*\ifdim\*X*<\X*min\global\X*min\*X*\fi
                      \ifdim\*X*>\X*max\global\X*max\*X*\fi\fi}
\def\check*min#1{\dimen0=-#1\advance\dimen0\*X*
               \ifdim\dimen0<\X*min\global\X*min\dimen0\fi}
\def\check*#1{\check*min{#1}\check*max{#1}}
\def\check*cen{\ifcen*\errhelp{Use `\hcenterto' or `\vcenterto'.}%
  \errmessage{You can't use `\string\centerto' to center `\the\name*'}\fi}
\def\put*box{\hbox to 0pt{\kern\*X*\raise\*Y*\box\*bbox\hss}}
\def\hc*#1{\hbox to 0pt{\hss#1\hss}}
\def\vc*#1{\vbox to 0pt{\vss#1\vss}}
\def\tlap#1{\vbox to 0pt{\vss#1}}
\def\blap#1{\vbox to 0pt{#1\vss}}
\def\ac*#1{\vc*{\hc*{#1}}}
\def\reset*ifs{\ld*false\cen*false\hvcen*false\lab*true\val*true\cc*false}
\def\store*XY#1{\ifshowpoints\message{#1}\fi
  \expandafter\xdef\csname#1\endcsname{\*X*\the\*X*\*Y*\the\*Y*}}
\def\save*XY{\**X\*X*\**Y\*Y*}
\def\save*xy{\***X\*X*\***Y\*Y*}
\def\restore*XY{\*X*\**X\*Y*\**Y}
\def\restore*xy{\*X*\***X\*Y*\***Y}
\def\diff*XY{\advance\**X-\*X*\advance\**Y-\*Y*}
\def\centerto#1 {\cen*true\save*XY\frompin#1: }
\def\hcenterto#1 {\hvcen*true\**Y\*Y*\frompin#1: \*Y*\**Y}
\def\vcenterto#1 {\hvcen*true\**X\*X*\frompin#1: \*X*\**X}
\def\do*Ilist{\ifshowpoints\message{|<}\fi
  \check*true
  \save*XY\the\*Ilist\ifshowpoints\message{>|}\fi\restore*XY\*Ilist={}}
\def\shift*Ilist#1{\ifshowpoints\message{|<}\fi
  \check*false
  \save*XY\the\*Ilist\frompin{\the\name*#1}
  \ifshowpoints\message{| shift \the\name*#1 |}\fi
  \advance\**X\**X\advance\**X-\*X*\*X*\**X
  \advance\**Y\**Y\advance\**Y-\*Y*\*Y*\**Y
  \check*true
  \save*XY\the\*Ilist\restore*XY
  \ifshowpoints\message{>|}\fi\*Ilist={}}
\def\shift*IOlist#1{\ifshowpoints\message{|<}\fi
  \check*false
  \save*XY\the\*Ilist\restore*XY\advance\*X*\wd\*bbox\the\*Olist
  \frompin{\the\name*#1}
  \ifshowpoints\message{| shift \the\name*#1 |}\fi
  \advance\**X\**X\advance\**X-\*X*\*X*\**X
  \advance\**Y\**Y\advance\**Y-\*Y*\*Y*\**Y
  \check*true
  \save*XY\the\*Ilist\restore*XY\advance\*X*\wd\*bbox\the\*Olist
  \restore*XY\ifshowpoints\message{>|}\fi\*Ilist={}\*Olist={}}
\def\Ladd*x#1#2{\dimen9=#2%
  \edef\next{{\the#1\advance\*X*\the\dimen9 }}%
  \global#1\next}
\def\Ladd*y#1#2{\dimen9=#2%
  \edef\next{{\the#1\advance\*Y*\the\dimen9 }}%
  \global#1\next}
\def\Lstore*#1#2{\edef\next{{\the#1\noexpand\store*XY{\the\name*#2}}}%
  \global#1\next}
\def\Lstopos*#1{\global#1\expandafter{\the#1\save*xy}}
\def\Lrstpos*#1{\global#1\expandafter{\the#1\restore*xy}}
\def\LX*check#1{\global#1\expandafter{\the#1\check*X}}
\def\add*x{\Ladd*x\*Ilist}
\def\add*y{\Ladd*y\*Ilist}
\def\store*{\Lstore*\*Ilist}
\def\stopos*{\Lstopos*\*Ilist}
\def\rstpos*{\Lrstpos*\*Ilist}
\def\X*check{\LX*check\*Ilist}
\def\Cadd*#1{\Ladd*y#1{-\pin*spc}}
\def\Cstore*#1#2{\ifx{#2}*\else\Lstore*#1{#2}\fi}
\def\frompin#1 {\expandafter\ifx\csname#1\endcsname\relax
  \errhelp{Check spelling! Look up in the description of circuits.}%
  \errmessage{Point >#1< is not defined}\else\csname#1\endcsname\fi}
\let\atpin\frompin
\def\h*twopins#1{\getc*#1 \ifcen*\*Y*\**Y\hvcen*true\fi
\wd\box*=.5\wd*
\advance\ht*\*spc
\X*check\store*{\the\ld*pin}\add*x{.5\wd*}\store*:\add*x{.5\wd*}%
\store*{\the\ru*pin}\X*check
\ifhvcen*\shift*Ilist:\else\ifld*\shift*Ilist{\the\ru*pin}\else\do*Ilist\fi\fi
\labelfont
\setbox0=\hbox{\the\rud*}\setbox1=\hbox{\the\ldd*}%
\**X\*X*\advance\*X*.5\wd*
\iflab*\check*{.5\wd0}\fi%
\ifval*\check*{.5\wd1}\fi%
\*X*\**X
\setbox\*bbox=\hbox{\box\box*
  \iflab*\raise\ht*\hc*{\unhbox0}\fi
  \ifval*\lower\dp*\vtop{\kern\*spc\hc*{\unhbox1}}\fi
  \add*cmds}%
\put*box
\ifld*\else\advance\*X*\wd*\fi\reset*ifs}
\def\v*twopins#1{\getc*#1 \ifcen*\*X*\**X\hvcen*true\fi
\labelfont
\setbox0=\hbox{\ifval*\the\ldd*\kern\*spc\fi\kern\dp*}\dimen1\wd0
\setbox1=\hbox{\kern\wd*\iflab*\kern\*spc\the\rud*\fi}\dimen0\wd1
\dp0=0pt\dp1=0pt
\wd\box*=0pt\dp\box*=0pt
\setbox\*bbox=\hbox{\box\box*
  \raise.5\ht*\hbox{\vc*{\hbox{\llap{\box0}\rlap{\box1}}}\add*cmds}}%
\store*{\the\ld*pin}\add*y{.5\ht*}\store*:\add*y{.5\ht*}\store*{\the\ru*pin}%
\ifhvcen*\shift*Ilist:\else\ifld*\shift*Ilist{\the\ru*pin}\else\do*Ilist\fi\fi
\check*X
\check*max{\dimen0}%
\check*min{\dimen1}%
\put*box
\ifld*\else\advance\*Y*\ht*\fi\reset*ifs}
\def\ii*#1 {\if#1h\ld*pin{l}\ru*pin{r}\h*twopins0\relax\else
            \if#1v\ld*pin{b}\ru*pin{t}\v*twopins1\relax\else
            \if#1u\ld*pin{b}\ru*pin{t}\v*twopins1\relax\else
            \if#1d\ld*pin{b}\ru*pin{t}\ld*true\v*twopins1\relax\else
            \if#1l\ld*pin{l}\ru*pin{r}\ld*true\h*twopins0\relax\else
            \if#1r\ld*pin{l}\ru*pin{r}\h*twopins0\relax\else
                  \errhelp{Direction >h<, >v<, >l<, >u<, >r< or >d< expected.}%
                  \errmessage{Bad direction specified! You typed:>#1<.}%
                  \fi\fi\fi\fi\fi\fi}
\def\change*pins{\toks0\ld*pin\ld*pin\ru*pin\ru*pin\toks0}
\def\CiRCl{1}\def\CiRCr{2}\def\CiRCu{3}\def\CiRCd{4}
\def\CiRCL{5}\def\CiRCR{6}\def\CiRCU{7}\def\CiRCD{8}
\def\CIRCiErr{\PackageError{CIRC}{Internal Error}%
              {You are great, please send all files to the author and wait for
               answer.}}
\def\iv*#1 #2 {\cnta*=0\csname CiRC#2\endcsname\relax
               \ifnum\cnta*=0
               \PackageError{CIRC}{Bad direction}%
                 {Please check spelling}\fi
               \ifcase\CIRCpintoN{#1}\relax\CIRCiErr \or
                 \ifcase\cnta*
                 \CIRCiErr\or\<\change*pins\h*twopins2\relax
                               \or\h*twopins0\relax
                               \or\v*twopins1\relax
                               \or\change*pins\<\v*twopins3\relax\else
                 \PackageError{CIRC}{Bad direction}%
                   {Please check spelling, only [l r u d] expected}\fi\or
                 \ifcase\cnta*
                 \CIRCiErr\or\<\h*twopins0\relax
                          \or\change*pins\h*twopins2\relax
                          \or\change*pins\v*twopins3\relax
                          \or\<\v*twopins1\relax\else
                 \PackageError{CIRC}{Bad direction}%
                   {Please check spelling, only [l r u d] expected}\fi\fi}
\def\iviv*#1 #2 {\cnta*=0\csname CiRC#2\endcsname\relax
               \ifnum\cnta*=0
               \PackageError{CIRC}{Bad direction}%
                 {Please check spelling}\fi
               \ifcase\CIRCpintoN{#1}\relax\CIRCiErr \or
                 \ifcase\cnta*
                 \CIRCiErr\or\<\change*pins\h*twopins6\relax
                          \or\h*twopins0\relax
                          \or\v*twopins5\relax
                          \or\change*pins\<\v*twopins3\relax
                          \or\<\change*pins\h*twopins2\relax
                          \or\h*twopins4\relax
                          \or\v*twopins1\relax
                          \or\change*pins\<\v*twopins7\relax\fi\or
                 \ifcase\cnta*
                 \CIRCiErr\or\<\h*twopins0\relax
                          \or\change*pins\h*twopins6\relax
                          \or\change*pins\v*twopins3\relax
                          \or\<\v*twopins5\relax
                          \or\<\h*twopins4\relax
                          \or\change*pins\h*twopins2\relax
                          \or\change*pins\v*twopins7\relax
                          \or\<\v*twopins1\relax\fi\fi}
\def\lviii*#1{\store*{\the\m*pin}\X*check
              \add*x\wd*\stopos*\add*y{-\dp*}\store*{\the\ld*pin}\X*check
              \rstpos*\add*y\ht*\store*{\the\ru*pin}\rstpos*
              \dimen0\ht*\advance\dimen0-\dp*\add*y{.5\dimen0}\store*:
              \rstpos*\add*x\ic*\X*check
              \ifhvcen*\shift*Ilist:\else\shift*Ilist{#1}\fi
              \setbox\*bbox=\hbox{\labelfont
                \the\llpos*\box\box*\the\ldpos*}\put*box}
\def\rviii*#1{\store*{\the\m*pin}\X*check
              \add*x{-\wd*}\stopos*\add*y\ht*\store*{\the\ru*pin}\X*check
              \rstpos*\add*y{-\dp*}\store*{\the\ld*pin}\rstpos*
              \dimen0\ht*\advance\dimen0-\dp*\add*y{.5\dimen0}\store*:
              \rstpos*\add*x{-\ic*}\X*check
              \ifhvcen*\shift*Ilist:\else\shift*Ilist{#1}\fi
              \setbox\*bbox=\hbox{\labelfont
                \the\rdpos*\box\box*\the\rlpos*}\put*box}
\def\dviii*#1{\store*{\the\m*pin}%
              \add*y\dp*\stopos*\add*x\ic*\store*{\the\ru*pin}\X*check
              \rstpos*\add*x{-\wd*}\store*{\the\ld*pin}\X*check
              \rstpos*\dimen0-\wd*\advance\dimen0\ic*\add*x{.5\dimen0}\store*:
              \ifhvcen*\shift*Ilist:\else\shift*Ilist{#1}\fi
              \wd\box*=0pt\dp\box*=0pt
              \setbox\*bbox=\hbox{\labelfont
                \the\dlpos*\box\box*\the\ddpos*}\put*box}
\def\uviii*#1{\store*{\the\m*pin}%
              \add*y{-\ht*}\stopos*\add*x\ic*\store*{\the\ru*pin}\X*check
              \rstpos*\add*x{-\wd*}\store*{\the\ld*pin}\X*check
              \rstpos*\dimen0-\wd*\advance\dimen0\ic*\add*x{.5\dimen0}\store*:
              \ifhvcen*\shift*Ilist:\else\shift*Ilist{#1}\fi
              \wd\box*=0pt\ht\box*=0pt
              \setbox\*bbox=\hbox{\labelfont
                \the\ulpos*\box\box*\the\udpos*}\put*box}
\def\viii*#1 #2 {\check*cen
                 \if#2l            \getc*0 \lviii*{#1}\else
                 \if#2r            \getc*1 \rviii*{#1}\else
                 \if#2d            \getc*3 \dviii*{#1}\else
                 \if#2u            \getc*2 \uviii*{#1}\else
                 \if#2L\change*pins\getc*4 \lviii*{#1}\else
                 \if#2R\change*pins\getc*5 \rviii*{#1}\else
                 \if#2D\change*pins\getc*7 \dviii*{#1}\else
                 \if#2U\change*pins\getc*6 \uviii*{#1}\else
                 \errhelp{Direction >l<, >r<, >u<, >d<, >L<, >R<, >U< or >D<
                          expected.}%
                 \errmessage{Bad direction >#2<}\fi\fi\fi\fi\fi\fi\fi\fi
                 \reset*ifs}
\def\CIRCpintoN#1{\if\the\ld*pin#1 1\else
                   \if\the\ru*pin#1 2\else
                    \if\the\m*pin#1 3\else
                      \PackageError{CIRC}{Bad pin name}%
                      {Please check spelling or look up in the documentation}
\fi\fi\fi}
\def\cdef#1 #2 #3#4 {\safedef{#1}##1 ##2 {%
   \name*{#1##1}\rud*{$#2_{##1}$}\ldd*{##2}\cc*#4 #3\ii*}}
\def\cdefiv#1 #2 #3#4 #5 #6 {\safedef{#1}##1 ##2 {%
   \name*{#1##1}\rud*{$#2_{##1}$}\ldd*{##2}\m*pin{@}%
   \ld*pin{#5}\ru*pin{#6}\cc*#4 #3\iv*}}
\def\cdefivNL#1 #2#3 #4 #5 {\safedef{#1}##1 ##2 {%
   \name*{#1##1}\rud*{}\ldd*{##2}\ld*pin{#4}\ru*pin{#5}\m*pin{@}%
   \cc*#3 #2\iv*}}
\def\cdefiviv#1 #2 #3#4 #5 #6 {\safedef{#1}##1 ##2 {%
   \name*{#1##1}\rud*{$#2_{##1}$}\ldd*{##2}\ld*pin{#5}\ru*pin{#6}\m*pin{@}%
   \cc*#4 #3\iviv*}}
\def\cdefivivNL#1 #2#3 #4 #5 {\safedef{#1}##1 ##2 {%
   \name*{#1##1}\rud*{}\ldd*{##2}\ld*pin{#4}\ru*pin{#5}\m*pin{@}%
   \cc*#3 #2\iviv*}}
\def\cdefNL#1 #2#3 {\safedef{#1}##1 ##2 {%
   \name*{#1##1}\rud*{}\ldd*{##2}\cc*#3 #2\ii*}}
\def\cdefviii#1 #2 #3#4 #5 #6 #7 {\safedef{#1}##1 ##2 {\name*{#1##1}%
   \rud*{$#2_{##1}$}\ldd*{##2}\ld*pin{#5}\m*pin{#6}\ru*pin{#7}\cc*#4 #3\viii*}}
\def\cwdef#1 #2 {\safedef{#1}##1 ##2 {\cc*#2
                 \cnta*##1\toks2{}\toks4{}\dimen2=##1em\test*xygrid
                 \csname line*##2\endcsname}}
\def\black*boxii#1 #2 #3 #4 #5 #6 #7 {\check*cen
  \if#7h\getc*0
  \store*{P1}\X*check\add*x{.5\wd*}\stopos*\X*check\store*:
  \add*y\ht*\store*{P4}\rstpos*\add*y{-\dp*}\store*{P2}\rstpos*
  \add*x{.5\wd*}\X*check\store*{P3}%
  \ifhvcen*\shift*Ilist:\else\shift*Ilist{#2}\fi
  \setbox\*bbox=\hbox{\ifpin\pinnumberfont
    \setbox0=\hbox{#3\kern\*spc}\check*min{\wd0}%
    \raise\pinnum*spc\llap{#3\kern\*spc}%
    \setbox0=\hbox{\kern\*spc\kern\wd*#5}\check*max{\wd0}\wd0=0pt
    \raise\pinnum*spc\box0
    \setbox0=\hbox{\kern\pinnum*spc\kern.5\wd*#6}\check*max{\wd0}\wd0=0pt
    \dimen0\ht*\advance\dimen0\*spc
    \raise\dimen0\box0
    \setbox0=\hbox{\kern\pinnum*spc\kern.5\wd*#4}\check*max{\wd0}\wd0=0pt
    \dimen0\dp*\advance\dimen0\*spc
    \lower\dimen0\vtop{\kern0pt\box0}\fi
    \hc*{\kern\wd*\ctextfont\vc*{\hbox{#1}}}\box\box*}\put*box\reset*ifs
  \else\if#7v\getc*1
  \store*{P4}\X*check\add*x{.5\wd*}\stopos*\X*check\store*:
  \add*y\ht*\store*{P3}\rstpos*\add*y{-\dp*}\store*{P1}\rstpos*
  \add*x{.5\wd*}\X*check\store*{P2}%
  \ifhvcen*\shift*Ilist:\else\shift*Ilist{#2}\fi
  \setbox\*bbox=\hbox{\ifpin\pinnumberfont
    \setbox0=\hbox{#6\kern\*spc}\check*min{\wd0}%
    \raise\pinnum*spc\llap{#6\kern\*spc}%
    \setbox0=\hbox{\kern\*spc\kern\wd*#4}\check*max{\wd0}\wd0=0pt
    \raise\pinnum*spc\box0
    \setbox0=\hbox{\kern\pinnum*spc\kern.5\wd*#5}\check*max{\wd0}\wd0=0pt
    \dimen0\ht*\advance\dimen0\*spc
    \raise\dimen0\box0
    \setbox0=\hbox{\kern\pinnum*spc\kern.5\wd*#3}\check*max{\wd0}\wd0=0pt
    \dimen0\dp*\advance\dimen0\*spc
    \lower\dimen0\vtop{\kern0pt\box0}\fi
    \hc*{\kern\wd*\ctextfont\vc*{\hbox{#1}}}\box\box*}\put*box\reset*ifs
  \else\errhelp{Direction >h< or >v< expected.}%
  \errmessage{ >#1<  Bad direction specified}\fi\fi}
\def\black*box#1 #2 #3 #4 #5 #6 {\black*boxii{#1} {#2} {#3} {#4} {#5} {#6} h }
\def\sym*box#1 #2 {\check*cen
  \getc*0
  \store*{P1}\X*check\stopos*
  \add*x{.5\wd*}\store*:\add*x{.5\wd*}\store*{P3}\X*check\rstpos*
  \add*y{-1em}\store* b
  \add*x{\wd*}\store* e\rstpos*
  \add*y{1em}\store* a
  \add*x{\wd*}\store* f\rstpos*
  \add*x{.5\wd*}\stopos*
  \add*y\ht*\store*{P4}%
  \add*x{1em}\store* g
  \rstpos*\add*y\ht*
  \add*x{-1em}\store* h
  \rstpos*\add*y{-\dp*}\store*{P2}%
  \add*x{1em}\store* d
  \rstpos*\add*y{-\dp*}%
  \add*x{-1em}\store* c
  \ifhvcen*\shift*Ilist:\else\shift*Ilist{#2}\fi
  \setbox\*bbox=
    \hbox{\hc*{\kern\wd*\ctextfont\vc*{\hbox{#1}}}\box\box*}\put*box
    \reset*ifs}
\def\bbdef#1 #2#3 {\safedef{#1}##1
{\name*{#1##1}\cc*#3 #2\black*box}}
\def\bbdefNeT#1 #2#3 #4 {\safedef{#1}##1
{\name*{#1##1}\cc*#3#2\black*box{#4} }}
\def\bbdefNeTii#1 #2#3 #4 {\safedef{#1}##1
{\name*{#1##1}\cc*#3#2\black*boxii{#4} }}
\def\sbdef#1 #2#3 #4 {\safedef{#1}##1
{\name*{#1##1}\cc*#3#2\sym*box{#4} }}
\cwdef        wire   {128\c*fnt}
\cwdef        dashed {120\c*fnt}
\def\line*r{\check*X\ifnum\cnta*=0\else\check*max{\dimen2}\ifxoutofgrid
  \advance\dimen2-.5\fontdimen6\c*fnt\fi
  \setbox\*bbox=\hbox{\ifxoutofgrid\else\char\cc*\fi\advance\cc*1%
                      \loop\ifnum\cnta*>1\char\cc*
                      \advance\cnta*-1\repeat}\put*box
  \advance\*X*.5\dimen2\the\toks2\advance\*X*.5\dimen2
  \advance\cc*2\setbox\*bbox=\hbox{\char\cc*}\put*box\xoutofgridfalse\fi}
\def\line*l{\advance\*X*-\dimen2
            \ifxoutofgrid\advance\*X*.5\fontdimen6\c*fnt\fi
            \**X\*X*\line*r\*X*\**X}
\def\line*u{\check*X\ifnum\cnta*=0\else\advance\cc*4\ifyoutofgrid
  \advance\dimen2-.5\fontdimen6\c*fnt\fi
  \setbox\box*=\hbox{\char\cc*}\advance\cc*-1%
  \setbox\*bbox=\vbox{\loop\ifnum\cnta*>1\copy\box*
                      \advance\cnta*-1\repeat
                      \ifyoutofgrid\else\hbox{\char\cc*}\fi}\put*box
  \advance\*Y*.5\dimen2\the\toks4\advance\*Y*.5\dimen2
  \advance\cc*2\setbox\*bbox=\vbox{\hbox{\char\cc*}}\put*box\youtofgridfalse\fi}
\def\line*d{\advance\*Y*-\dimen2
            \ifyoutofgrid\advance\*Y*.5\fontdimen6\c*fnt\fi
            \**Y\*Y*\line*u\*Y*\**Y}
\def\test*xygrid{\dimen9\fontdimen6\c*fnt\count@\dimen9
                \cntb*\*X*\divide\cntb*\count@
                \dimen0\*X*\advance\dimen0-\cntb*\dimen9
                \advance\dimen9-.1pt
                \ifdim\dimen0<0pt \dimen0-\dimen0 \fi
                \ifdim\dimen0>0.1pt \ifdim\dimen0<\dimen9 \xoutofgridtrue\fi\fi
                \cntb*\*Y*\divide\cntb*\count@
                \dimen0\*Y*\advance\dimen0-\cntb*\fontdimen6\c*fnt
                \ifdim\dimen0<0pt \dimen0-\dimen0 \fi
                \ifdim\dimen0>0.1pt \ifdim\dimen0<\dimen9 \youtofgridtrue\fi\fi}
\def\bundle#1 #2 #3 {\cc*136\c*fnt\cnta*#2\dimen2=#2em
                     \toks2{\setbox\box*=\hbox{\char134}%
                     \setbox\*bbox=\rlap{\raise\ht\box*
                     \hc*{\labelfont#1}\unhbox\box*}\put*box}%
                     \toks4{\setbox\*bbox=\hbox{\char135\labelfont
                     \vc*{\hbox{#1}}}%
                     \check*max{\wd\*bbox}\put*box}%
                     \test*xygrid\csname line*#3\endcsname}
\def\wwire#1 #2 #3 {\cc*112\c*fnt\cnta*#2\dimen2=#2em
                    \toks2{\setbox\*bbox=\rlap{\raise\*spc
                    \hc*{\labelfont#1}}\put*box}%
                    \toks4{\setbox\*bbox=\hbox{\kern\*spc\labelfont
                    \vc*{\hbox{#1}}}%
                    \check*max{\wd\*bbox}\put*box}%
                    \test*xygrid\csname line*#3\endcsname}
\def\by#1 {\def\by*cmd{#1}}
\by{\wire}
\def\calc*u{\cnta*\fontdimen6\c*fnt\advance\dimen0 .5\fontdimen6\c*fnt
            \cntb*\dimen0\divide\cntb*\cnta*}
\def\vtopin#1 {\save*XY\frompin{#1} \test*xygrid
               \dimen0\**Y\advance\dimen0-\*Y*\restore*XY
               \ifdim\dimen0<0pt\dimen0-\dimen0
               \calc*u\by*cmd {\cntb*} u
               \else\calc*u\by*cmd {\cntb*} d \fi}
\def\htopin#1 {\save*XY\frompin{#1} \test*xygrid
               \dimen0\**X\advance\dimen0-\*X*\restore*XY
               \ifdim\dimen0<0pt\dimen0-\dimen0
               \calc*u\by*cmd {\cntb*} r
               \else\calc*u\by*cmd {\cntb*} l \fi}
\safedef{Utext}#1 from #2 to #3 {{%
  \frompin{#2} \save*XY\frompin{#3} \diff*XY
    \ifdim\**X=0pt
      \setbox1=\hbox{\c*fnt\char132}%
      \ifdim\**Y<0pt
        \dimen0-\**Y
        \setbox0=\hbox{\c*fnt\char'373}\advance\dimen0-\ht0\dp0=0pt
        \calc*u
        \setbox\*bbox=
          \vtop to -\**Y{\vfill\box0\loop\ifnum\cntb*>2\copy1
            \advance\cntb*-1\repeat\vfill}%
      \else
        \dimen0\**Y
        \setbox0=\hbox{\c*fnt\char'371}\advance\dimen0-\ht0\dp0=0pt
        \calc*u
        \setbox\*bbox=
          \vbox to \**Y{\vfill\loop\ifnum\cntb*>2\copy1
            \advance\cntb*-1\repeat\box0\vfill}%
      \fi
      \put*box\advance\*X*\*spc\advance\*Y*.5\**Y\put\vc*{\hbox{#1}}
    \else
    \ifdim\**Y=0pt
      \ifdim\**X<0pt
        \dimen0-\**X
        \setbox0=\hbox{\c*fnt\char'372}\advance\dimen0-\wd0
        \calc*u
        \setbox\*bbox=\llap{\hbox to -\**X{\hfill\loop\ifnum\cntb*>2\char129
          \advance\cntb*-1\repeat\box0\hfill}}%
      \else
        \dimen0\**X
        \setbox0=\hbox{\c*fnt\char'370}\advance\dimen0-\wd0
        \calc*u
        \setbox\*bbox=\hbox to \**X{\hfill\box0\loop\ifnum\cntb*>2\char129
          \advance\cntb*-1\repeat\hfill}%
      \fi
      \put*box\advance\*X*.5\**X\advance\*Y*\*spc\put\hc*{#1}
    \else\errhelp{Only horizontal or vertical labeling allowed.}%
    \errmessage{Bad points!}\fi\fi}}
\safedef{centertext}#1 from #2 to #3 {%
  {\frompin{#2} \save*XY\frompin{#3} \diff*XY
    \ifdim\**X=0pt
      \advance\*Y*.5\**Y\put\vc*{\hbox{#1}}
    \else
    \ifdim\**Y=0pt
      \advance\*X*.5\**X\put\hc*{#1}
    \else\errhelp{Only horizontal or vertical labeling allowed.}%
    \errmessage{Bad points}\fi\fi}}
\def\from#1 #2 {\c*fnt\*X*=#1em\*Y*=#2em\check*X}
\let\at\from
\def\moverel#1 #2 {\c*fnt\advance\*X* #1em\advance\*Y* #2em\check*X}
\let\shift\moverel
\safedef{put}#1 {\setbox\*bbox=\hbox{\ctextfont#1}\check*X
                 \check*max{\wd\*bbox}\put*box}

\safedef{P}#1 {\store*XY{P#1}\check*X\reset*ifs}
\safedefs{_} #1 #2 {\c*fnt\cnta*=0\csname CiRC#2\endcsname\relax
               \ifnum\cnta*=0\relax
               \PackageError{CIRC}{Bad direction}{Please check spelling}\fi
               \ifcase \cnta* \relax
               \or \advance\*X* -#1em
               \or \advance\*X*  #1em
               \or \advance\*Y*  #1em
               \or \advance\*Y* -#1em
               \or \advance\*X* -#1em
               \or \advance\*X*  #1em
               \or \advance\*Y*  #1em
               \or \advance\*Y* -#1em \fi}
\def\nl{\lab*false}
\def\nv{\val*false}
\def\cc{\cc*true}
\def\clr*acmds{\global\let\add*cmds\relax}
\def\*fdef#1 {\expandafter\xdef\csname#1\endcsname{\the\toks0}}
\newtoks\CIRCfinit
\CIRCfinit={}
\def\addCIRCfont#1 {\expandafter\CIRCfinit=\expandafter{\the\CIRCfinit
                    \expandafter\font\csname CIRC#1\endcsname=#1 scaled \*mag}}
\def\CIusefont#1#2#3{\fontencoding{\encodingdefault}\fontfamily{#1}%
                     \fontseries{\seriesdefault}\fontshape{\shapedefault}%
                     \fontsize{#2}{#3}\selectfont}
\def\circuit#1 {\PackageInfo{CIRC}{`\CIRCredef' redefined}%
    \let\add*cmds\relax
    \*Ilist{}\*Olist{}\check*true
    \xdef\*mag{\magstep{#1}}%
    \global\X*max-\maxdimen
    \global\X*min\maxdimen
\ifcase#1 % magstep 0
    \toks0={\CIusefont{\rmdefault}{10}{12pt}}%
    \*fdef outlabelfont
    \*fdef labelfont
    \*fdef ctextfont
    \toks0={\CIusefont{\sfdefault}{10}{12pt}}%
    \*fdef symfont
    \toks0={\CIusefont{\rmdefault}{7}{8pt}}%
    \*fdef pinnumberfont
    \*fdef functionfont
    \toks0={\CIusefont{\rmdefault}{8}{9.5pt}}%
    \*fdef circlabelfont
    \toks0={\CIusefont{\sfdefault}{8}{9.5pt}}%
    \*fdef inlabelfont
\or       % magstep 1
    \toks0={\CIusefont{\rmdefault}{12}{14pt}}%
    \*fdef outlabelfont
    \*fdef labelfont
    \*fdef ctextfont
    \toks0={\CIusefont{\sfdefault}{12}{14pt}}%
    \*fdef symfont
    \toks0={\CIusefont{\rmdefault}{8}{9.5pt}}%
    \*fdef pinnumberfont
    \toks0={\CIusefont{\rmdefault}{9}{11pt}}%
    \*fdef functionfont
    \*fdef circlabelfont
    \toks0={\CIusefont{\sfdefault}{9}{11pt}}%
    \*fdef inlabelfont
\or       % magstep 2
    \toks0={\CIusefont{\rmdefault}{14.4}{18pt}}%
    \*fdef outlabelfont
    \*fdef labelfont
    \*fdef ctextfont
    \toks0={\CIusefont{\sfdefault}{14.4}{18pt}}%
    \*fdef symfont
    \toks0={\CIusefont{\rmdefault}{9}{11pt}}%
    \*fdef pinnumberfont
    \toks0={\CIusefont{\rmdefault}{10}{12pt}}%
    \*fdef functionfont
    \*fdef circlabelfont
    \toks0={\CIusefont{\sfdefault}{10}{12pt}}%
    \*fdef inlabelfont
\or       % magstep 3
    \toks0={\CIusefont{\rmdefault}{17.28}{22pt}}%
    \*fdef outlabelfont
    \*fdef labelfont
    \*fdef ctextfont
    \toks0={\CIusefont{\sfdefault}{17.28}{22pt}}%
    \*fdef symfont
    \toks0={\CIusefont{\sfdefault}{10}{12pt}}%
    \*fdef pinnumberfont
    \toks0={\CIusefont{\rmdefault}{12}{14pt}}%
    \*fdef functionfont
    \*fdef circlabelfont
    \toks0={\CIusefont{\sfdefault}{12}{14pt}}%
    \*fdef inlabelfont
\or       % magstep 4
    \toks0={\CIusefont{\rmdefault}{20.74}{25pt}}%
    \*fdef outlabelfont
    \*fdef labelfont
    \*fdef ctextfont
    \toks0={\CIusefont{\sfdefault}{20.74}{25pt}}%
    \*fdef symfont
    \toks0={\CIusefont{\rmdefault}{12}{14pt}}%
    \*fdef pinnumberfont
    \toks0={\CIusefont{\rmdefault}{14.4}{18pt}}%
    \*fdef functionfont
    \*fdef circlabelfont
    \toks0={\CIusefont{\sfdefault}{14.4}{18pt}}%
    \*fdef inlabelfont
\else\errhelp{0 ... 4 expected.}\errmessage{Bad magnification!}\fi
{\outlabelfont
\global\*spc 0.4em}%
\font\c*fnt=cirest      scaled \*mag
\font\c*fntb=cicirc     scaled \*mag
\font\c*fntd=cidiod     scaled \*mag
\font\c*fntt=cibimos    scaled \*mag
\font\c*fntw=ciwidko    scaled \*mag
\font\c*fnts=cisym      scaled \*mag
\outerspace1mm
\pinnum*spc.7mm
\pin*ind\fontdimen12\c*fntb
\pin*spc\fontdimen13\c*fntb
\io*ind\fontdimen14\c*fntb
\mid*ind\fontdimen16\c*fntb
\X*min\maxdimen
\X*max-\maxdimen
\the\CIRCfinit
\begingroup
  \the\rmacros
  \let\.\junction
  \def\- ##1 ##2 {\wire##1 ##2 }%
  \def\= ##1 ##2 ##3 {\bundle##1 ##2 ##3 }%
  \def\<{\ld*true}%
\parindent0pt
\offinterlineskip\setbox\*bbox=\hbox\bgroup\at 0 0 }
\def\endcircuit{\egroup\leavevmode
                \hbox{\kern-\X*min\unhbox\*bbox\kern\X*max}\endgroup
                \PackageInfo{CIRC}{`\CIRCredef' restored}}
\safedef{fallingEdge}{{\c*fnts\char3}}
\safedef{raisingEdge}{{\c*fnts\char2}}
\safedef{spike}{{\c*fnts\char4}}
\safedef{ispike}{{\c*fnts\char12}}
\safedef{squarePulse}{{\c*fnts\char1}}
\safedef{squarePulses}{{\c*fnts\char5}}
\safedef{sawtoothPuls}{{\c*fnt\char6}}
\def\CIRCLogo{\c*fnt\cc*0\getc*252 \check*max{.5\wd*}\check*min{.5\wd*}%
  \setbox\*bbox=\hbox to \wd*{\hss\lower\ht*\hbox to 0pt{\hss
  \symfont\raise1.5ex\rlap{\kern1ex CIRC}\box\box*}\hss}\put*box\reset*ifs}
\protectcirc
\ProcessOptions
\endinput
%%
%% End of file `circ.sty'.
