File cxref.c

RCS Header: /home/amb/cxref/RCS/cxref.c 1.61 2003/06/27 18:06:38 amb Exp

C Cross Referencing & Documentation tool. Version 1.5e.


Included Files


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 run_command

The information about the cxref run, the command line options.

char* run_command
Visible in:  cxref.c
   html.c
   latex.c
   rtf.c
   sgml.c
Used in: ParseOptions()cxref.c
  WriteHTMLPreamble()html.c
  WriteLatexAppendix()latex.c
  WriteLatexFile()latex.c
  WriteSGMLPreamble()sgml.c
  main()cxref.c


Global Variable run_cpp_command

The information about the cxref run, the cpp command and options.

char* run_cpp_command
Visible in:  cxref.c
   html.c
   latex.c
   rtf.c
   sgml.c
Used in: WriteHTMLPreamble()html.c
  WriteLatexAppendix()latex.c
  WriteLatexFile()latex.c
  WriteSGMLPreamble()sgml.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
  SeenFileChange()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
The same function is used in WWWOFFLE and cxref with changes for files or URLs.

Prototyped in: cxref.h
Calls: strcmp(), strlen(), strncmp(), 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: CurFilecxref.c
  cpp_argument_numcxref.c
  cpp_commandcxref.c
  cpp_command_numcxref.c
  option_deletecxref.c
  option_filescxref.c
  option_htmlcxref.c
  option_incdirscxref.c
  option_indexcxref.c
  option_latexcxref.c
  option_namecxref.c
  option_nfilescxref.c
  option_nincdirscxref.c
  option_odircxref.c
  option_rawcxref.c
  option_rootcxref.c
  option_rtfcxref.c
  option_sgmlcxref.c
  option_warncxref.c
  option_xrefcxref.c
  run_commandcxref.c
  run_cpp_commandcxref.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_commandcxref.c
  cpp_command_numcxref.c
  yydebugparse-yacc.c
  yyinparse-lex.c


Local Function ParseConfigFile()

Read in the options from the configuration file.

static int ParseConfigFile ( void )

int ParseConfigFile
Returns the value 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_filescxref.c
  option_nfilescxref.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: ConcatStrings()memory.c
  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_numcxref.c
  cpp_commandcxref.c
  cpp_command_numcxref.c
  option_all_commentscxref.c
  option_block_commentscxref.c
  option_deletecxref.c
  option_filescxref.c
  option_htmlcxref.c
  option_incdirscxref.c
  option_indexcxref.c
  option_latexcxref.c
  option_namecxref.c
  option_nfilescxref.c
  option_nincdirscxref.c
  option_no_commentscxref.c
  option_odircxref.c
  option_rawcxref.c
  option_rootcxref.c
  option_rtfcxref.c
  option_sgmlcxref.c
  option_verbatim_commentscxref.c
  option_warncxref.c
  option_xrefcxref.c
  run_commandcxref.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_pidcxref.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_pidcxref.c