# File latex.c

RCS Header: /home/amb/cxref/RCS/latex.c 1.30 1998/12/22 14:25:50 amb Exp

C Cross Referencing & Documentation tool. Version 1.5.
Writes the Latex output.

## Included Files

- `#include <stdlib.h>`

- `#include <stdio.h>`

- `#include <string.h>`

- `#include <sys/types.h>`

- `#include <sys/stat.h>`

- `#include <unistd.h>`

- `#include "memory.h"`

- `#include "datatype.h"`

- `#include "cxref.h"`
  - `#include "datatype.h"`

## Preprocessor definitions

`#define min( x, y )`

The name of the output tex file that includes each of the others.

`#define LATEX_FILE ".tex"`

`#define LATEX_FILE_BACKUP ".tex~"`

The name of the output tex file that contains the appendix.

`#define LATEX_APDX ".apdx"`

## External Variables

option_verbatim_comments
The comments are to be inserted verbatim.

`extern int option_verbatim_comments`

Defined in: | cxref.c

option_latex
The type of LaTeX output to produce.

`extern int option_latex`

Defined in: | cxref.c

option_odir
The name of the directory for the output.

`extern char* option_odir`

Defined in: | cxref.c

option_name
The base name of the file for the output.

`extern char* option_name`

Defined in: | cxref.c

latex_fonts_style
`extern char* latex_fonts_style`

Defined in: | latex-style.c

latex_page_style
`extern char* latex_page_style`

Defined in: | latex-style.c

latex_cxref_style
`extern char* latex_cxref_style`

Defined in: | latex-style.c

## Local Variables

of
The output file for the latex.

`static FILE* of`

Used in: | WriteLatexAppendix()
| WriteLatexDefine()
| WriteLatexFile()
| WriteLatexFilePart()
| WriteLatexFunction()
| WriteLatexInclude()
| WriteLatexStructUnion()
| WriteLatexSubInclude()
| WriteLatexTypedef()
| WriteLatexVariable()

countlines
Counts the lines in a table to insert breaks.

`static int countlines`

Used in: | WriteLatexInclude()
| WriteLatexStructUnion()
| WriteLatexSubInclude()
| WriteLatexTypedef()

## Global Function WriteLatexAppendix()

Write out the appendix information.

`void WriteLatexAppendix ( StringList files, StringList2 funcs, StringList2 vars, StringList2 types )`

`StringList files`
  The list of files to write.
`StringList2 funcs`
  The list of functions to write.
`StringList2 vars`
  The list of variables to write.
`StringList2 types`
  The list of types to write.

Prototyped in: | cxref.h
Calls: | ConcatStrings() | memory.c
| WriteLatexDocument() | latex.c
| latex() | latex.c
| exit(), fclose(), fopen(), fprintf(), strncmp()
Called by: | main() | cxref.c
References Variables: | of | latex.c
| option_name | cxref.c
| option_odir | cxref.c

## Global Function WriteLatexFile()

Write a Latex file for a complete File structure and all components.

`void WriteLatexFile ( File file )`

`File file`
  The File structure to output.

The file structure is broken into its components and they are each written out.

Prototyped in: | cxref.h
Calls: | ConcatStrings() | memory.c
| WriteLatexDefine() | latex.c
| WriteLatexDocument() | latex.c
| WriteLatexFilePart() | latex.c
| WriteLatexFunction() | latex.c
| WriteLatexInclude() | latex.c
| WriteLatexTypedef() | latex.c
| WriteLatexVariable() | latex.c
| latex() | latex.c
| exit(), fclose(), fopen(), fprintf(), fputs(), mkdir(), stat(), strlen()
Called by: | main() | cxref.c
References Variables: | of | latex.c
| option_odir | cxref.c

## Global Function WriteLatexFileDelete()

Delete the latex file and main file reference that belong to the named file.

`void WriteLatexFileDelete ( char* name )`

`char* name`
  The name of the file to delete.

Prototyped in: | cxref.h
Calls: | ConcatStrings() | memory.c
| fclose(), fgets(), fopen(), fprintf(), fputs(), rename(), strcmp(), unlink()
Called by: | main() | cxref.c
References Variables: | option_name | cxref.c
| option_odir | cxref.c

## Local Function WriteLatexDefine()

Write a Define structure out.

`static void WriteLatexDefine ( Define def )`

`Define def`
  The Define structure to output.

Prototyped in: | latex.c
Calls: | latex() | latex.c
| fprintf()
Called by: | WriteLatexFile() | latex.c
References Variables: | of | latex.c

## Local Function WriteLatexDocument()

Write out a file that will include the current information.

`static void WriteLatexDocument ( char* name, int appendix )`

`char* name`
  The name of the file (without the LaTeX extension).
`int appendix`
  set to non-zero if the appendix file is to be added, else a normal source file.

Prototyped in: | latex.c
Calls: | ConcatStrings() | memory.c
| WriteLatexTemplate() | latex.c
| exit(), fclose(), fgets(), fopen(), fprintf(), fputs(), rename(), strcmp(), unlink()
Called by: | WriteLatexAppendix() | latex.c
| WriteLatexFile() | latex.c
References Variables: | option_name | cxref.c
| option_odir | cxref.c

## Local Function WriteLatexFilePart()

Write a File structure out.

`static void WriteLatexFilePart ( File file )`

`File file`
  The File to output.

Prototyped in: | latex.c
Calls: | latex() | latex.c
| fprintf(), strstr()
Called by: | WriteLatexFile() | latex.c
References Variables: | of | latex.c
| option_verbatim_comments | cxref.c

## Local Function WriteLatexFunction()

Write a Function structure out.

`static void WriteLatexFunction ( Function func, char* filename )`

`Function func`
  The Function structure to output.
`char* filename`
  The name of the file that is being processed (required for the cross reference label).

Prototyped in: | latex.c
Calls: | latex() | latex.c
| fprintf(), strcmp(), strncmp(), strstr()
Called by: | WriteLatexFile() | latex.c
References Variables: | of | latex.c
| option_verbatim_comments | cxref.c

## Local Function WriteLatexInclude()

Write an Include structure out.

`static void WriteLatexInclude ( Include inc )`

`Include inc`
  The Include structure to output.

Prototyped in: | latex.c
Calls: | WriteLatexSubInclude() | latex.c
| latex() | latex.c
| fprintf()
Called by: | WriteLatexFile() | latex.c
References Variables: | countlines | latex.c
| of | latex.c

## Local Function WriteLatexStructUnion()

Write a structure / union structure out.

`static void WriteLatexStructUnion ( StructUnion su, int depth )`

`StructUnion su`
  The structure / union to write.
`int depth`
  The current depth within the structure.

Prototyped in: | latex.c
Calls: | WriteLatexStructUnion() | latex.c
| latex() | latex.c
| fprintf(), strstr()
Called by: | WriteLatexStructUnion() | latex.c
| WriteLatexTypedef() | latex.c
References Variables: | countlines | latex.c
| of | latex.c

## Local Function WriteLatexSubInclude()

Write an Sub Include structure out. (An include structure that is included from another file.)

`static void WriteLatexSubInclude ( Include inc, int depth )`

`Include inc`
  The Include structure to output.
`int depth`
  The depth of the include hierarchy.

Prototyped in: | latex.c
Calls: | WriteLatexSubInclude() | latex.c
| latex() | latex.c
| fprintf()
Called by: | WriteLatexInclude() | latex.c
| WriteLatexSubInclude() | latex.c
References Variables: | countlines | latex.c
| of | latex.c

## Local Function WriteLatexTemplate()

Write out the standard template for the main LaTeX file. This sets up the page styles, and includes markers for the start and end of included source code.

`static void WriteLatexTemplate ( char* name )`

`char* name`
  The name of the file to write the template to.

Prototyped in: | latex.c
Calls: | ConcatStrings() | memory.c
| exit(), fclose(), fopen(), fprintf(), fputs(), stat()
Called by: | WriteLatexDocument() | latex.c
References Variables: | latex_cxref_style | latex-style.c
| latex_fonts_style | latex-style.c
| latex_page_style | latex-style.c
| option_latex | cxref.c
| option_odir | cxref.c

## Local Function WriteLatexTypedef()

Write a Typedef structure out.

`static void WriteLatexTypedef ( Typedef type, char* filename )`

`Typedef type`
  The Typedef structure to output.
`char* filename`
  The name of the file that is being processed (required for the cross reference label).

Prototyped in: | latex.c
Calls: | WriteLatexStructUnion() | latex.c
| latex() | latex.c
| fprintf(), strncmp()
Called by: | WriteLatexFile() | latex.c
References Variables: | countlines | latex.c
| of | latex.c

## Local Function WriteLatexVariable()

Write a Variable structure out.

`static void WriteLatexVariable ( Variable var, char* filename )`

`Variable var`
  The Variable structure to output.
`char* filename`
  The name of the file that is being processed (required for the cross reference label).

Prototyped in: | latex.c
Calls: | latex() | latex.c
| fprintf()
Called by: | WriteLatexFile() | latex.c
References Variables: | of | latex.c

## Local Function latex()

Make the input string safe to output as LaTeX ( not #, $, %, &, \, ^, _, {, }, <, > or ~ ).

`static char* latex ( char* c )`

`char* latex`
  Returns a safe LaTeX string.
`char* c`
  A non-safe LaTeX string.

The function can only be called four times in each fprintf() since it returns one of only four static strings.

Prototyped in: | latex.c
Calls: | CopyOrSkip() | warn-raw.c
| SafeFree() | memory.c
| SafeMalloc() | memory.c
| SafeRealloc() | memory.c
| strcpy(), strncpy()
Called by: | WriteLatexAppendix() | latex.c
| WriteLatexDefine() | latex.c
| WriteLatexFile() | latex.c
| WriteLatexFilePart() | latex.c
| WriteLatexFunction() | latex.c
| WriteLatexInclude() | latex.c
| WriteLatexStructUnion() | latex.c
| WriteLatexSubInclude() | latex.c
| WriteLatexTypedef() | latex.c
| WriteLatexVariable() | latex.c