
\Module{main.c}{main.c}

This is the \BibTool{} main module. It contains the |main()|
function which evaluates the command line arguments and
proceeds accordingly. This means that usually resource files
and \BibTeX{} files are read and one or more \BibTeX{} files
are written.

This file makes use of the \BibTool{} C library but is not
part of it. For this purpose it has to provide certain
functions which are expected by the library. These functions
are: 
\begin{quote}
\texttt{save\_input\_file()}\\
\texttt{save\_macro\_file()}\\
\texttt{save\_output\_file()}\\
\end{quote}
The arguments and the expected behaviour of these functions is
described below.

If you are trying to understand the implementation of
\BibTool{} the file |resource.h| plays a central
r\^ole. Consult the description of this file for further
details. 

If you are trying to write your own program to manipulate
\BibTeX{} files then this file can serve as a starting point.
But you should keep in mind that this file has grown over
several years and it contains the full complexity of the
\BibTool{} program logic. Thus you can reduce this file
drastically if you start playing around with the \BibTool{} C
library. 

\begin{Function}{int \Fct{main}}{main}
  \begin{Arguments}
    int \ 	&\Var{argc};	&Number of arguments\\
    char *\ 	&\Var{argv}[];	&Array of arguments
  \end{Arguments}%
  This is the main function which is automatically
  called when the program is started. This function
  contains the overall program logic. It has to perform
  the appropriate initializations, evaluate command line
  arguments, and run the main loop.
  \begin{Result}
    0 upon success. Usually a failure raises an exception
    which leads to an |exit()|. Thus this function does
    not need to signal an error to the calling environment.
  \end{Result}
\end{Function}
\begin{Function}{void \Fct{save\_input\_file}}{save\_input\_file}
  \begin{Arguments}
    char *\ 	&\Var{file};	&File name to save.
  \end{Arguments}%
  The input file pipe is a dynamic array of strings.
  This fifo stack is used to store the input \BibTeX{}
  files to be processed by \BibTool.
  
  This function is called to push an string into the pipe.
  If neccesary the array has to be allocated or enlarged.
  This is done in larger junks to avoid lots of calls to
  |realloc()|.
  \begin{Result}
    nothing
  \end{Result}
\end{Function}
\begin{Function}{void \Fct{save\_macro\_file}}{save\_macro\_file}
  \begin{Arguments}
    char *\ 	&\Var{file};	&File name to save
  \end{Arguments}%
  Simply feed the macro file name into the static variable.
  This function is useful since it can be called from rsc.c
  \begin{Result}
    nothing
  \end{Result}
\end{Function}
\begin{Function}{void \Fct{save\_output\_file}}{save\_output\_file}
  \begin{Arguments}
    char * \ 	&\Var{file};	&File name to save
  \end{Arguments}%
  Simply feed the output file name into the static variable.
  This function is useful since it can be called from rsc.c
  \begin{Result}
    nothing
  \end{Result}
\end{Function}
