%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% wotree.sty                           2000-06-29-20:18 %
% Copyright (C) 2000            Eitan M. Gurari         %
%                                                       %
% This program can redistributed and/or modified under  %
% the terms of the LaTeX Project Public License         %
% Distributed from CTAN archives in directory           %
% macros/latex/base/lppl.txt; either version 1 of the   %
% License, or (at your option) any later version.       %
%                                                       %
% However, you are allowed to modify this program       %
% without changing its name, if you modify its          %
% signature. Changes to the signature can be introduced %
% with a directive of the form                          %
%            \message{signature}                        %
%                                                       %
%                             gurari@cse.ohio-state.edu %
%                 http://www.cse.ohio-state.edu/~gurari %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\immediate\write-1{version 2000-06-29-20:18}

\expandafter\edef\csname wo:recall\endcsname{\catcode`:=\the\catcode`:}
\catcode`\:=11

\Define\WO:GetY(2){\Vb=#2;}

\Define\WOEdge(2){
  \CSeg\WO:GetY(#2,EdgeGuide)
  \IF \GtDec(\Vb,0)
            \MoveToNode(#2,0,-1)
  \ELSE
            \MoveToNode(#2,0,1)
  \FI
  \MarkLoc(*1)   \Move(10,0)  \MarkLoc(*2)
  \MoveToLoc(EdgeGuide) \Move(0,10)  \MarkLoc(*3)
  \MoveToLL(*1,*2)(EdgeGuide,*3) \MarkLoc(*3)
  \MoveToNode(#1,1,0) \Move(5,0) \LineToLoc(EdgeGuide)
  \LineToLoc(*3)    \CSeg[2]\Line(*1,#2)
}
\def\WOTree#1{%
   \let\WO:tree=\empty
   \def\:queue{\init:count#1,,//}\put:queue
   \TreeSpec()()(\WOEdge)
   \TreeAlign(H,-1,0)(0,0,0)%
   \WO:TreeSpace
   \def\wo:temp{\Tree()(}%
   \expandafter\wo:temp\expandafter{\WO:tree})
    }

\def\put:queue{%
   \let\put:woitem=\empty
   \ifx \WO:tree\empty \else
       \expandafter\def\expandafter\WO:tree\expandafter{\WO:tree//}%
    \fi
   \ifx \:queue\empty  \def\wo:temp##1{}\else
   \let\wo:temp=\:queue \let\:queue=\empty \fi
   \wo:temp\put:queue }

\def\init:count#1,{%
   \def\WO:root{#1}\I=0;\WO:count}

\edef\wo:temp{\catcode`\noexpand\&=\the\catcode`\&}
\catcode`\&=13

\def\WO:count#1,{%
   \def\wo:temp{#1}\ifx \wo:temp\empty
       \expandafter\checkWO:root\WO:root//%
       \edef\wo:temp{\put:woitem\Val\I,\beforeWO:root}%
       \def\put:woitem{\noexpand&}%
       \expandafter\expandafter\expandafter\def
       \expandafter\expandafter\expandafter\WO:root
       \expandafter\expandafter\expandafter
          {\expandafter\wo:temp\WO:root}%
       \expandafter\expandafter\expandafter\def
       \expandafter\expandafter\expandafter\WO:tree
       \expandafter\expandafter\expandafter
          {\expandafter\WO:tree \WO:root}%
       \def\WO:root##1//{}\expandafter\WO:root
   \else
      \expandafter\def\expandafter\:queue
          \expandafter{\:queue\init:count#1,,//}%
      \I+1;\expandafter\WO:count
   \fi }

\wo:temp

\def\checkWO:root{\futurelet\wo:temp\ckWO:root}
\def\ckWO:root#1//{\edef\beforeWO:root{\ifx \wo:temp\WO \else
    \ifx \WO:tree\empty\else
         \noexpand\noexpand\noexpand\WO{}\fi\fi}}

\def\WO#1{\csname :WO:#1\endcsname}
\def\defWO#1#2{\expandafter\def\csname :WO:#1\endcsname{#2}}

\defWO{}{\llap{$\triangleright$ }}
\defWO{not}{\hrulefill~~\WO{}}
\defWO{or}{~$\bigoplus$}
\defWO{plus}{~$+$}
\defWO{xor}{~$\bigotimes$}

\Define\WOSpace(2){\def\WO:TreeSpace{\TreeSpace(C,#1,#2)}}
\WOSpace(10,20)

\wo:recall
\endinput

