# File xref.c

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

C Cross Referencing & Documentation tool. Version 1.4.
Cross referencing of functions.

## Included Files

- `#include <stdlib.h>`

- `#include <stdio.h>`

- `#include <string.h>`

- `#include <unistd.h>`

- `#include "memory.h"`

- `#include "datatype.h"`

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

## Preprocessor definitions

The names of the function cross reference files.

`#define XREF_FUNC_FILE ".function"`

`#define XREF_FUNC_BACKUP ".function~"`

The names of the variable cross reference files.

`#define XREF_VAR_FILE ".variable"`

`#define XREF_VAR_BACKUP ".variable~"`

The names of the include cross reference files.

`#define XREF_INC_FILE ".include"`

`#define XREF_INC_BACKUP ".include~"`

The names of the type cross reference files.

`#define XREF_TYPE_FILE ".typedef"`

`#define XREF_TYPE_BACKUP ".typedef~"`

## External Variables

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

option_xref
The option for cross referencing.

`extern int option_xref`

Defined in: | cxref.c

option_index
The option for indexing.

`extern int option_index`

Defined in: | cxref.c

## Global Function CreateAppendix()

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

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

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

Prototyped in: | cxref.h
Calls: | AddToStringList() | slist.c
| AddToStringList2() | slist.c
| ConcatStrings() | memory.c
| fclose(), fgets(), fopen(), fscanf(), strlen()
Called by: | main() | cxref.c
References Variables: | option_index | cxref.c
| option_name | cxref.c
| option_odir | cxref.c

## Global Function CrossReference()

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.

`void CrossReference ( File file )`

`File file`
  The file structure containing the information.

Prototyped in: | cxref.h
Calls: | AddToStringList() | slist.c
| ConcatStrings() | memory.c
| check_for_called() | xref.c
| check_for_caller() | xref.c
| check_for_var() | xref.c
| check_for_var_func() | xref.c
| fixup_extern_var() | xref.c
| exit(), fclose(), fgets(), fopen(), fprintf(), fputs(), fscanf(), rename(), strcmp(), unlink()
Called by: | main() | cxref.c
References Variables: | option_name | cxref.c
| option_odir | cxref.c
| option_xref | cxref.c

## Global Function CrossReferenceDelete()

Delete the named file from the cross reference database.

`void CrossReferenceDelete ( char* name )`

`char* name`
  The name of the file that is to be deleted.

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

## Local Function check_for_called()

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

`static void check_for_called ( File file, char* called, char* caller, char* filename )`

`File file`
  The file structure.
`char* called`
  The function that is called.
`char* caller`
  The function that the called function is called from.
`char* filename`
  The file that the function is called from.

Prototyped in: | xref.c
Calls: | AddToStringList2() | slist.c
| strcmp()
Called by: | CrossReference() | xref.c

## Local Function check_for_caller()

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

`static void check_for_caller ( File file, char* called, char* filename )`

`File file`
  The file structure.
`char* called`
  The function that is called.
`char* filename`
  The file that the called function is in.

Prototyped in: | xref.c
Calls: | SafeMallocString() | memory.c
| strcmp()
Called by: | CrossReference() | xref.c

## Local Function check_for_var()

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

`static void check_for_var ( File file, char* variable, char* filename, int scope, char* funcname )`

`File file`
  The file structure.
`char* variable`
  The global variable name.
`char* filename`
  The file that the variable is used in.
`int scope`
  The scope of the variable in the foreign file.
`char* funcname`
  The name of a function that uses the variable.

Prototyped in: | xref.c
Calls: | AddToStringList2() | slist.c
| SafeMallocString() | memory.c
| strcmp()
Called by: | CrossReference() | xref.c

## Local Function check_for_var_func()

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

`static int check_for_var_func ( File file, Variable var, Function func )`

`int check_for_var_func`
  Returns 1 if the variable is referenced from the function or file.
`File file`
  The file that the function belongs to.
`Variable var`
  The variable that may be referenced.
`Function func`
  The function that is to be checked.

Prototyped in: | xref.c
Calls: | AddToStringList2() | slist.c
| SafeFree() | memory.c
| SafeMallocString() | memory.c
| strcmp()
Called by: | CrossReference() | xref.c

## Local Function fixup_extern_var()

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.

`static void fixup_extern_var ( Variable var, StringList2 refs )`

`Variable var`
  The list of variables for this file.
`StringList2 refs`
  A list of variable references from a file or a function.

Prototyped in: | xref.c
Calls: | SafeFree() | memory.c
| SafeMallocString() | memory.c
| strcmp()
Called by: | CrossReference() | xref.c