[vox-tech] Re: latex help: drawing arrows

Peter Jay Salzman vox-tech@lists.lugod.org
Thu, 5 Sep 2002 18:44:17 -0700


ok, here's the solution.  i guess it looks ok.

pete






\newcommand{\Next}{\texttt{next}\ }
\newcommand{\Step}{\texttt{step}\ }


In contrast, \Step will cause gdb to step into the function and begin executing
the function line by line.

\begin{figure}[H]
\begin{pspicture}(0,0)(10,10)
\psset{unit=.4cm}
\rput[l](0,22){/* flawedswap.c: A flawed function that swaps two integers. */}
\rput[l](0,21){\#include $<$stdio.h$>$}
\rput[l](0,20){void swap(int a, int b);}
\rput[l](0,18){int main(void)}
\rput[l](0,17){\{}
\rput[l](1,16){int i = 4;}
\rput[l](1,15){int j = 4;}
\rput[l](1,13){printf("i: \%d, j: \%d\backslash{n}", i, j);}
\rput[l](1,12){swap(i, j);}
\rput[l](1,11){printf("i: \%d, j: \%d\backslash{n}", i, j);}
\rput[l](1,9){return 0;}
\rput[l](0,8){\}}
\rput[l](0,6){void swap(int a, int b)}
\rput[l](0,5){\{}
\rput[l](1,4){int c = a;}
\rput[l](1,3){a = b;}
\rput[l](1,2){b = c;}
\rput[l](0,1){\}}

\rput[l](17.5,13){step}
\psbezier[linearc=.25, linewidth=.75pt, linecolor=gray]
	{->}(12,13)(20,12.5)(20,12.4)(5,12)
\rput[l](22,9){step}
\psbezier[linearc=.25, linewidth=.75pt, linecolor=gray]
	{->}(5,12)(27,11.5)(27,4.5)(5,4)

\rput[l](10.5,3.5){step}
\psbezier[linearc=.25, linewidth=.75pt, linecolor=gray]
	{->}(5,4)(12,3.8)(12,3.4)(5,3)
\rput[l](10.5,2.5){step}
\psbezier[linearc=.25, linewidth=.75pt, linecolor=gray]
	{->}(5,3)(12,2.8)(12,2.4)(5,2)

\rput[l](18.5,2.5){step}
\psbezier[linearc=.25, linewidth=.75pt, linecolor=gray]
	{->}(5,2)(12,2.8)(25,0.0)(10.5,10.5)

\end{pspicture}
\label{fig:step}
\caption{Step goes into the function}
\end{figure}





begin p <p> 
> hola,
> 
> i'd like to draw a program execution chart, like this:
> 
>    #include <stdio.h>
>    void swap(int *a, int *b);
> 
>    int main(void)
>    {
>       int x = 3;
>       int y = 4;
>       printf("x: %d, y: %d\n", x, y);
>       swap(&x, &y);
>       printf("x: %d, y: %d\n", x, y);
>       return 0;
>    }
> 
>    void swap(int *a, int *b)
>    {
>       int c = *a;
>       *a = *b;
>       *b = c;
>    }
> 
> 
> but with a curved arrow that points from line 1 to line 2.  and then
> another line that points from line 2 to line 3.  and then line 3 to line
> 4.  and so on.
> 
> basically, the arrows will show the order in which statements get
> executed.
> 
> i'm thumbing through the latex graphics companion, and it looks like
> either the pstricks or metafont/metapost package seems the best way to
> go.  i don't know either one (yet) and they both look pretty difficult
> to learn.
> 
> can i get some advice?  what's the easiest way to do something like
> this?

-- 
Fingerprint: B9F1 6CF3 47C4 7CD8 D33E 70A9 A3B9 1945 67EA 951D