4
votes
  1. Generally I want Doxygen to allow viewing the source code of documented files. But I want a part of the source code to be hidden. I know how to force Doxygen not to document certain piece of code (e.g. with /cond /endcond), but it still appears when clicking on "Go to the source code of this file".

    What I actually want is: if something is not commented in Doxygen-style, it shall appear nowhere at all, not in the documentation nor within "Go to the source code of this file". This shall be the case for functions as well as for #-defines or whatever.

  2. I use @hideinitializer to hide the initializer for #-defines. That works well within the documentation. But again, the initializer is still shown within the source code.

Does anybody have any suggestions?

1

1 Answers

4
votes

You can pre-process source files by specifying a filter script/program using the INPUT_FILTER option. Then, by setting FILTER_SOURCE_FILE = YES, the filtered source code will be used in the source browser rather than the original source.

From the docs:

The INPUT_FILTER tag can be used to specify a program that doxygen should invoke to filter for each input file. Doxygen will invoke the filter program by executing (via popen()) the command:

<filter> <input-file>

where is the value of the INPUT_FILTER tag, and is the name of an input file. Doxygen will then use the output that the filter program writes to standard output.

and

If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using INPUT_FILTER ) will also be used to filter the input files that are used for producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES).


As a crude example, using the following source (saved as filter.py in the same location as Doxyfile, and made executable):

#!/usr/bin/env python
import fileinput, re

# output all lines that does not start with // (but allow //!)
for line in fileinput.input():
  if not re.match(r'\s*//(?![!])', line):
    print line,

and in Doxyfile, setting:

INPUT_FILTER = ./filter.py
FILTER_SOURCE_FILE = YES

The output source browser will now show only lines that do not start with //.

Naturally, creating a filter script that discards all C-style comments except those that are relevant to doxygen will be a lot more involved than the one shown above.