# File cxref.c

RCS Header: /home/amb/cxref/RCS/cxref.c 1.45 1999/01/26 19:40:12 amb Exp

C Cross Referencing & Documentation tool. Version 1.5.

## Included Files

- `#include <stdio.h>`

- `#include <stdlib.h>`

- `#include <string.h>`

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

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

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

- `#include <unistd.h>`

- `#include "parse-yy.h"`
  - `#include <stdio.h>`
  - `#include <stdlib.h>`

- `#include "memory.h"`

- `#include "datatype.h"`

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

## Preprocessor definitions

The default value of the CPP command.

`#define CPP_COMMAND "gcc -E -C -dD -dI"`

The name of the file to read the configuration from.

`#define CXREF_CONFIG_FILE ".cxref"`

## Global Variable option_all_comments

The command line switch that sets the format of the output, use all comments.

`int option_all_comments`

Visible in: |  | cxref.c
|  | parse-lex.c
Used in: | ParseOptions() | cxref.c
| yylex() | parse-lex.c

## Global Variable option_verbatim_comments

The command line switch that sets the format of the output, insert the comments verbatim into the output.

`int option_verbatim_comments`

Visible in: |  | comment.c
|  | cxref.c
|  | html.c
|  | latex.c
|  | rtf.c
|  | sgml.c
Used in: | ParseOptions() | cxref.c
| SeenComment() | comment.c
| WriteHTMLFilePart() | html.c
| WriteHTMLFunction() | html.c
| WriteLatexFilePart() | latex.c
| WriteLatexFunction() | latex.c
| WriteRTFFilePart() | rtf.c
| WriteRTFFunction() | rtf.c
| WriteSGMLFilePart() | sgml.c
| WriteSGMLFunction() | sgml.c

## Global Variable option_block_comments

The command line switch that sets the format of the output, remove the leading block comment marker.

`int option_block_comments`

Visible in: |  | cxref.c
|  | parse-lex.c
Used in: | ParseOptions() | cxref.c
| yylex() | parse-lex.c

## Global Variable option_no_comments

The command line switch that sets the format of the output, ignore all comments.

`int option_no_comments`

Visible in: |  | cxref.c
|  | parse-lex.c
Used in: | ParseOptions() | cxref.c
| yylex() | parse-lex.c

## Global Variable option_xref

The command line switch that sets the format of the output, do cross referencing.

`int option_xref`

Visible in: |  | cxref.c
|  | func.c
|  | warn-raw.c
|  | xref.c
Used in: | CheckFunctionVariableRef() | func.c
| CrossReference() | xref.c
| ParseOptions() | cxref.c
| SeenFunctionCall() | func.c
| SeenFunctionDefinition() | func.c
| SeenFunctionProto() | func.c
| WriteWarnRawFilePart() | warn-raw.c
| WriteWarnRawFunction() | warn-raw.c
| WriteWarnRawVariable() | warn-raw.c
| main() | cxref.c

## Global Variable option_warn

The command line switch that sets the format of the output, produce warnings.

`int option_warn`

Visible in: |  | cxref.c
|  | parse-lex.c
|  | warn-raw.c
Used in: | ParseOptions() | cxref.c
| WriteWarnRawAppendix() | warn-raw.c
| WriteWarnRawDefine() | warn-raw.c
| WriteWarnRawFilePart() | warn-raw.c
| WriteWarnRawFunction() | warn-raw.c
| WriteWarnRawInclude() | warn-raw.c
| WriteWarnRawStructUnion() | warn-raw.c
| WriteWarnRawTypedef() | warn-raw.c
| WriteWarnRawVariable() | warn-raw.c
| main() | cxref.c
| yylex() | parse-lex.c

## Global Variable option_index

The command line switch that sets the format of the output, produce an index.

`int option_index`

Visible in: |  | cxref.c
|  | warn-raw.c
|  | xref.c
Used in: | CreateAppendix() | xref.c
| ParseOptions() | cxref.c
| WriteWarnRawAppendix() | warn-raw.c
| main() | cxref.c

## Global Variable option_raw

The command line switch that sets the format of the output, produce raw output.

`int option_raw`

Visible in: |  | cxref.c
|  | warn-raw.c
Used in: | ParseOptions() | cxref.c
| WriteWarnRawDefine() | warn-raw.c
| WriteWarnRawFile() | warn-raw.c
| WriteWarnRawFilePart() | warn-raw.c
| WriteWarnRawFunction() | warn-raw.c
| WriteWarnRawInclude() | warn-raw.c
| WriteWarnRawStructUnion() | warn-raw.c
| WriteWarnRawTypedef() | warn-raw.c
| WriteWarnRawVariable() | warn-raw.c
| main() | cxref.c

## Global Variable option_latex

The command line switch that sets the format of the output, produce LaTeX output.

`int option_latex`

Visible in: |  | cxref.c
|  | latex.c
Used in: | ParseOptions() | cxref.c
| WriteLatexTemplate() | latex.c
| main() | cxref.c

## Global Variable option_html

The command line switch that sets the format of the output, produce HTML output.

`int option_html`

Visible in: |  | cxref.c
|  | html.c
Used in: | ParseOptions() | cxref.c
| WriteHTMLDefine() | html.c
| WriteHTMLFile() | html.c
| WriteHTMLFilePart() | html.c
| WriteHTMLFunction() | html.c
| WriteHTMLPreamble() | html.c
| WriteHTMLStructUnion() | html.c
| WriteHTMLTypedef() | html.c
| WriteHTMLVariable() | html.c
| main() | cxref.c

## Global Variable option_rtf

The command line switch that sets the format of the output, produce RTF output.

`int option_rtf`

Visible in: |  | cxref.c
Used in: | ParseOptions() | cxref.c
| main() | cxref.c

## Global Variable option_sgml

The command line switch that sets the format of the output, produce SGML output.

`int option_sgml`

Visible in: |  | cxref.c
Used in: | ParseOptions() | cxref.c
| main() | cxref.c

## Global Variable option_odir

The command line switch for the output name, the directory to use.

`char* option_odir`

Visible in: |  | cxref.c
|  | html.c
|  | latex.c
|  | rtf.c
|  | sgml.c
|  | xref.c
Used in: | CreateAppendix() | xref.c
| CrossReference() | xref.c
| CrossReferenceDelete() | xref.c
| ParseOptions() | cxref.c
| WriteHTMLAppendix() | html.c
| WriteHTMLDocument() | html.c
| WriteHTMLFile() | html.c
| WriteHTMLFileDelete() | html.c
| WriteHTMLSource() | html.c
| WriteLatexAppendix() | latex.c
| WriteLatexDocument() | latex.c
| WriteLatexFile() | latex.c
| WriteLatexFileDelete() | latex.c
| WriteLatexTemplate() | latex.c
| WriteRTFAppendix() | rtf.c
| WriteRTFFile() | rtf.c
| WriteRTFFileDelete() | rtf.c
| WriteSGMLAppendix() | sgml.c
| WriteSGMLFile() | sgml.c
| WriteSGMLFileDelete() | sgml.c
| main() | cxref.c

## Global Variable option_name

The command line switch for the output name, the base part of the name.

`char* option_name`

Visible in: |  | cxref.c
|  | html.c
|  | latex.c
|  | rtf.c
|  | sgml.c
|  | xref.c
Used in: | CreateAppendix() | xref.c
| CrossReference() | xref.c
| CrossReferenceDelete() | xref.c
| ParseOptions() | cxref.c
| WriteHTMLAppendix() | html.c
| WriteHTMLDocument() | html.c
| WriteHTMLFile() | html.c
| WriteHTMLFileDelete() | html.c
| WriteLatexAppendix() | latex.c
| WriteLatexDocument() | latex.c
| WriteLatexFileDelete() | latex.c
| WriteRTFAppendix() | rtf.c
| WriteSGMLAppendix() | sgml.c
| WriteSGMLFile() | sgml.c
| main() | cxref.c

## Global Variable option_root

The command line switch for the output name, the source tree root directory.

`char* option_root`

Visible in: |  | cxref.c
Used in: | ParseOptions() | cxref.c
| main() | cxref.c

## Global Variable option_incdirs

The name of the include directories specified on the command line.

`char** option_incdirs`

Visible in: |  | cxref.c
|  | preproc.c
Used in: | ParseOptions() | cxref.c
| SeenInclude() | preproc.c
| main() | cxref.c

## Global Variable option_nincdirs

The number of include directories on the command line.

`int option_nincdirs`

Visible in: |  | cxref.c
|  | preproc.c
Used in: | ParseOptions() | cxref.c
| SeenInclude() | preproc.c
| main() | cxref.c

## Global Variable CurFile

The current file that is being processed.

`File CurFile`

Visible in: |  | comment.c
|  | cxref.c
|  | file.c
|  | func.c
|  | preproc.c
|  | type.c
|  | var.c
Used in: | CheckFunctionVariableRef() | func.c
| ResetFunctionAnalyser() | func.c
| SeenComment() | comment.c
| SeenDefine() | preproc.c
| SeenFileComment() | file.c
| SeenFunctionDefinition() | func.c
| SeenInclude() | preproc.c
| SeenStructUnionComp() | type.c
| SeenStructUnionEnd() | type.c
| SeenTypedef() | type.c
| SeenVariableDefinition() | var.c
| main() | cxref.c

## Local Variables

cpp_command
The actual cpp command that is built up, adding -D, -U and -I options.

`static char** cpp_command`

Used in: | DocumentTheFile()
| ParseOptions()
| main()

cpp_command_num
The number of arguments to the cpp command.

`static int cpp_command_num`

Used in: | DocumentTheFile()
| ParseOptions()
| main()

cpp_argument_num
The number of arguments to the -CPP argument.

`static int cpp_argument_num`

Used in: | ParseOptions()
| main()

option_delete
The option to control the mode of operation.

`static int option_delete`

Used in: | ParseOptions()
| main()

option_files
The names of the files to process.

`static char** option_files`

Used in: | ParseConfigFile()
| ParseOptions()
| main()

option_nfiles
The number of files to process.

`static int option_nfiles`

Used in: | ParseConfigFile()
| ParseOptions()
| main()

popen_pid
The process id of the pre-processor.

`static pid_t popen_pid`

Used in: | pclose_execvp()
| popen_execvp()

## Global Function CanonicaliseName()

Canonicalise a file name by removing '/../', '/./' and '//' references.

`char* CanonicaliseName ( char* name )`

`char* CanonicaliseName`
  Returns the argument modified.
`char* name`
  The original name

Prototyped in: | cxref.h
Calls: | strcmp(), strlen(), strstr()
Called by: | SeenFileChange() | preproc.c
| SeenInclude() | preproc.c
| main() | cxref.c

## Global Function main()

The main function that calls the parser.

`int main ( int argc, char** argv )`

`int main`
  Returns the status, zero for normal termination, else an error.
`int argc`
  The command line number of arguments.
`char** argv`
  The actual command line arguments

Calls: | CanonicaliseName() | cxref.c
| ConcatStrings() | memory.c
| CreateAppendix() | xref.c
| CrossReference() | xref.c
| CrossReferenceDelete() | xref.c
| DeleteComment() | comment.c
| DeleteFile() | file.c
| DeleteStringList() | slist.c
| DeleteStringList2() | slist.c
| DocumentTheFile() | cxref.c
| NewFile() | file.c
| NewStringList() | slist.c
| NewStringList2() | slist.c
| ParseConfigFile() | cxref.c
| ParseOptions() | cxref.c
| PrintMemoryStatistics() | memory.c
| ResetFunctionAnalyser() | func.c
| ResetLexer() | parse-lex.c
| ResetParser() | parse-yacc.c
| ResetPreProcAnalyser() | preproc.c
| ResetTypeAnalyser() | type.c
| ResetVariableAnalyser() | var.c
| SafeFree() | memory.c
| SafeMalloc() | memory.c
| SafeMallocString() | memory.c
| SafeRealloc() | memory.c
| TidyMemory() | memory.c
| Usage() | cxref.c
| WriteHTMLAppendix() | html.c
| WriteHTMLFile() | html.c
| WriteHTMLFileDelete() | html.c
| WriteLatexAppendix() | latex.c
| WriteLatexFile() | latex.c
| WriteLatexFileDelete() | latex.c
| WriteRTFAppendix() | rtf.c
| WriteRTFFile() | rtf.c
| WriteRTFFileDelete() | rtf.c
| WriteSGMLAppendix() | sgml.c
| WriteSGMLFile() | sgml.c
| WriteSGMLFileDelete() | sgml.c
| WriteWarnRawAppendix() | warn-raw.c
| WriteWarnRawFile() | warn-raw.c
| chdir(), exit(), fprintf(), getcwd(), strcmp(), strlen(), strncmp()
References Variables: | CurFile | cxref.c
| cpp_argument_num | cxref.c
| cpp_command | cxref.c
| cpp_command_num | cxref.c
| option_delete | cxref.c
| option_files | cxref.c
| option_html | cxref.c
| option_incdirs | cxref.c
| option_index | cxref.c
| option_latex | cxref.c
| option_name | cxref.c
| option_nfiles | cxref.c
| option_nincdirs | cxref.c
| option_odir | cxref.c
| option_raw | cxref.c
| option_root | cxref.c
| option_rtf | cxref.c
| option_sgml | cxref.c
| option_warn | cxref.c
| option_xref | cxref.c

## Local Function DocumentTheFile()

Calls CPP for the file to get all of the needed information.

`static int DocumentTheFile ( char* name )`

`int DocumentTheFile`
  Returns 1 in case of error, else 0.
`char* name`
  The name of the file to document.

The CPP is started as a sub-process, (using popen to return a FILE* for lex to use).

Prototyped in: | cxref.c
Calls: | pclose_execvp() | cxref.c
| popen_execvp() | cxref.c
| yyparse() | parse-yacc.c
| yyrestart() | parse-lex.c
| exit(), fprintf(), stat()
Called by: | main() | cxref.c
References Variables: | cpp_command | cxref.c
| cpp_command_num | cxref.c
| yyin | parse-lex.c

## Local Function ParseConfigFile()

Read in the options from the configuration file.

`static int ParseConfigFile ( void )`

`int ParseConfigFile`
  Returns the values returned by ParseOptions().

Prototyped in: | cxref.c
Calls: | CopyString() | memory.c
| ParseOptions() | cxref.c
| SafeFree() | memory.c
| SafeMalloc() | memory.c
| SafeRealloc() | memory.c
| fclose(), fgets(), fopen(), fprintf(), strlen(), strncmp()
Called by: | main() | cxref.c
References Variables: | option_files | cxref.c
| option_nfiles | cxref.c

## Local Function ParseOptions()

Parse the options from the command line or from the .cxref file.

`static int ParseOptions ( int nargs, char** args, int fromfile )`

`int ParseOptions`
  Return 1 if there is an error.
`int nargs`
  The number of arguments.
`char** args`
  The actual arguments
`int fromfile`
  A flag indicating that they are read from the .cxref file.

Prototyped in: | cxref.c
Calls: | SafeFree() | memory.c
| SafeMalloc() | memory.c
| SafeMallocString() | memory.c
| SafeRealloc() | memory.c
| fprintf(), strcmp(), strncmp()
Called by: | ParseConfigFile() | cxref.c
| main() | cxref.c
References Variables: | cpp_argument_num | cxref.c
| cpp_command | cxref.c
| cpp_command_num | cxref.c
| option_all_comments | cxref.c
| option_block_comments | cxref.c
| option_delete | cxref.c
| option_files | cxref.c
| option_html | cxref.c
| option_incdirs | cxref.c
| option_index | cxref.c
| option_latex | cxref.c
| option_name | cxref.c
| option_nfiles | cxref.c
| option_nincdirs | cxref.c
| option_no_comments | cxref.c
| option_odir | cxref.c
| option_raw | cxref.c
| option_root | cxref.c
| option_rtf | cxref.c
| option_sgml | cxref.c
| option_verbatim_comments | cxref.c
| option_warn | cxref.c
| option_xref | cxref.c

## Local Function Usage()

Print out the usage instructions.

`static void Usage ( int verbose )`

`int verbose`
  If true then output a long version of the information.

Prototyped in: | cxref.c
Calls: | exit(), fputs()
Called by: | main() | cxref.c

## Local Function pclose_execvp()

Close the file to the to the preprocessor

`static int pclose_execvp ( FILE* f )`

`int pclose_execvp`
  Return the error status.
`FILE* f`
  The file to close.

Prototyped in: | cxref.c
Calls: | fclose(), waitpid()
Called by: | DocumentTheFile() | cxref.c
References Variables: | popen_pid | cxref.c

## Local Function popen_execvp()

A popen function that takes a list of arguments not a string.

`static FILE* popen_execvp ( char** command )`

`FILE* popen_execvp`
  Returns a file descriptor.
`char** command`
  The command arguments.

Prototyped in: | cxref.c
Calls: | close(), dup(), execvp(), exit(), fdopen(), fork(), fprintf(), pipe()
Called by: | DocumentTheFile() | cxref.c
References Variables: | popen_pid | cxref.c