% flow.sty  5 september 1989, C.M. Lindhout.
%
%  Copyright (C) by CAWCS, Royal Netherlands Navy.
%  This program may be freely used and copied but may not be sold
%  without the author's written permission.  This notice must remain
%  in any copy or derivative.
%
%  Please send improvements, bug fixes, comments, etc., to
%    Marion van Geest,
%    CAWCS, 
%    Royal Netherlands Navy,
%    P.O.BOX 10000, 
%    1780 CA Den Helder, 
%    The Netherlands.

%  Modifications.
%  --------------
% Version 2, march 1993,
%  1) Error in empty \THEN in \IF statement corrected
%  2) \tenrm for typesetting second parameter in \STRUCT replaced by \rm\small.
%     The reason for using \tenrm in the first place, was that originally 
%     flow.sty was designed to be used with a very specific documentstyle that 
%     was always typeset in 11pts. When flow.sty was adapted for more general 
%     use, this \tenrm was forgotten. \rm\small serves the same purpose in our 
%     document style, but is generally a better solution.

\ProvidesPackage{flow}[1989/09/05 v2.0 Flow macro's.]
%
\newdimen\unitwidth%
\unitwidth=60pt%
\newbox\thentext%
\newbox\elsetext%
\newbox\savethentext%
\newbox\saveelsetext%
\newdimen\unitheight%
\newdimen\unitysize%
\newdimen\unitxsize%
\newdimen\unitspace%
\newdimen\wa%
\newdimen\ha%
\newdimen\wb%
\newdimen\hb%
\newdimen\wda%
\newdimen\hta%
\newdimen\wdb%
\newdimen\htb%
%
\def\setiftext#1#2{\setbox\thentext=\hbox{#1}\setbox\elsetext=\hbox{#2}}%
\setiftext{}{}%
%
\def\cvline#1{%
  \hbox{\kern.5\unitwidth\rule{0.0067in}{#1}}%
}%
%
\def\chline#1{%
  \hbox{%
    \raise.5\unitheight%
    \hbox to #1{\leaders\hrule height0.0067in\hfill}%
  }%
}%
%
\def\VCENTER#1{%
  \raise.5\unitspace%
  \hbox{#1}%
  \rule{0pt}{\unitheight}%
}%
%
\def\makepicture#1{%
  \ifvmode%
    \cvline{.5\unitspace}
    \hbox to \unitwidth{\hfil\hbox{#1}\hfil}%
    \cvline{.5\unitspace}
  \else%
    \chline{.5\unitspace}%
    \VCENTER{#1}%
    \chline{.5\unitspace}%
  \fi%
}%
%
\def\ACTION#1{\makepicture{\makeaction{#1}}}%
%
\def\makeaction#1{%
  \wa=0.86\unitwidth%
  \begin{picture}(90,60)%
    \put(00,00){\line( 0, 1){60}}%
    \put(90,00){\line( 0, 1){60}}%
    \put(00,00){\line( 1, 0){90}}%
    \put(00,60){\line( 1, 0){90}}%
    \put(02,00){%
      \vbox to \unitysize{%
        \vfil%
        \parbox{\wa}{\raggedright#1}%
        \vfil%
      }%
    }%
  \end{picture}%
}%
%
\def\PROC#1#2{\makepicture{\makeproc{#1}{#2}}}%
%
\def\makeproc#1#2{%
  \wa=.76\unitwidth%
  \wb=.80\unitwidth%
  \ha=.56\unitwidth%
  \begin{picture}(90,60)
    \put(00,00){\line( 0, 1){60}}
    \put(05,00){\line( 0, 1){60}}
    \put(85,00){\line( 0, 1){60}}
    \put(90,00){\line( 0, 1){60}}
    \put(00,00){\line( 1, 0){90}}
    \put(00,60){\line( 1, 0){90}}
    \put(07,02){%
      \vbox to \ha{%
        \vfil%
        \parbox{\wa}{\raggedright#2}%
        \vfil%
        \vbox to 2ex{}%
      }%
    }%
    \put(05,02){%
      \vbox to 2ex{%
        \hbox to \wb{\leaders\hrule height0.0067in\hfill}%
        \vfil%
        \hbox to \wb{\hfil#1\hfil}%
      }%
    }%
  \end{picture}%
}%
%
\def\LABEL#1{\makepicture{\makelabel{#1}}}%
%
\def\makelabel#1{%
  \begin{picture}(30,30)
    \put(15,15){\circle{30}}
    \put(00,00){\makebox(30,30){#1}}
  \end{picture}%
}%
%
\def\makeif#1{%
  \wa=\unitxsize%
  \advance\wa by -2ex%
  \wb=\unitxsize%
  \advance\wb by -6ex%
  \begin{picture}(90,60)
    \put(00,30){\line( 3, 2){45}}
    \put(45,60){\line( 3,-2){45}}
    \put(90,30){\line(-3,-2){45}}
    \put(45,00){\line(-3, 2){45}}
    \put(90,33){\hbox to 0pt{\copy\elsetext\hss}}
    \put(00,00){\vbox to 0pt{\hbox to 43\unitlength{\hfil\copy\thentext}\vss}}
    \put(00,30){%
      \parbox{\unitxsize}{%
        \parshape=3 3ex\wb 1ex\wa 3ex\wb%
        \begin{center}%
          #1%
        \end{center}%
      }%
    }%
  \end{picture}%
}%
%
\def\IF#1\THEN#2\ELSE#3\ENDIF{%
  \setbox0=\vbox{#2}%
  \setbox1=\vbox{#3}%
  \wda=\wd0%
  \hta=\ht0%
  \wdb=\wd1%
  \htb=\ht1%
  \hbox{%
    \vbox{%
      \makepicture{\makeif{#1}}%
    }%
    \kern-.5\unitspace\chline{.5\unitspace}%
    \ifdim\wda=0pt%
      \wa=.5\unitwidth%
      \advance\wa by 0.0067in%
    \else%
      \wa=\wda%
    \fi%
    \ifdim\wdb=0pt%
      \advance\wa by -\unitwidth%
      \advance\wa by .5\unitspace%
    \else%
      \advance\wa by -.5\unitwidth%
    \fi%
    \chline{\wa}%
    \rule{0.0067in}{.5\unitheight}%
  }%
  \hbox{%
    \vbox{%
      \ifdim\htb>\hta%
        \hb=\htb%
        \advance\hb by -\hta%
        \cvline{\hb}%
      \fi%
      \box0%
    }%
    \ifdim\wdb=0pt%
      \hbox{%
        \kern.5\unitspace%
        \rule{0.0067in}{\hta}%
        \kern.5\unitspace%
      }%
    \else%
      \vbox{%
        \ifdim\hta>\htb%
          \ha=\hta%
          \advance\ha by -\htb%
          \cvline{\ha}%
        \fi%
        \box1%
      }%
    \fi%
  }%
  \kern -0.0067in%
  \hbox{%
    \kern.5\unitwidth%
    \ifdim\wda=0pt%
      \wa=.5\unitwidth%
      \advance\wa by .0067in%
    \else
      \wa=\wda%
    \fi%
    \ifdim\wdb=0pt%
      \advance\wa by -.5\unitwidth%
      \advance\wa by .5\unitspace%
    \fi%
    \rule{\wa}{0.0067in}%
  }%
}%
%
\def\WHILE#1#2\ENDWHILE{%
  \IF{#1}%
  \THEN{%
    \setbox\savethentext=\copy\thentext%
    \setbox\saveelsetext=\copy\elsetext%
    \setbox\elsetext=\copy\savethentext%
    \setbox\thentext=\copy\saveelsetext%
    \ifdim\wd\thentext=0pt%
      \ifdim\wd\elsetext=0pt%
        \setiftext{n}{y}%
      \fi%
    \fi%
    \REPEAT{%
      \setbox\thentext=\copy\savethentext%
      \setbox\elsetext=\copy\saveelsetext%
      #2%
    }%
    \UNTIL{#1}%
  }%
  \ELSE{}%
  \ENDIF%
}%
%
\def\REPEAT#1\UNTIL#2{%
  \setbox0=\vbox{#1}%
  \wda=\wd0%
  \hta=\ht0%
  \hbox{%
    \kern.5\unitwidth%
    \ifdim\wda=0pt%
      \wa=\unitwidth%
    \else%
      \wa=\wda%
    \fi%
    \advance\wa by -.5\unitwidth%
    \advance\wa by .5\unitspace%
    \rule{\wa}{0.0067in}%
  }%
  \kern -0.0067in%
  \hbox{%
    \box0%
    \kern.5\unitspace%
    \rule{0.0067in}{\hta}%
    \kern.5\unitspace%
  }%
  \hbox{%
    \vbox{%
      \makepicture{\makeif{#2}}%
    }%
    \kern-.5\unitspace\chline{.5\unitspace}%
    \ifdim\wda=0pt%
      \wa=\unitwidth%
    \else%
      \wa=\wda%
    \fi%
    \advance\wa by -\unitwidth%
    \advance\wa by .5\unitspace%
    \chline{\wa}%
    \rule[.5\unitheight]{0.0067in}{.5\unitheight}%
  }%
}%
%
\def\WHEN#1#2{%
  \hbox{%
    \vbox{%
      \hbox{%
        \kern.5\unitspace%
        \parbox{\unitxsize}{\raggedright#1}%
      }%
      \kern.5\unitspace%
      \chline{\unitwidth}%
    }%
    {#2}%
    \chline{.5\unitspace}%
  }%
}%
%
\def\CASE#1#2\ENDCASE{%
  \setbox0=\vbox{#2}%
  \wda=\wd0%
  \hta=\ht0%
  \setbox\savethentext=\copy\thentext%
  \setbox\saveelsetext=\copy\elsetext%
  \setiftext{}{}%
  \makepicture{\makeif{#1}}%
  \setbox\thentext=\copy\savethentext%
  \setbox\elsetext=\copy\saveelsetext%
  \hbox{%
    \cvline{\hta}%
    \vbox{%
      \box0%
      \kern-0.0067in%
      \hbox to \wda{\leaders\hrule height0.0067in\hfill}%
    }%
    \ha=\hta%
    \advance\ha by -.5\unitheight%
    \rule{0.0067in}{\ha}%
    \kern.5\unitspace%
  }%
}%
%
\def\STRUCT#1#2#3{%
  \vbox{%
    \unitheight=0.7\unitwidth%
    \unitysize=0.6\unitwidth%
    \unitxsize=0.9\unitwidth%
    \unitspace=0.1\unitwidth%
    \unitlength=0.01\unitwidth%
    \baselineskip=0pt%
    \lineskip=0pt%
    \parindent=0pt%
    \parskip=0pt%
    \linethickness{0.0067in}%
    \hbox{%
      \hbox to .5\unitspace{}%
      \hbox{%
        \begin{picture}(90,50)
          \put(45,15){\oval(90,30)}
          \put(00,00){\makebox(90,30){#1}}
        \end{picture}%
        \hbox to .5\unitwidth{}%
        \wa=\textwidth%
        \advance\wa by -1.5\unitwidth%
        \raise\unitspace%
        \hbox{\rm\small\parbox{\wa}{#2}}%
      }%
    }%
    \cvline{.5\unitspace}%
    {#3}%
    \cvline{.5\unitspace}%
    \hbox{%
      \hbox to .5\unitspace{}%
      \hbox{%
        \begin{picture}(90,30)
          \put(45,15){\oval(90,30)}
          \put(00,00){\makebox(90,30){return}}
        \end{picture}%
      }%
    }%
  }%
}%
\endinput