don't check when its clang masquerading as gcc
[AROS.git] / tools / cxref / README.tex
blob8015a5bf3ae0cb81c14f30af4ba063edb25201cb
1 % This LaTeX file generated by cxref (and then edited by hand).
2 % cxref program README (c) Andrew M. Bishop 1995,96,97,98,99.
4 \documentclass{report}
5 \usepackage{doc/fonts,doc/page,doc/cxref}
6 \pagestyle{myheadings}
8 \begin{document}
10 % Contents (Optional, either here or at end)
12 %\markboth{Contents}{Contents}
13 %\tableofcontents
15 \chapter{C Cross Referencing \& Documenting tool. Version 1.5 - cxref}
17 A program that can automatically generate documentation and cross references for
18 a C program.
20 The input is any C program with appropriate comments and the output is \LaTeX ,
21 HTML, RTF or SGML files.
23 \section{Program Options}
25 The name of the program is cxref.
27 \smallskip
29 \begin{tabular}{ll}
30 Usage: {\tt cxref} & \\
31 & {\tt filename [ ... filename]} \\
32 & {\tt [-Odirname] [-Nbasename] [-Rdirname]} \\
33 & {\tt [-all-comments] [-no-comments]} \\
34 & {\tt [-verbatim-comments] [-block-comments]} \\
35 & {\tt [-xref[-all][-file][-func][-var][-type]]} \\
36 & {\tt [-warn[-all][-comment][-xref]]} \\
37 & {\tt [-index[-all][-file][-func][-var][-type]]} \\
38 & {\tt [-raw]} \\
39 & {\tt [-latex209|-latex2e]} \\
40 & {\tt [-html20|-html32][-src]} \\
41 & {\tt [-rtf]} \\
42 & {\tt [-sgml]} \\
43 & {\tt [-Idirname] [-Ddefine] [-Udefine]} \\
44 & {\tt [-CPP cpp\_program] [-- cpp\_arg [ ... cpp\_arg]]} \\
45 \end{tabular}
46 \begin{tabular}{ll}
47 Usage: {\tt cxref} & \\
48 & {\tt filename [ ... filename] -delete} \\
49 & {\tt [-Odirname] [-Nbasename] [-Rdirname]} \\
50 \end{tabular}
52 \begin{list}{}{\leftmargin=1in \labelwidth=2.5in}
53 \item[{\tt filename}]
54 The name of the file to document, any number of files may be
55 documented at a time.
56 \item[{\tt -delete}]
57 The files named are to be deleted from the output directory and
58 their entries in the cross reference database and main output
59 files are to be removed.
60 \item[{\tt -Odirname}]
61 The name of a directory to use for the output \LaTeX files and
62 the location of the cross reference files that are created.
63 \item[{\tt -Nbasename}]
64 The name to use for the first part of the output and cross
65 reference files instead of cxref, the file extensions remain
66 the same.
67 \item[{\tt -Rdirname}]
68 When the source files are in more than one directory, set
69 dirname to the name of the root directory of the source tree
70 (use relative path if easier e.g. ``-R../..''). This will then
71 run cxref from that root directory and the ``-Odirname'' must be
72 relative to that directory.
73 \item[{\tt -all-comments}]
74 In case you think that the existing comments might work,
75 (see below for description of special comments).
76 {\it[Danger! This option can produce weird results.]}
77 \item[{\tt -no-comments}]
78 Ignores all comments, useful if you just want the cross
79 references and not the documentation.
80 \item[{\tt -verbatim-comments}]
81 When the comments that you have in the code are formatted
82 in a predetermined style that you want to preserve on the
83 output, this option will force them not to be reformatted.
84 {\it[Note, this is for file and function comments only.]}
85 \item[{\tt -block-comments}]
86 When the comments in the program are formatted in the ``block''
87 style (with a leading ``*'' character on every line), this option
88 will remove that character from the output.
89 {\it[Works for a single ``*'', ``+'', ``|'' or ``:'' on each line.]}
90 \item[{\tt -xref}]
91 Produce cross referencing information (see below).
92 \begin{list}{}{\leftmargin=1in \labelwidth=1in}
93 \item[{\tt -all}] All cross references.
94 \item[{\tt -file}] Cross references for files.
95 \item[{\tt -func}] Cross references for functions.
96 \item[{\tt -var}] Cross references for variables.
97 \item[{\tt -type}] Cross references for types.
98 \end{list}
99 \item[{\tt -warn}]
100 Produce warnings, the options must be concatenated together:
101 \begin{list}{}{\leftmargin=1in \labelwidth=1in}
102 \item[{\tt -all}] All warnings.
103 \item[{\tt -comment}] Warn of missing comments.
104 \item[{\tt -xref}] Warn of missing cross references.
105 \end{list}
106 \item[{\tt -index}]
107 Produce a cross reference index, the options must be
108 concatenated together:
109 \begin{list}{}{\leftmargin=1in \labelwidth=1in}
110 \item[{\tt -all}] All indexes.
111 \item[{\tt -file}] Index of files.
112 \item[{\tt -func}] Index of functions.
113 \item[{\tt -var}] Index of variables.
114 \item[{\tt -type}] Index of types.
115 \end{list}
116 \item[{\tt -raw}]
117 Produce a raw form of output, not really of much use except
118 with -warn.
119 \item[{\tt -latex209}]
120 Produce a LaTeX file to document each of the source files and
121 also an extra file that includes each of these files. (Using
122 the LaTeX version 2.09 format.)
123 \item[{\tt -latex2e}]
124 Produce the LaTeX file described above for use with the
125 LaTeX2e version of LaTeX.
126 \item[{\tt -html20}]
127 Produce an HTML file to document each of the source files and
128 a main file to reference each of these files. (using the HTML
129 2.0 standard, no tables).
130 \item[{\tt -html32}]
131 Produce the HTML file described above but using HTML 3.2.
132 \item[{\tt -html20-src}]
133 Produce the HTML v2.0 output and a HTML version of the source
134 file with links into it.
135 \item[{\tt -html32-src}]
136 Produce the HTML v3.2 output and a HTML version of the source
137 file with links into it.
138 \item[{\tt -rtf}]
139 Produce a Rich Text Format (RTF) file to document the source
140 file.
141 \item[{\tt -sgml}]
142 Produce an SGML file to document the source file. (Using the
143 LinuxDoc DTD).
144 \item[{\tt -Idirname}]
145 GCC option to specify the path for include files.
146 \item[{\tt -Ddefine}]
147 GCC option to define a pre-processor symbol.
148 \item[{\tt -Udefine}]
149 GCC option to undefine a pre-processor symbol.
150 \item[{\tt -CPP program}]
151 The name of the program to use instead of the compile time
152 default. The program must be able to perform all of the actions
153 that ``gcc -E -C -dD'' does to work. If the program takes
154 arguments then the whole thing needs to be in quotes so that it
155 is interpreted as a single argument to cxref.
156 \item[{\tt-- arg ... arg}]
157 Extra arguments to be passed to the pre-processor can be placed
158 after the ``--'' separator.
159 \end{list}
161 \section{C Compiler Replacement cxref-cc}
163 To simplify using cxref on existing source code, there is now a shell script
164 that will call the C compiler and then call cxref to process the source file.
165 This means that it can be used as a drop in replacement for CC in Makefiles and
166 the like.
168 Usage: cxref-cc [usual cc options]
170 The name of the source file is extracted from the list of options as well as the
171 ``-D*'', ``-I*'', ``-U*'' flags and when the C compiler exits succesfully cxref will
172 be called. The name of the C compiler to use is controlled by the CXREFCC
173 environment variable, or if this is not set then the CC environment variable, or
174 failing this just gcc.
176 Using this script requires the use of a `.cxref' configuration file to contain
177 the options since there is nowhere to put the options on the command line for
178 the C compiler.
180 This will only cross-reference and document the C source files since they are
181 the only ones that are compiled, but it will make sure that they are
182 cross-referenced with the correct options etc.
184 \section{Cxref configuration File}
186 These command line arguments can also be put into a file named ``.cxref'' instead of
187 on the command line. When cxref is run the arguments to the program are
188 interpreted in the following order.
190 \begin{enumerate}
191 \item Those on the command line.
192 \item Those in the ``.cxref'' file in the current directory.
193 \item Those in the ``.cxref'' file in the source tree root specified by ``-R''.
194 \end{enumerate}
196 This means that in a multi-directory source tree, each sub-directory can have a
197 ``.cxref'' file containing just the line ``-R..'' or appropriate. The main
198 directory can have a ``.cxref'' file containing the remainder of the options. This
199 removes completely the need to have any options on the command line apart from
200 the source file names.
202 The format of the .cxref file is any number of lines, each one containing a
203 single command line argument (equivalent to one of the argv). The only options
204 that cannot be used are the names of source files themselves and the ``-delete''
205 option. Blank lines are ignored and lines starting with a `\#' are comments.
207 \section{Program Documentation Comments}
209 The documentation for the program is produced from comments in the code that are
210 appropriately formatted. The cross referencing comes from the code itself and
211 requires no extra work.
213 The special comments are ``/**** ****/'' (for a file) and ``/*++++ ++++*/'' (for a
214 data object) any number of ``*'' or ``+'' can be used inside of the standard ``/*''
215 and ``*/'' comment delimiters in the comments, they are ignored.
217 If a comment line starts with whitespace and is followed by `+html+' then the
218 rest of the line is included only in the HTML output, and is not processed so it
219 can include HTML markup, `-html-' means that the rest of the line is included in
220 all except the HTML output. The same also applies to the other output formats,
221 `+none+' can be used for lines not to appear in any output. The exception to
222 this is that the raw output does not do any checking and will output all lines.
224 In any situation where a comment follows a ``,'', ``;'' or ``)'' separated only by
225 spaces and tabs, the comment is pushed to before the punctuation to apply to
226 the object there.
228 The program is implemented using a full ANSI C grammar parser with some GCC
229 extensions, this means that the style of the code is unimportant, only the
230 content and comments.
232 \section{Automated Comment Insertion}
234 To simplify the insertion of comments that will be parsed by cxref, the file
235 cxref.el provides a number of Emacs lisp functions. To use them add the line
236 {\tt (load "cxref")} to your ``.emacs'' file or type {\tt M-x load-file cxref.el} from
237 within Emacs.
239 The functions and key bindings are:
240 \begin{list}{}{\leftmargin=1.3in \labelwidth=2.5in}
241 \item[{\it Control-C Control-F}]
242 Adds file comments, a /** **/ header at the top of the
243 file and if it is a .h file then it also adds a \#ifndef,
244 \#define at the beginning and \#endif at the end to stop
245 multiple inclusions.
246 \item[{\it Control-C f}]
247 Adds comments to a function, the cursor must be on the
248 line containing the start of the function definition when
249 this function is called. The /*+ ... +*/ comment that is
250 added is of the header type (see the examples) not inline.
251 \item[{\it Control-C v}]
252 Adds a leading comment to the variable or other definition
253 on the current line.
254 \item[{\it Control-C e}]
255 Adds a trailing comment at the end of the line.
256 \item[{\it Control-C i}]
257 Adds an inline comment that is ignored by cxref.
258 \end{list}
260 \section{C Preprocessor}
262 To improve the output that is available a modified version of the GNU CPP V2.7.2
263 is supplied (named cxref-cpp).
265 This modified C preprocessor allows for a finer control over some features of
266 the preprocessing that are not important for a compiler. In a standard
267 preprocessor, the preprocessor directives are intended for use only by the
268 preprocessor, so passing the information through is not important.
270 With cxref-cpp, there are two features that are different to the standard GNU
271 CPP:
273 \begin{enumerate}
274 \item
275 The \#include directives from the file are output in the same way as the
276 \#defines are output. An extra flag has been added to cpp to do this, '-dI',
277 it works in the same way as the existing '-dD' flag for \#defines.
278 \item
279 Comments trailing a \#include or a \#define are dropped with GNU CPP even if -C
280 is used. This is not important while compiling but is useful for documenting.
281 \end{enumerate}
283 \section{Cross Referencing}
285 The cross referencing is performed for the following items
286 \begin{list}{}{\leftmargin=1in \labelwidth=1.5in}
287 \item[Files]
288 \begin{itemize}
289 \item The files that the current file is included in
290 (even when included via other files).
291 \end{itemize}
292 \item[\#includes]
293 \begin{itemize}
294 \item Files included in the current file.
295 \item Files included by these files etc.
296 \end{itemize}
297 \item[Variables]
298 \begin{itemize}
299 \item The location of the definition of external variables.
300 \item The files that have visibility of global variables.
301 \item The files / functions that use the variable.
302 \end{itemize}
303 \item[Functions]
304 \begin{itemize}
305 \item The file that the function is prototyped in.
306 \item The functions that the function calls.
307 \item The functions that call the function.
308 \item The files and functions that reference the function.
309 \item The variables that are used in the function.
310 \end{itemize}
311 \end{list}
312 Each of these items is cross referenced in the output.
314 The cross referencing uses files `cxref.variable', `cxref.function',
315 `cxref.include' and `cxref.typedef' in the output directory.
317 These are a complete list of the function and variable usage in the program and
318 could be used to generate a function call hierarchy or variable usage diagram
319 for example.
321 Two cxref passes of each file is needed, the first to build up the cross
322 referencing files and the second to use them.
324 {\it (The file names are different if the ``-N'' option is used.)}
326 \section{\LaTeX Output}
328 The default \LaTeX output is a file for each of the source files with one extra
329 file ``cxref.tex'' that includes each of the other files. This is to allow a
330 makefile to only update the changed files (although the references may require
331 all of the files to be checked again). When the cxref.tex file has been written
332 it can be modified by the user, any new files that are added are added at the
333 end of the source code section, the rest of the file being unchanged.
335 The index is written to a file called ``cxref.apdx.tex'' and cxref.tex is updated
336 to refer to it.
338 Also written out are three \LaTeX style files ``page.sty'', ``fonts.sty'' and
339 ``cxref.sty''. These set up the page to use a smaller margin and smaller fonts to
340 allow more to appear on a page and also define the new commands for typesetting
341 the cxref output.
343 {\it (The file names ``cxref.tex'' and ``cxref.apdx.tex'' are different if the ``-N''
344 option is used.)}
346 The two different forms of \LaTeX output are selected by using the {\it -latex209} or
347 the {\it -latex2e} options. These select between two sets of output that can be used
348 with those two different versions of \LaTeX.
350 \section{HTML Output}
352 The default HTML output is a file for each of the source files with one extra
353 file ``cxref.html'' that includes each of the other files. This is to allow a
354 makefile to only update the changed files (although the references may require
355 all of the files to be checked again). When the cxref.html file has been
356 written it can be modified by the user, any new files that are added are added
357 at the end before the table of contents, the rest of the file being unchanged.
359 The index is written to a file called ``cxref.apdx.html'' and cxref.html is
360 updated to refer to it.
362 {\it (The file names ``cxref.html'' and ``cxref.apdx.html'' are different if the ``-N''
363 option is used.)}
365 The two different forms of HTML output are selected by using the {\it-html20} or the
366 {\it -html32} options. These select between two sets of output that comply with the
367 HTML 2.0 and 3.2 definitions, they differ in their use of tables.
369 \section{RTF Output}
371 Rich Text Format is a fairly low level page description format devised by
372 Microsoft. It is not a well defined and easy to understand standard as are the
373 other formats, but it is popular for document exchange.
375 There is a single output file for each of the source files and an index file.
377 \section{SGML Output}
379 Since SGML is a meta-language it is necessary to define the layout elements as
380 well as provide the information. The cxref output uses the LinuxDoc document
381 format and is designed for use with the SGMLtools programs
382 (http://www.sgmltools.org/).
384 There is a single output file for each of the source files and an index file.
386 \section{Example Special Comments}
388 The file ``README.c'' is included at the end of this document to show that the
389 comments are indeed seen in the code, the result of running this through cxref
390 is also included.
392 \section{Further Information}
394 There is a list of frequently asked questions and their answers for the cxref
395 program in the FAQ file. A list of improvements planned for future versions of
396 the program are listed in the file TODO.
398 More up-to-date information can be found on the World Wide Web at the cxref
399 homepage, reached via the author's homepage http://www.gedanken.demon.co.uk/.
401 If you wish to submit bug reports or other comments about the program then email
402 the author amb@gedanken.demon.co.uk and put cxref in the subject line.
404 \section{Author and Copyright}
406 The cxref program was written by Andrew M. Bishop in 1995,96,97,98,99.
408 The cxref program is copyright Andrew M. Bishop 1995,96,97,98,99.
410 The cxref-cpp program is copyright Free Software Foundation, Inc.
412 The cxref and cxref-cpp programs can be freely distributed according to the
413 terms of the GNU General Public License (see the file `COPYING').
415 \chapter{Example ``README.c''}
417 % What a hack to load a file into a verbatim section!
418 % I have also had to rename README.c.tex to README_c.tex
419 % so that \input{README.c} does not do \input{README.c.tex} instead.
421 \def\endverbatim{\input{README.c}\endtrivlist}
422 \begin{verbatim}
423 \end{verbatim}
425 \chapter{Cxref Output For ``README.c''}
427 % Begin-Of-Source-Files
429 \input{README_c.tex}
431 % End-Of-Source-Files
433 % Appendix
435 % Contents (Optional, either here or at beginning)
437 \markboth{Contents}{Contents}
438 \tableofcontents
440 \end{document}