\hypertarget{util_8c}{
\section{util.c File Reference}
\label{util_8c}\index{util.c@{util.c}}
}
General character/conversion utilities.  


{\tt \#include $<$XLX\_\-p.h$>$}\par
{\tt \#include $<$EXPAT/expat.h$>$}\par
{\tt \#include $<$stdlib.h$>$}\par
{\tt \#include $<$stdio.h$>$}\par
{\tt \#include $<$string.h$>$}\par
{\tt \#include $<$ctype.h$>$}\par
\subsection*{Functions}
\begin{CompactItemize}
\item 
static int \hyperlink{util_8c_74886f74f809675934828d0b05defb21}{strtobin} (int optns, const char $\ast$string, unsigned int len, void $\ast$value)
\begin{CompactList}\small\item\em Convert a string to binary. \item\end{CompactList}\item 
int \hyperlink{util_8c_aed87016200cf1e4652ae9d0ae9e08e2}{XLX\_\-isEnabled} (const char $\ast$$\ast$attribute, int $\ast$enabled)
\begin{CompactList}\small\item\em Reads the attribute list and sets {\em enabled\/} accordingly. \item\end{CompactList}\item 
int \hyperlink{util_8c_660b4f1ed1825e0f464cf4e35958fe77}{XLX\_\-getAttribute} (const char $\ast$$\ast$attribute, const char $\ast$name, int $\ast$value)
\begin{CompactList}\small\item\em Find a named attribute in an attribute list. \item\end{CompactList}\item 
int \hyperlink{util_8c_d8a7a94d974383d5d7d77c6218938b6a}{XLX\_\-strtoi} (const char $\ast$string, unsigned int len, int $\ast$value)
\begin{CompactList}\small\item\em Convert a string to a signed 32-bit integer. \item\end{CompactList}\item 
int \hyperlink{util_8c_a8d794149203cb3a8d52cf58051ceb71}{XLX\_\-strtou} (const char $\ast$string, unsigned int len, unsigned int $\ast$value)
\begin{CompactList}\small\item\em Convert a string to an unsigned 32-bit integer. \item\end{CompactList}\item 
int \hyperlink{util_8c_7d2a1e591a5878dead4b0dad971a39dd}{XLX\_\-strtoll} (const char $\ast$string, unsigned int len, long long $\ast$value)
\begin{CompactList}\small\item\em Convert a string to a signed 64-bit integer. \item\end{CompactList}\item 
int \hyperlink{util_8c_21f440de32b115fc56bcae71cf7047be}{XLX\_\-strtoull} (const char $\ast$string, unsigned int len, unsigned long long $\ast$value)
\begin{CompactList}\small\item\em Convert a string to an unsigned 64-bit integer. \item\end{CompactList}\item 
int \hyperlink{util_8c_a17b2d041e46090a3a155f0f22316b23}{XLX\_\-getLineNum} (\hyperlink{struct__XLX__state}{XLX\_\-state} $\ast$state)
\begin{CompactList}\small\item\em Get the current line number. \item\end{CompactList}\item 
void \hyperlink{util_8c_d1b8bf73ff8abc87ddcbdd47b25c85fa}{XLX\_\-valError} (\hyperlink{struct__XLX__state}{XLX\_\-state} $\ast$state, const char $\ast$func, const char $\ast$string, unsigned int len)
\begin{CompactList}\small\item\em Report value string to be in error. \item\end{CompactList}\item 
void \hyperlink{util_8c_97b8ce7af015c52561f69e47e7b9eb95}{XLX\_\-attrError} (\hyperlink{struct__XLX__state}{XLX\_\-state} $\ast$state, const char $\ast$func, const char $\ast$name)
\begin{CompactList}\small\item\em Report missing attribute error. \item\end{CompactList}\item 
void \hyperlink{util_8c_1b65c9da27c5b90061b226fd01d10fe0}{XLX\_\-attrValError} (\hyperlink{struct__XLX__state}{XLX\_\-state} $\ast$state, const char $\ast$func, const char $\ast$name)
\begin{CompactList}\small\item\em Report invalid attribute value error. \item\end{CompactList}\item 
void \hyperlink{util_8c_947d8ce00b1f69329842b3ec2814cbdd}{XLX\_\-dispFileName} (\hyperlink{struct__XLX__state}{XLX\_\-state} $\ast$state, const char $\ast$func)
\begin{CompactList}\small\item\em Display the name of the current file being parsed. \item\end{CompactList}\item 
int \hyperlink{util_8c_a5626385cb58d8d0c1898a78da30676a}{XLX\_\-ischar} (const char $\ast$string, unsigned int len)
\begin{CompactList}\small\item\em Test a string for valid characters. \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
General character/conversion utilities. 

\begin{Desc}
\item[Author:]James Swain \& Owen Saxton\end{Desc}
\begin{Desc}
\item[Id]\hyperlink{util_8c}{util.c},v 1.17 2011/03/25 21:01:49 saxton Exp \end{Desc}


\subsection{Function Documentation}
\hypertarget{util_8c_74886f74f809675934828d0b05defb21}{
\index{util.c@{util.c}!strtobin@{strtobin}}
\index{strtobin@{strtobin}!util.c@{util.c}}
\subsubsection[{strtobin}]{\setlength{\rightskip}{0pt plus 5cm}int strtobin (int {\em optns}, \/  const char $\ast$ {\em string}, \/  unsigned int {\em len}, \/  void $\ast$ {\em value})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{util_8c_74886f74f809675934828d0b05defb21}


Convert a string to binary. 

This routine converts a decimal or hexadecimal string to an integer. By default the string must be unsigned and the integer is 32-bit. Options allow the string to be signed, and the integer to be 64-bit.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em optns}]Bit mask of conversion options: 1 = signed, 2 = 64-bit\item[{\em string}]String to convert\item[{\em len}]Maximum length of the string (including whitespace)\item[{\em value}]Address of the converted value\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0}]If the string represents a valid integer \item[{\em -1}]If the string contains invalid characters \end{description}
\end{Desc}


Referenced by XLX\_\-strtoi(), XLX\_\-strtoll(), XLX\_\-strtou(), and XLX\_\-strtoull().\hypertarget{util_8c_97b8ce7af015c52561f69e47e7b9eb95}{
\index{util.c@{util.c}!XLX\_\-attrError@{XLX\_\-attrError}}
\index{XLX\_\-attrError@{XLX\_\-attrError}!util.c@{util.c}}
\subsubsection[{XLX\_\-attrError}]{\setlength{\rightskip}{0pt plus 5cm}void XLX\_\-attrError ({\bf XLX\_\-state} $\ast$ {\em state}, \/  const char $\ast$ {\em func}, \/  const char $\ast$ {\em name})}}
\label{util_8c_97b8ce7af015c52561f69e47e7b9eb95}


Report missing attribute error. 

This routine displays the name of the missing attribute, along with the line number in and the name of the file being parsed.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em state}]Current parse state\item[{\em func}]Name of function reporting the error\item[{\em name}]Attribute name \end{description}
\end{Desc}


References \_\-XLX\_\-state::parser, \_\-XLX\_\-state::verbose, and XLX\_\-dispFileName().\hypertarget{util_8c_1b65c9da27c5b90061b226fd01d10fe0}{
\index{util.c@{util.c}!XLX\_\-attrValError@{XLX\_\-attrValError}}
\index{XLX\_\-attrValError@{XLX\_\-attrValError}!util.c@{util.c}}
\subsubsection[{XLX\_\-attrValError}]{\setlength{\rightskip}{0pt plus 5cm}void XLX\_\-attrValError ({\bf XLX\_\-state} $\ast$ {\em state}, \/  const char $\ast$ {\em func}, \/  const char $\ast$ {\em name})}}
\label{util_8c_1b65c9da27c5b90061b226fd01d10fe0}


Report invalid attribute value error. 

This routine displays the name of the attribute, along with the line number in and the name of the file being parsed.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em state}]Current parse state\item[{\em func}]Name of function reporting the error\item[{\em name}]Attribute name \end{description}
\end{Desc}


References \_\-XLX\_\-state::parser, \_\-XLX\_\-state::verbose, and XLX\_\-dispFileName().\hypertarget{util_8c_947d8ce00b1f69329842b3ec2814cbdd}{
\index{util.c@{util.c}!XLX\_\-dispFileName@{XLX\_\-dispFileName}}
\index{XLX\_\-dispFileName@{XLX\_\-dispFileName}!util.c@{util.c}}
\subsubsection[{XLX\_\-dispFileName}]{\setlength{\rightskip}{0pt plus 5cm}void XLX\_\-dispFileName ({\bf XLX\_\-state} $\ast$ {\em state}, \/  const char $\ast$ {\em func})}}
\label{util_8c_947d8ce00b1f69329842b3ec2814cbdd}


Display the name of the current file being parsed. 

This routine is used when reporting errors during the parsing.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em state}]Current parse state\item[{\em func}]Name of function reporting the error \end{description}
\end{Desc}


References \_\-XLX\_\-state::fName.

Referenced by XLX\_\-attrError(), XLX\_\-attrValError(), XLX\_\-end(), XLX\_\-parse(), XLX\_\-start(), and XLX\_\-valError().\hypertarget{util_8c_660b4f1ed1825e0f464cf4e35958fe77}{
\index{util.c@{util.c}!XLX\_\-getAttribute@{XLX\_\-getAttribute}}
\index{XLX\_\-getAttribute@{XLX\_\-getAttribute}!util.c@{util.c}}
\subsubsection[{XLX\_\-getAttribute}]{\setlength{\rightskip}{0pt plus 5cm}int XLX\_\-getAttribute (const char $\ast$$\ast$ {\em attribute}, \/  const char $\ast$ {\em name}, \/  int $\ast$ {\em value})}}
\label{util_8c_660b4f1ed1825e0f464cf4e35958fe77}


Find a named attribute in an attribute list. 

This routine looks for the attribute in the attribute list and returns its associated value (signed decimal or hexadecimal string) converted to an integer.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em attribute}]Attribute list from the start tag of the element\item[{\em name}]Attribute to find and return\item[{\em value}]Location to put value of attribute\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0}]If the name is found and its value is valid \item[{\em -1}]If the value is not a valid number \item[{\em -2}]If the name is missing from the attribute list \end{description}
\end{Desc}


References XLX\_\-strtoi().\hypertarget{util_8c_a17b2d041e46090a3a155f0f22316b23}{
\index{util.c@{util.c}!XLX\_\-getLineNum@{XLX\_\-getLineNum}}
\index{XLX\_\-getLineNum@{XLX\_\-getLineNum}!util.c@{util.c}}
\subsubsection[{XLX\_\-getLineNum}]{\setlength{\rightskip}{0pt plus 5cm}int XLX\_\-getLineNum ({\bf XLX\_\-state} $\ast$ {\em state})}}
\label{util_8c_a17b2d041e46090a3a155f0f22316b23}


Get the current line number. 

This routine obtains the current line number in the file being parsed.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em state}]Current parse state\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]The current line number \end{Desc}


References \_\-XLX\_\-state::parser.\hypertarget{util_8c_a5626385cb58d8d0c1898a78da30676a}{
\index{util.c@{util.c}!XLX\_\-ischar@{XLX\_\-ischar}}
\index{XLX\_\-ischar@{XLX\_\-ischar}!util.c@{util.c}}
\subsubsection[{XLX\_\-ischar}]{\setlength{\rightskip}{0pt plus 5cm}int XLX\_\-ischar (const char $\ast$ {\em string}, \/  unsigned int {\em len})}}
\label{util_8c_a5626385cb58d8d0c1898a78da30676a}


Test a string for valid characters. 

Checks that the string has valid graphic characters after any leading whitespace and before the start of the next tag.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em string}]Address of string to test\item[{\em len}]Max length of the string (including whitespace)\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 1}]If the string has valid characters before the start of the next tag \item[{\em 0}]If the string does not have valid characters before the start of the next tag \end{description}
\end{Desc}


Referenced by XLX\_\-character\_\-tag().\hypertarget{util_8c_aed87016200cf1e4652ae9d0ae9e08e2}{
\index{util.c@{util.c}!XLX\_\-isEnabled@{XLX\_\-isEnabled}}
\index{XLX\_\-isEnabled@{XLX\_\-isEnabled}!util.c@{util.c}}
\subsubsection[{XLX\_\-isEnabled}]{\setlength{\rightskip}{0pt plus 5cm}int XLX\_\-isEnabled (const char $\ast$$\ast$ {\em attribute}, \/  int $\ast$ {\em enabled})}}
\label{util_8c_aed87016200cf1e4652ae9d0ae9e08e2}


Reads the attribute list and sets {\em enabled\/} accordingly. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em attribute}]Attribute list from the start tag of the element\item[{\em enabled}]Location to write 0 (FALSE) or 1 (TRUE)\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0}]If the attribute list was read correctly \item[{\em -1}]If there was a bad value for the 'enabled' attribute \item[{\em -2}]If there was no 'enabled' attribute \end{description}
\end{Desc}
\hypertarget{util_8c_d8a7a94d974383d5d7d77c6218938b6a}{
\index{util.c@{util.c}!XLX\_\-strtoi@{XLX\_\-strtoi}}
\index{XLX\_\-strtoi@{XLX\_\-strtoi}!util.c@{util.c}}
\subsubsection[{XLX\_\-strtoi}]{\setlength{\rightskip}{0pt plus 5cm}int XLX\_\-strtoi (const char $\ast$ {\em string}, \/  unsigned int {\em len}, \/  int $\ast$ {\em value})}}
\label{util_8c_d8a7a94d974383d5d7d77c6218938b6a}


Convert a string to a signed 32-bit integer. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em string}]String to convert\item[{\em len}]Maximum length of the string (including whitespace)\item[{\em value}]Address of the converted value\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0}]If the string represents a valid integer \item[{\em -1}]If the string contains invalid characters \end{description}
\end{Desc}


References strtobin().

Referenced by XLX\_\-getAttribute().\hypertarget{util_8c_7d2a1e591a5878dead4b0dad971a39dd}{
\index{util.c@{util.c}!XLX\_\-strtoll@{XLX\_\-strtoll}}
\index{XLX\_\-strtoll@{XLX\_\-strtoll}!util.c@{util.c}}
\subsubsection[{XLX\_\-strtoll}]{\setlength{\rightskip}{0pt plus 5cm}int XLX\_\-strtoll (const char $\ast$ {\em string}, \/  unsigned int {\em len}, \/  long long $\ast$ {\em value})}}
\label{util_8c_7d2a1e591a5878dead4b0dad971a39dd}


Convert a string to a signed 64-bit integer. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em string}]String to convert\item[{\em len}]Maximum length of the string (including whitespace)\item[{\em value}]Address of the converted value\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0}]If the string represents a valid integer \item[{\em -1}]If the string contains invalid characters \end{description}
\end{Desc}


References strtobin().\hypertarget{util_8c_a8d794149203cb3a8d52cf58051ceb71}{
\index{util.c@{util.c}!XLX\_\-strtou@{XLX\_\-strtou}}
\index{XLX\_\-strtou@{XLX\_\-strtou}!util.c@{util.c}}
\subsubsection[{XLX\_\-strtou}]{\setlength{\rightskip}{0pt plus 5cm}int XLX\_\-strtou (const char $\ast$ {\em string}, \/  unsigned int {\em len}, \/  unsigned int $\ast$ {\em value})}}
\label{util_8c_a8d794149203cb3a8d52cf58051ceb71}


Convert a string to an unsigned 32-bit integer. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em string}]String to convert\item[{\em len}]Maximum length of the string (including whitespace)\item[{\em value}]Address of the converted value\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0}]If the string represents a valid integer \item[{\em -1}]If the string contains invalid characters \end{description}
\end{Desc}


References strtobin().\hypertarget{util_8c_21f440de32b115fc56bcae71cf7047be}{
\index{util.c@{util.c}!XLX\_\-strtoull@{XLX\_\-strtoull}}
\index{XLX\_\-strtoull@{XLX\_\-strtoull}!util.c@{util.c}}
\subsubsection[{XLX\_\-strtoull}]{\setlength{\rightskip}{0pt plus 5cm}int XLX\_\-strtoull (const char $\ast$ {\em string}, \/  unsigned int {\em len}, \/  unsigned long long $\ast$ {\em value})}}
\label{util_8c_21f440de32b115fc56bcae71cf7047be}


Convert a string to an unsigned 64-bit integer. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em string}]String to convert\item[{\em len}]Maximum length of the string (including whitespace)\item[{\em value}]Address of the converted value\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0}]If the string represents a valid integer \item[{\em -1}]If the string contains invalid characters \end{description}
\end{Desc}


References strtobin().\hypertarget{util_8c_d1b8bf73ff8abc87ddcbdd47b25c85fa}{
\index{util.c@{util.c}!XLX\_\-valError@{XLX\_\-valError}}
\index{XLX\_\-valError@{XLX\_\-valError}!util.c@{util.c}}
\subsubsection[{XLX\_\-valError}]{\setlength{\rightskip}{0pt plus 5cm}void XLX\_\-valError ({\bf XLX\_\-state} $\ast$ {\em state}, \/  const char $\ast$ {\em func}, \/  const char $\ast$ {\em string}, \/  unsigned int {\em len})}}
\label{util_8c_d1b8bf73ff8abc87ddcbdd47b25c85fa}


Report value string to be in error. 

This routine displays the contents of the string, along with the line number in and the name of the file being parsed.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em state}]Current parse state\item[{\em func}]Name of function reporting the error\item[{\em string}]String to report\item[{\em len}]Max length of the string (including whitespace) \end{description}
\end{Desc}


References \_\-XLX\_\-state::parser, \_\-XLX\_\-state::verbose, and XLX\_\-dispFileName().