% This LaTeX file generated by cxref
% cxref program (c) Andrew M. Bishop 1995,96,97.

\markboth{File xref.c}{File xref.c}
\section{File xref.c}
\label{file_xref.c}

{\bf RCS Header: /home/amb/cxref/RCS/xref.c 1.15 1997/05/18 10:05:52 amb Exp }

\smallskip

  C Cross Referencing \& Documentation tool. Version 1.4.

  Cross referencing of functions.


\subsection*{Included Files}

\begin{cxreftabi}
{\stt \#include <stdlib.h>} &\\
\end{cxreftabi}

\medskip
\begin{cxreftabi}
{\stt \#include <stdio.h>} &\\
\end{cxreftabi}

\medskip
\begin{cxreftabi}
{\stt \#include <string.h>} &\\
\end{cxreftabi}

\medskip
\begin{cxreftabi}
{\stt \#include <unistd.h>} &\\
\end{cxreftabi}

\medskip
\begin{cxreftabi}
{\stt \#include "memory.h"} &\cxreffile{memory.h}\\
\end{cxreftabi}

\medskip
\begin{cxreftabi}
{\stt \#include "datatype.h"} &\cxreffile{datatype.h}\\
\end{cxreftabi}

\medskip
\begin{cxreftabi}
{\stt \#include "cxref.h"} &\cxreffile{cxref.h}\\
\hspace*{0.2in}{\stt \#include "datatype.h"} &\cxreffile{datatype.h}\\
\end{cxreftabi}


\subsection*{Preprocessor definitions}

 The names of the function cross reference files. 

\smallskip
{\stt \#define XREF\_FUNC\_FILE ".function"}

\medskip
{\stt \#define XREF\_FUNC\_BACKUP ".function$\sim$"}

\medskip
 The names of the variable cross reference files. 

\smallskip
{\stt \#define XREF\_VAR\_FILE ".variable"}

\medskip
{\stt \#define XREF\_VAR\_BACKUP ".variable$\sim$"}

\medskip
 The names of the include cross reference files. 

\smallskip
{\stt \#define XREF\_INC\_FILE ".include"}

\medskip
{\stt \#define XREF\_INC\_BACKUP ".include$\sim$"}

\medskip
 The names of the type cross reference files. 

\smallskip
{\stt \#define XREF\_TYPE\_FILE ".typedef"}

\medskip
{\stt \#define XREF\_TYPE\_BACKUP ".typedef$\sim$"}


\subsection{Variables}


\subsubsection{External Variables}

{\bf option\_odir}
\label{var_option_odir_xref.c}

 The name of the directory for the output. 

\smallskip
{\stt extern char* option\_odir}

\smallskip
\begin{cxreftabiii}
Defined in:& cxref.c & \ & \cxrefvar{option_odir}{cxref.c}\\
\end{cxreftabiii}

\medskip
{\bf option\_name}
\label{var_option_name_xref.c}

 The base name of the file for the output. 

\smallskip
{\stt extern char* option\_name}

\smallskip
\begin{cxreftabiii}
Defined in:& cxref.c & \ & \cxrefvar{option_name}{cxref.c}\\
\end{cxreftabiii}

\medskip
{\bf option\_xref}
\label{var_option_xref_xref.c}

 The option for cross referencing. 

\smallskip
{\stt extern int option\_xref}

\smallskip
\begin{cxreftabiii}
Defined in:& cxref.c & \ & \cxrefvar{option_xref}{cxref.c}\\
\end{cxreftabiii}

\medskip
{\bf option\_index}
\label{var_option_index_xref.c}

 The option for indexing. 

\smallskip
{\stt extern int option\_index}

\smallskip
\begin{cxreftabiii}
Defined in:& cxref.c & \ & \cxrefvar{option_index}{cxref.c}\\
\end{cxreftabiii}


\subsection{Functions}


\subsubsection{Global Function CreateAppendix()}
\label{func_CreateAppendix_xref.c}

  Create the appendix of files, global functions, global variables and types.

\smallskip
{\stt void CreateAppendix ( StringList files, StringList2 funcs, StringList2 vars, StringList2 types )}

\smallskip
\begin{cxrefarglist}
\cxrefargitem{StringList files} The list of files to create.
\cxrefargitem{StringList2 funcs} The list of functions to create.
\cxrefargitem{StringList2 vars} The list of variables to create.
\cxrefargitem{StringList2 types} The list of types to create.
\end{cxrefarglist}

\smallskip
\begin{cxreftabiii}
Prototype:& cxref.h & \ & \cxreffile{cxref.h}\\
Calls:\ & AddToStringList() & slist.c & \cxreffunc{AddToStringList}{slist.c}\\
\ & AddToStringList2() & slist.c & \cxreffunc{AddToStringList2}{slist.c}\\
\ & ConcatStrings() & memory.c & \cxreffunc{ConcatStrings}{memory.c}\\
\cxreftabbreak{cxreftabiii}
\ & \cxreftabiiispan{ fclose(), fgets(), fopen(), fscanf(), strlen()} &\\
Called by:\ & main() & cxref.c & \cxreffunc{main}{cxref.c}\\
Refs Var:\ & option\_index & cxref.c & \cxrefvar{option_index}{cxref.c}\\
\ & option\_name & cxref.c & \cxrefvar{option_name}{cxref.c}\\
\ & option\_odir & cxref.c & \cxrefvar{option_odir}{cxref.c}\\
\end{cxreftabiii}


\subsubsection{Global Function CrossReference()}
\label{func_CrossReference_xref.c}

  Cross reference the functions, variables and includes that are used in this file
  with the global functions, variables and includes. The types that are defined are also listed here.

\smallskip
{\stt void CrossReference ( File file )}

\smallskip
\begin{cxrefarglist}
\cxrefargitem{File file} The file structure containing the information.
\end{cxrefarglist}

\smallskip
\begin{cxreftabiii}
Prototype:& cxref.h & \ & \cxreffile{cxref.h}\\
Calls:\ & AddToStringList() & slist.c & \cxreffunc{AddToStringList}{slist.c}\\
\ & ConcatStrings() & memory.c & \cxreffunc{ConcatStrings}{memory.c}\\
\ & check\_for\_called() & xref.c & \cxreffunc{check_for_called}{xref.c}\\
\cxreftabbreak{cxreftabiii}
\ & check\_for\_caller() & xref.c & \cxreffunc{check_for_caller}{xref.c}\\
\ & check\_for\_var() & xref.c & \cxreffunc{check_for_var}{xref.c}\\
\ & check\_for\_var\_func() & xref.c & \cxreffunc{check_for_var_func}{xref.c}\\
\ & fixup\_extern\_var() & xref.c & \cxreffunc{fixup_extern_var}{xref.c}\\
\ & \cxreftabiiispan{ exit(), fclose(), fgets(), fopen(), fprintf(), fputs(), fscanf(), rename(), strcmp(), unlink()} &\\
Called by:\ & main() & cxref.c & \cxreffunc{main}{cxref.c}\\
Refs Var:\ & option\_name & cxref.c & \cxrefvar{option_name}{cxref.c}\\
\ & option\_odir & cxref.c & \cxrefvar{option_odir}{cxref.c}\\
\ & option\_xref & cxref.c & \cxrefvar{option_xref}{cxref.c}\\
\cxreftabbreak{cxreftabiii}
\end{cxreftabiii}


\subsubsection{Global Function CrossReferenceDelete()}
\label{func_CrossReferenceDelete_xref.c}

  Delete the named file from the cross reference database.

\smallskip
{\stt void CrossReferenceDelete ( char* name )}

\smallskip
\begin{cxrefarglist}
\cxrefargitem{char* name} The name of the file that is to be deleted.
\end{cxrefarglist}

\smallskip
\begin{cxreftabiii}
Prototype:& cxref.h & \ & \cxreffile{cxref.h}\\
Calls:\ & ConcatStrings() & memory.c & \cxreffunc{ConcatStrings}{memory.c}\\
\ & \cxreftabiiispan{ fclose(), fgets(), fopen(), fprintf(), fputs(), fscanf(), rename(), strcmp(), unlink()} &\\
Called by:\ & main() & cxref.c & \cxreffunc{main}{cxref.c}\\
Refs Var:\ & option\_name & cxref.c & \cxrefvar{option_name}{cxref.c}\\
\cxreftabbreak{cxreftabiii}
\ & option\_odir & cxref.c & \cxrefvar{option_odir}{cxref.c}\\
\end{cxreftabiii}


\subsubsection{Local Function check\_for\_called()}
\label{func_check_for_called_xref.c}

  Check through all of the functions in this file to see if any of them are called or referenced.

\smallskip
{\stt static void check\_for\_called ( File file, char* called, char* caller, char* filename )}

\smallskip
\begin{cxrefarglist}
\cxrefargitem{File file} The file structure.
\cxrefargitem{char* called} The function that is called.
\cxrefargitem{char* caller} The function that the called function is called from.
\cxrefargitem{char* filename} The file that the function is called from.
\end{cxrefarglist}

\smallskip
\begin{cxreftabiii}
Prototype:& xref.c & \ & \cxreffile{xref.c}\\
Calls:\ & AddToStringList2() & slist.c & \cxreffunc{AddToStringList2}{slist.c}\\
\ & \cxreftabiiispan{ strcmp()} &\\
Called by:\ & CrossReference() & xref.c & \cxreffunc{CrossReference}{xref.c}\\
\end{cxreftabiii}


\subsubsection{Local Function check\_for\_caller()}
\label{func_check_for_caller_xref.c}

  Check through all of the functions in this file to see if any of them are callers or referencers.

\smallskip
{\stt static void check\_for\_caller ( File file, char* called, char* filename )}

\smallskip
\begin{cxrefarglist}
\cxrefargitem{File file} The file structure.
\cxrefargitem{char* called} The function that is called.
\cxrefargitem{char* filename} The file that the called function is in.
\end{cxrefarglist}

\smallskip
\begin{cxreftabiii}
Prototype:& xref.c & \ & \cxreffile{xref.c}\\
Calls:\ & SafeMallocString() & memory.c & \cxreffunc{SafeMallocString}{memory.c}\\
\ & \cxreftabiiispan{ strcmp()} &\\
Called by:\ & CrossReference() & xref.c & \cxreffunc{CrossReference}{xref.c}\\
\end{cxreftabiii}


\subsubsection{Local Function check\_for\_var()}
\label{func_check_for_var_xref.c}

  Check through all of the variables in this file to see if any of them are extern usage of others.

\smallskip
{\stt static void check\_for\_var ( File file, char* variable, char* filename, int scope, char* funcname )}

\smallskip
\begin{cxrefarglist}
\cxrefargitem{File file} The file structure.
\cxrefargitem{char* variable} The global variable name.
\cxrefargitem{char* filename} The file that the variable is used in.
\cxrefargitem{int scope} The scope of the variable in the foreign file.
\cxrefargitem{char* funcname} The name of a function that uses the variable.
\end{cxrefarglist}

\smallskip
\begin{cxreftabiii}
Prototype:& xref.c & \ & \cxreffile{xref.c}\\
Calls:\ & AddToStringList2() & slist.c & \cxreffunc{AddToStringList2}{slist.c}\\
\ & SafeMallocString() & memory.c & \cxreffunc{SafeMallocString}{memory.c}\\
\ & \cxreftabiiispan{ strcmp()} &\\
Called by:\ & CrossReference() & xref.c & \cxreffunc{CrossReference}{xref.c}\\
\cxreftabbreak{cxreftabiii}
\end{cxreftabiii}


\subsubsection{Local Function check\_for\_var\_func()}
\label{func_check_for_var_func_xref.c}

  Check through the function to see if it uses the variable, if func is NULL then check the file.

\smallskip
{\stt static int check\_for\_var\_func ( File file, Variable var, Function func )}

\smallskip
\begin{cxrefarglist}
\cxrefargitem{int check\_for\_var\_func} Returns 1 if the variable is referenced from the function or file.
\cxrefargitem{File file} The file that the function belongs to.
\cxrefargitem{Variable var} The variable that may be referenced.
\cxrefargitem{Function func} The function that is to be checked.
\end{cxrefarglist}

\smallskip
\begin{cxreftabiii}
Prototype:& xref.c & \ & \cxreffile{xref.c}\\
Calls:\ & AddToStringList2() & slist.c & \cxreffunc{AddToStringList2}{slist.c}\\
\ & SafeFree() & memory.c & \cxreffunc{SafeFree}{memory.c}\\
\ & SafeMallocString() & memory.c & \cxreffunc{SafeMallocString}{memory.c}\\
\cxreftabbreak{cxreftabiii}
\ & \cxreftabiiispan{ strcmp()} &\\
Called by:\ & CrossReference() & xref.c & \cxreffunc{CrossReference}{xref.c}\\
\end{cxreftabiii}


\subsubsection{Local Function fixup\_extern\_var()}
\label{func_fixup_extern_var_xref.c}

  We can only now put in the location of the external variables that we found were used.
  Previously we did not know the location of their global definition.

\smallskip
{\stt static void fixup\_extern\_var ( Variable var, StringList2 refs )}

\smallskip
\begin{cxrefarglist}
\cxrefargitem{Variable var} The list of variables for this file.
\cxrefargitem{StringList2 refs} A list of variable references from a file or a function.
\end{cxrefarglist}

\smallskip
\begin{cxreftabiii}
Prototype:& xref.c & \ & \cxreffile{xref.c}\\
Calls:\ & SafeFree() & memory.c & \cxreffunc{SafeFree}{memory.c}\\
\ & SafeMallocString() & memory.c & \cxreffunc{SafeMallocString}{memory.c}\\
\ & \cxreftabiiispan{ strcmp()} &\\
Called by:\ & CrossReference() & xref.c & \cxreffunc{CrossReference}{xref.c}\\
\cxreftabbreak{cxreftabiii}
\end{cxreftabiii}

