%%
%% This is file `circ.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% circ.dtx  (with options: `code')
%% Copyright 1997  Andreas Tille / Sebastian Tannert
%% 
%% 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.

\ProvidesPackage{circ}
\DeclareOption{basic}{\input{basic.def}}
\DeclareOption{box}{\input{box.def}}
\DeclareOption{gate}{\input{gate.def}}
\DeclareOption{ic}{\input{ic.def}}
\DeclareOption{optics}{\input{optics.def}}
\DeclareOption*{\InputIfFileExists{\CurrentOption.def}{\wlog{Loading
  \CurrentOption.def}}{\errhelp{^^J^^JCheck spelling or think about
  the location of file.^^JI tried to load macros for
  CIRC.}\errmessage{CIRC Error : File \CurrentOption.def not found^^J}}}
\def\freecirc{\chardef\ccat\the\catcode`\@\catcode`\@=11
              \chardef\@cclb\the\catcode`\[
              \chardef\@ccrb\the\catcode`\]
              \chardef\@ccst\the\catcode`\*
              \catcode`\[=11\catcode`\]=11\catcode`\*=11 }
\def\protectcirc{\catcode`\[=\@cclb\catcode`\]=\@ccrb\catcode`\*=\@ccst
                 \catcode`\@=\ccat\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    % ...
\newdimen\outerspace
\newtoks\*Ilist
\newtoks\*Olist

\newdimen\pin*spc
\newdimen\pin*ind
\newdimen\io*ind
\newdimen\mid*ind
\newdimen\pinnum*spc
\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{\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{\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}\getc*0 \h*twopins\else
            \if#1v\ld*pin{d}\ru*pin{u}\getc*1 \v*twopins\else
            \if#1u\ld*pin{d}\ru*pin{u}\getc*1 \v*twopins\else
            \if#1d\ld*pin{d}\ru*pin{u}\getc*1 \ld*true\v*twopins\else
            \if#1l\ld*pin{l}\ru*pin{r}\getc*0 \ld*true\h*twopins\else
            \if#1r\ld*pin{l}\ru*pin{r}\getc*0 \h*twopins\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\iv*#1 {\if#1l            \getc*0 \h*twopins\else
            \if#1r\change*pins\getc*2 \h*twopins\else
            \if#1d            \getc*1 \v*twopins\else
            \if#1u\change*pins\getc*3 \v*twopins\else
            \errhelp{Direction >l<, >r<, >u< or >d< expected.}%
            \errmessage{Bad direction >#1<}\fi\fi\fi\fi}
\def\iviv*#1 {\if#1l            \getc*4 \h*twopins\else
              \if#1r\change*pins\getc*2 \h*twopins\else
              \if#1d            \getc*5 \v*twopins\else
              \if#1u\change*pins\getc*3 \v*twopins\else
              \if#1L            \getc*0 \h*twopins\else
              \if#1R\change*pins\getc*6 \h*twopins\else
              \if#1D            \getc*1 \v*twopins\else
              \if#1U\change*pins\getc*7 \v*twopins\else
              \errhelp{Direction >l<, >r<, >u<, >d<, >L<, >R<, >U< or >D<
                       expected.}%
              \errmessage{Bad direction >#1<}\fi\fi\fi\fi\fi\fi\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\cdef#1 #2 #3#4 {\expandafter\def\csname#1\endcsname##1 ##2 {%
   \name*{#1##1}\rud*{$#2_{##1}$}\ldd*{##2}\cc*#4 #3\ii*}}
\def\cdefiv#1 #2 #3#4 #5 #6 {\expandafter\def\csname#1\endcsname##1 ##2 {%
   \name*{#1##1}\rud*{$#2_{##1}$}\ldd*{##2}\ld*pin{#5}\ru*pin{#6}\cc*#4 #3
   \iv*}}
\def\cdefiviv#1 #2 #3#4 #5 #6 {\expandafter\def\csname#1\endcsname##1 ##2 {%
   \name*{#1##1}\rud*{$#2_{##1}$}\ldd*{##2}\ld*pin{#5}\ru*pin{#6}\cc*#4 #3
   \iviv*}}
\def\cdefNL#1 #2#3 {\expandafter\def\csname#1\endcsname##1 ##2 {%
   \name*{#1##1}\rud*{}\ldd*{##2}\cc*#3 #2\ii*}}
\def\cdefivNL#1 #2#3 #4 #5 {\expandafter\def\csname#1\endcsname##1 ##2 {%
   \name*{#1##1}\rud*{}\ldd*{##2}\ld*pin{#4}\ru*pin{#5}\cc*#3 #2\iv*}}
\def\cdefivivNL#1 #2#3 #4 #5 {\expandafter\def\csname#1\endcsname##1 ##2 {%
   \name*{#1##1}\rud*{}\ldd*{##2}\ld*pin{#4}\ru*pin{#5}\cc*#3 #2\iviv*}}
\def\cdefviii#1 #2 #3#4 #5 #6 #7 {\expandafter
   \def\csname#1\endcsname##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 {\expandafter\def\csname#1\endcsname##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 {\expandafter
   \def\csname#1\endcsname##1 {\name*{#1##1}\cc*#3 #2\black*box}}
\def\bbdefNeT#1 #2#3 #4 {\expandafter
   \def\csname#1\endcsname##1 {\name*{#1##1}\cc*#3#2\black*box{#4} }}
\def\bbdefNeTii#1 #2#3 #4 {\expandafter
   \def\csname#1\endcsname##1 {\name*{#1##1}\cc*#3#2\black*boxii{#4} }}
\def\sbdef#1 #2#3 #4 {\expandafter
   \def\csname#1\endcsname##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}
\def\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\text\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\text\hc*{#1}
    \else\errhelp{Only horizontal or vertical labeling allowed.}%
    \errmessage{Bad points!}\fi\fi}}
\def\centertext #1 from #2 to #3 {%
  {\frompin{#2} \save*XY\frompin{#3} \diff*XY
    \ifdim\**X=0pt
      \advance\*Y*.5\**Y\text\vc*{\hbox{#1}}
    \else
    \ifdim\**Y=0pt
      \advance\*X*.5\**X\text\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
\def\text*circ#1 {\setbox\*bbox=\hbox{\ctextfont#1}\check*X\check*max{\wd\*bbox}%
            \put*box}
\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}}
\let\extracircinit\relax
\let\opticfontinit\relax
\def\circuit#1 {\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={\normalsize\rm}%
    \*fdef outlabelfont
    \*fdef labelfont
    \*fdef ctextfont
    \toks0={\normalsize\sf}%
    \*fdef symfont
    \toks0={\scriptsize\rm}%
    \*fdef pinnumberfont
    \*fdef functionfont
    \toks0={\footnotesize\rm}%
    \*fdef circlabelfont
    \toks0={\footnotesize\sf}%
    \*fdef inlabelfont
\or       % magstep 1
    \toks0={\large\rm}%
    \*fdef outlabelfont
    \*fdef labelfont
    \*fdef ctextfont
    \toks0={\large\sf}%
    \*fdef symfont
    \toks0={\footnotesize\rm}%
    \*fdef pinnumberfont
    \toks0={\small\rm}%
    \*fdef functionfont
    \*fdef circlabelfont
    \toks0={\small\sf}%
    \*fdef inlabelfont
\or       % magstep 2
    \toks0={\Large\rm}%
    \*fdef outlabelfont
    \*fdef labelfont
    \*fdef ctextfont
    \toks0={\Large\sf}%
    \*fdef symfont
    \toks0={\small\rm}%
    \*fdef pinnumberfont
    \toks0={\normalsize\rm}%
    \*fdef functionfont
    \*fdef circlabelfont
    \toks0={\normalsize\sf}%
    \*fdef inlabelfont
\or       % magstep 3
    \toks0={\LARGE\rm}%
    \*fdef outlabelfont
    \*fdef labelfont
    \*fdef ctextfont
    \toks0={\LARGE\sf}%
    \*fdef symfont
    \toks0={\normalsize\rm}%
    \*fdef pinnumberfont
    \toks0={\large\rm}%
    \*fdef functionfont
    \*fdef circlabelfont
    \toks0={\large\sf}%
    \*fdef inlabelfont
\or       % magstep 4
    \toks0={\huge\rm}%
    \*fdef outlabelfont
    \*fdef labelfont
    \*fdef ctextfont
    \toks0={\huge\sf}%
    \*fdef symfont
    \toks0={\large\rm}%
    \*fdef pinnumberfont
    \toks0={\Large\rm}%
    \*fdef functionfont
    \*fdef circlabelfont
    \toks0={\sf\Large}%
    \*fdef inlabelfont
\else\errhelp{0 ... 4 expected.}\errmessage{Bad magnification!}\fi
{\outlabelfont
\global\*spc 0.4em}%
\font\c*fnt=csyrest      scaled \*mag
\font\c*fntb=csycirc     scaled \*mag
\font\c*fntd=csydiod     scaled \*mag
\font\c*fntt=csybimos    scaled \*mag
\font\c*fntw=csywidko    scaled \*mag
\font\c*fnts=csysym      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
\extracircinit
\opticfontinit
\begingroup
  \def\P##1 {\store*XY{P##1}\check*X\reset*ifs}
  \let\.\junction
  \let\put\text*circ
  \let\text\text*circ
  \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\hbox{\kern-\X*min\unhbox\*bbox\kern\X*max}\endgroup}
\def\fallingEdge{{\c*fnts\char3}}
\def\raisingEdge{{\c*fnts\char2}}
\def\spike{{\c*fnts\char4}}
\def\ispike{{\c*fnts\char12}}
\def\squarePulse{{\c*fnts\char1}}
\def\squarePulses{{\c*fnts\char5}}
\def\sawtoothPuls{{\c*fnt\char6}}
\def\CIRCLogo {\setbox\*bbox=\hbox{\symfont
  \raise1.5ex\rlap{\kern1ex CIRC}\c*fnt\char252}%
  \check*max{\wd\*bbox}\put*box\reset*ifs}
\protectcirc
\ProcessOptions
\endinput
%%
%% End of file `circ.sty'.
