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


{\tt \#include $<$XLX\_\-p.h$>$}\par
{\tt \#include $<$stdlib.h$>$}\par
{\tt \#include $<$string.h$>$}\par
{\tt \#include $<$stdio.h$>$}\par
\subsection*{Functions}
\begin{CompactItemize}
\item 
int \hyperlink{stack_8c_fbda485196df1d610370bef40488a96b}{XLX\_\-initStack} (\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_96788aac23ed927799fe4545c7a8c240}{XLX\_\-endStack} (\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_1f76b289b6e6ddcf686100fc1e0f1cc2}{XLX\_\-destroyStack} (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$stack, \hyperlink{XLX_8h_9bd2b34a583985a1c36cbe705c2c9287}{XLX\_\-pDelete} dFn)
\begin{CompactList}\small\item\em Free the memory allocated to a stack and its elements. \item\end{CompactList}\item 
int \hyperlink{stack_8c_ac70bf79231d8e79fb14f6d3972c2472}{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_df82d85e99f10e6710adedf5cff92b44}{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_2b3722f47dd9d0a439db94c4dd788ddd}{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_a1bc53ebd2c260e18cac1edc4602664f}{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.10 2011/03/25 21:01:49 saxton Exp \end{Desc}


\subsection{Function Documentation}
\hypertarget{stack_8c_1f76b289b6e6ddcf686100fc1e0f1cc2}{
\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\_\-destroyStack ({\bf XLX\_\-stack} $\ast$ {\em stack}, \/  {\bf XLX\_\-pDelete} {\em dFn})}}
\label{stack_8c_1f76b289b6e6ddcf686100fc1e0f1cc2}


Free the memory allocated to a stack and its elements. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em stack}]Stack to end\item[{\em dFn}]Function to call to delete objects on the stack \end{description}
\end{Desc}


References XLX\_\-endStack(), and XLX\_\-pop().\hypertarget{stack_8c_a1bc53ebd2c260e18cac1edc4602664f}{
\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 ({\bf XLX\_\-stack} $\ast$ {\em stack})}}
\label{stack_8c_a1bc53ebd2c260e18cac1edc4602664f}


Print out the stack information. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em stack}]Stack to dump \end{description}
\end{Desc}


References \_\-XLX\_\-stack::base, \_\-XLX\_\-stack::limit, and \_\-XLX\_\-stack::used.\hypertarget{stack_8c_96788aac23ed927799fe4545c7a8c240}{
\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\_\-endStack ({\bf XLX\_\-stack} $\ast$ {\em stack})}}
\label{stack_8c_96788aac23ed927799fe4545c7a8c240}


Free the memory allocated to a stack. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em stack}]Stack to free \end{description}
\end{Desc}


References \_\-XLX\_\-stack::base, \_\-XLX\_\-stack::limit, and \_\-XLX\_\-stack::used.

Referenced by XLX\_\-destroyStack().\hypertarget{stack_8c_fbda485196df1d610370bef40488a96b}{
\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\_\-initStack ({\bf XLX\_\-stack} $\ast$ {\em stack}, \/  unsigned int {\em limit})}}
\label{stack_8c_fbda485196df1d610370bef40488a96b}


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}


References \_\-XLX\_\-stack::base, \_\-XLX\_\-stack::limit, and \_\-XLX\_\-stack::used.

Referenced by XLX\_\-initState().\hypertarget{stack_8c_2b3722f47dd9d0a439db94c4dd788ddd}{
\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 ({\bf XLX\_\-stack} $\ast$ {\em stack}, \/  unsigned int {\em depth})}}
\label{stack_8c_2b3722f47dd9d0a439db94c4dd788ddd}


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}


References \_\-XLX\_\-stack::base, and \_\-XLX\_\-stack::used.

Referenced by XLX\_\-character(), XLX\_\-character\_\-tag(), and XLX\_\-start().\hypertarget{stack_8c_df82d85e99f10e6710adedf5cff92b44}{
\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 ({\bf XLX\_\-stack} $\ast$ {\em stack})}}
\label{stack_8c_df82d85e99f10e6710adedf5cff92b44}


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}


References \_\-XLX\_\-stack::base, and \_\-XLX\_\-stack::used.

Referenced by XLX\_\-character\_\-tag(), XLX\_\-destroyStack(), and XLX\_\-end().\hypertarget{stack_8c_ac70bf79231d8e79fb14f6d3972c2472}{
\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 ({\bf XLX\_\-stack} $\ast$ {\em stack}, \/  void $\ast$ {\em ptr})}}
\label{stack_8c_ac70bf79231d8e79fb14f6d3972c2472}


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}


References \_\-XLX\_\-stack::base, \_\-XLX\_\-stack::limit, and \_\-XLX\_\-stack::used.

Referenced by XLX\_\-character\_\-tag(), XLX\_\-initState(), and XLX\_\-start().