\hypertarget{stack_8c}{
\section{stack.c File Reference}
\label{stack_8c}\index{stack.c@{stack.c}}
}
Stack manipulation functions. 

{\tt \#include \char`\"{}XLX\_\-p.h\char`\"{}}\par
{\tt \#include \char`\"{}stdlib.h\char`\"{}}\par
{\tt \#include \char`\"{}string.h\char`\"{}}\par
{\tt \#include \char`\"{}stdio.h\char`\"{}}\par


Include dependency graph for stack.c:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=149pt]{stack_8c__incl}
\end{center}
\end{figure}
\subsection*{Functions}
\begin{CompactItemize}
\item 
int \hyperlink{stack_8c_a0}{XLX\_\-init\-Stack} (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$stack, unsigned int limit)
\begin{CompactList}\small\item\em Initialise a stack. \item\end{CompactList}\item 
void \hyperlink{stack_8c_a1}{XLX\_\-end\-Stack} (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$stack)
\begin{CompactList}\small\item\em Free the memory allocated to a stack. \item\end{CompactList}\item 
void \hyperlink{stack_8c_a2}{XLX\_\-destroy\-Stack} (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$stack, \hyperlink{XLX_8h_a5}{XLX\_\-p\-Delete} d\-Fn)
\begin{CompactList}\small\item\em Free the memory allocated to a stack and its elements. \item\end{CompactList}\item 
int \hyperlink{stack_8c_a3}{XLX\_\-push} (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$stack, void $\ast$ptr)
\begin{CompactList}\small\item\em Put a new item on the top of a stack. \item\end{CompactList}\item 
void $\ast$ \hyperlink{stack_8c_a4}{XLX\_\-pop} (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$stack)
\begin{CompactList}\small\item\em Remove and return the top item on a stack. \item\end{CompactList}\item 
void $\ast$ \hyperlink{stack_8c_a5}{XLX\_\-peek} (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$stack, unsigned int depth)
\begin{CompactList}\small\item\em Look at an item on a stack without removing it. \item\end{CompactList}\item 
void \hyperlink{stack_8c_a6}{XLX\_\-dump} (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$stack)
\begin{CompactList}\small\item\em Print out the stack information. \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
Stack manipulation functions. 

\begin{Desc}
\item[Author:]James Swain \& Owen Saxton\end{Desc}
\begin{Desc}
\item[Id]\hyperlink{stack_8c}{stack.c},v 1.9 2007/05/10 20:04:11 saxton Exp \end{Desc}


\subsection{Function Documentation}
\hypertarget{stack_8c_a2}{
\index{stack.c@{stack.c}!XLX_destroyStack@{XLX\_\-destroyStack}}
\index{XLX_destroyStack@{XLX\_\-destroyStack}!stack.c@{stack.c}}
\subsubsection[XLX\_\-destroyStack]{\setlength{\rightskip}{0pt plus 5cm}void XLX\_\-destroy\-Stack (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$ {\em stack}, \hyperlink{XLX_8h_a5}{XLX\_\-p\-Delete} {\em d\-Fn})}}
\label{stack_8c_a2}


Free the memory allocated to a stack and its elements. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em stack}]Stack to end\item[{\em d\-Fn}]Function to call to delete objects on the stack\end{description}
\end{Desc}
\hypertarget{stack_8c_a6}{
\index{stack.c@{stack.c}!XLX_dump@{XLX\_\-dump}}
\index{XLX_dump@{XLX\_\-dump}!stack.c@{stack.c}}
\subsubsection[XLX\_\-dump]{\setlength{\rightskip}{0pt plus 5cm}void XLX\_\-dump (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$ {\em stack})}}
\label{stack_8c_a6}


Print out the stack information. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em stack}]Stack to dump\end{description}
\end{Desc}
\hypertarget{stack_8c_a1}{
\index{stack.c@{stack.c}!XLX_endStack@{XLX\_\-endStack}}
\index{XLX_endStack@{XLX\_\-endStack}!stack.c@{stack.c}}
\subsubsection[XLX\_\-endStack]{\setlength{\rightskip}{0pt plus 5cm}void XLX\_\-end\-Stack (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$ {\em stack})}}
\label{stack_8c_a1}


Free the memory allocated to a stack. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em stack}]Stack to free\end{description}
\end{Desc}
\hypertarget{stack_8c_a0}{
\index{stack.c@{stack.c}!XLX_initStack@{XLX\_\-initStack}}
\index{XLX_initStack@{XLX\_\-initStack}!stack.c@{stack.c}}
\subsubsection[XLX\_\-initStack]{\setlength{\rightskip}{0pt plus 5cm}int XLX\_\-init\-Stack (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$ {\em stack}, unsigned int {\em limit})}}
\label{stack_8c_a0}


Initialise a stack. 

This routine allocates memory to hold the stack contents and sets the limit and used values.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em stack}]Stack to initialise\item[{\em limit}]Size of the stack\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0}]If the stack was successfully initialised \item[{\em -1}]If there was an error allocating memory for the stack\end{description}
\end{Desc}
\hypertarget{stack_8c_a5}{
\index{stack.c@{stack.c}!XLX_peek@{XLX\_\-peek}}
\index{XLX_peek@{XLX\_\-peek}!stack.c@{stack.c}}
\subsubsection[XLX\_\-peek]{\setlength{\rightskip}{0pt plus 5cm}void$\ast$ XLX\_\-peek (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$ {\em stack}, unsigned int {\em depth})}}
\label{stack_8c_a5}


Look at an item on a stack without removing it. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em stack}]Stack to peek at\item[{\em depth}]Depth from the top of the stack of item to peek at\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]Item on the top of the stack\end{Desc}
\hypertarget{stack_8c_a4}{
\index{stack.c@{stack.c}!XLX_pop@{XLX\_\-pop}}
\index{XLX_pop@{XLX\_\-pop}!stack.c@{stack.c}}
\subsubsection[XLX\_\-pop]{\setlength{\rightskip}{0pt plus 5cm}void$\ast$ XLX\_\-pop (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$ {\em stack})}}
\label{stack_8c_a4}


Remove and return the top item on a stack. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em stack}]Stack to pop item off\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]Item popped off the top of the stack\end{Desc}
\hypertarget{stack_8c_a3}{
\index{stack.c@{stack.c}!XLX_push@{XLX\_\-push}}
\index{XLX_push@{XLX\_\-push}!stack.c@{stack.c}}
\subsubsection[XLX\_\-push]{\setlength{\rightskip}{0pt plus 5cm}int XLX\_\-push (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$ {\em stack}, void $\ast$ {\em ptr})}}
\label{stack_8c_a3}


Put a new item on the top of a stack. 

If the stack is already full, its size is doubled.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em stack}]Stack to push item onto\item[{\em ptr}]Pointer to push onto stack\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0}]If the item is added successfully \item[{\em -1}]If the stack needs to be extended to accomodate the new item and the memory allocation failed\end{description}
\end{Desc}
