tqsheng

go.....
随笔 - 366, 文章 - 18, 评论 - 101, 引用 - 0
数据加载中……

Doxygen入门(1)--基础知识


来自:http://www.stack.nl/~dimitri/doxygen/starting.html

Getting started

The executable doxygen is the main program that parses the sources and generates the documentation. See section Doxygen usage for more detailed usage information.

[可执行的 doxygen 是一种源文件转换及文档生成工具,具体使用信息请参见 Doxygen用法 ]

The executable doxytag is only needed if you want to generate references to external documentation (i.e. documentation that was generated by doxygen) for which you do not have the sources. See section Doxytag usage for more detailed usage information.

[可执行的 doxytag 是一种外部文档索引生成工具,当然所谓外部文档也是应由 doxygen 生成的,doxytag 特别适合于所基于的外部文档不包含源程序时的情况。具体查看 Doxytag 用法 ]

Optionally, the executable doxywizard can be used, which is a graphical front-end for editing the configuration file that is used by doxygen and for running doxygen in a graphical environment. For Mac OS X doxywizard will be started by clicking on the Doxygen application icon.

[另外,可执行的 doxywizard 是一种前端图形工具,用于配置文件的编辑。如果在 Mac 中使用 doxywizard 可以直接点击 Doxygen 应用程序图标。]

The following figure shows the relation between the tools and the flow of information between them (it looks complex but that's only because it tries to be complete):

[下图说明了工具和信息流向的关系,虽然看起来有些复杂,但其实很简单,当然复杂也是因为 Doxygen 期望能够提供更完善的功能。]

infoflow.gif

Doxygen information flow

Step 1: Creating a configuration file [第一步:创建配置文件]

Doxygen uses a configuration file to determine all of its settings. Each project should get its own configuration file. A project can consist of a single source file, but can also be an entire source tree that is recursively scanned.

[Doxygen 使用配置文件来决定使用中所有的设置。每个项目应该拥有自己的配置文件。这里所说的项目可以包含一个文件的项目,当然更适合的是包括整个源文件树中所有文件的项目。]

To simplify the creation of a configuration file, doxygen can create a template configuration file for you. To do this call doxygen from the command line with the -g option:

[为了简化配置文件的创建, doxygen 提供了配置模板,使用如下命令即可:]

doxygen -g <config-file>

where <config-file> is the name of the configuration file. If you omit the file name, a file named Doxyfile will be created. If a file with the name <config-file> already exists, doxygen will rename it to <config-file>.bak before generating the configuration template. If you use - (i.e. the minus sign) as the file name then doxygen will try to read the configuration file from standard input (stdin), which can be useful for scripting.

[其中 <config-file> 是配置文件的名称。如果忽略该项,默认的文件名将被创建,即 Doxyfile。如果指定的 <config-file> 已经存在,doxygen 将重命名原来的文件为 <config-file>.bak,之后再生成新的配置模板。如果我们使用 -(减号)作为文件名,doxygen 将尝试从标准输入(stdin)读取配置信息,这种方式特别适合于自写脚本。]

The configuration file has a format that is similar to that of a (simple) Makefile. It consists of a number of assignments (tags) of the form:

[配置文件的格式类似于简单的 Makefile,它包含一些具有赋值格式的标签,如下:]

TAGNAME = VALUE or 
TAGNAME = VALUE1 VALUE2 ... 

You can probably leave the values of most tags in a generated template configuration file to their default value. See section Configuration for more details about the configuration file.

[我们可以保留大部分标签的默认值,参见具体配置说明。]

If you do not wish to edit the config file with a text editor, you should have a look at doxywizard, which is a GUI front-end that can create, read and write doxygen configuration files, and allows setting configuration options by entering them via dialogs.

[如果我们不希望以文本形式编辑配置文件,我们可以使用 doxywizard,它是一个 doxygen 的前端 gui,用以创建、读取、编辑 doxygen 配置文件,可以通过对话框选择配置选项。]

For a small project consisting of a few C and/or C++ source and header files, you can leave INPUT tag empty and doxygen will search for sources in the current directory.

[对于只包含几个C或C++源文件及头文件的小项目来说,我们可以使 INPUT 标签留空,这样 doxygen 将在当前文件夹中搜寻所有的源文件。]

If you have a larger project consisting of a source directory or tree you should assign the root directory or directories to the INPUT tag, and add one or more file patterns to the FILE_PATTERNS tag (for instance *.cpp *.h). Only files that match one of the patterns will be parsed (if the patterns are omitted a list of source extensions is used). For recursive parsing of a source tree you must set the RECURSIVE tag to YES. To further fine-tune the list of files that is parsed the EXCLUDE and EXCLUDE_PATTERNS tags can be used. To omit all testdirectories from a source tree for instance, one could use:

[如果处理包含一个源文件目录的大项目,我们应该令 INPUT 标签等于源文件根目录和相应的目录,并添加文件类型
标签 FILE_PATTERNS (如 *.cpp、*.h)。只有匹配文件类型的文件才会被处理,如果该标签忽略不指明,则“源文件
扩展列表”将被采用。如果希望迭代处理源代码树,你必须设置 RECURSIVE 为 YES。如果希望更精确地控制文件
类型列表,还可以使用 EXCLUDEEXCLUDE_PATTERNS 。如下面列子,如果需要忽略掉 test 目录下的所有文件,
可以这样处理:]

EXCLUDE_PATTERNS = */test/*

Doxygen looks at the file's extension to determine how to parse a file. If a file has an .idl or .odl extension it is treated as an IDL file. If it has a .java extension it is treated as a file written in Java. Files ending with .cs are treated as C# files and the .py extension selects the Python parser. Finally, files with the extensions .php.php4,.inc or .phtml are treated as PHP sources. Any other extension is parsed as if it is a C/C++ file, where files that end with .m are treated as Objective-C source files.

[Doxygen 是通过文件的扩展名来决定如何处理文件的。如果某个文件扩展名为 .idl 或 .odl,那么这个文件即被认为

是 IDL 文件。如果某个具有 .java 扩展名,那么即被认为是由 Java 语言写成的文件。同样,.cs 是 C# 文件,.py 文件

作为 Python 来处理;.php、.php4、.inc 或 .phtml 被认为是 PHP 源文件。其他的就被认为是 C/C++文件处理,其中

以 .m 结尾的被认为是 Object-C 文件处理。]

If you start using doxygen for an existing project (thus without any documentation that doxygen is aware of), you can still get an idea of what the structure is and how the documented result would look like. To do so, you must set the EXTRACT_ALL tag in the configuration file to YES. Then, doxygen will pretend everything in your sources is documented. Please note that as a consequence warnings about undocumented members will not be generated as long as EXTRACT_ALL is set to YES.

[如果你使用 doxygen 对现有项目进行处理(也就是说目前 doxygen 对要处理的项目还一无所知),我们可以先规划出未来成品的结构如何,或者是明确到底以什么样子呈现。为实现该目的,我们必须设置 EXTRACT_ALL 标签为 YES。这样,doxygen 将记录源文件中所有内容。请注意:使用了该标签后,未记录的成员或文件内容将不会得到任何提示或警告。]

To analyse an existing piece of software it is useful to cross-reference a (documented) entity with its definition in the source files. Doxygen will generate such cross-references if you set the SOURCE_BROWSER tag to YES. It can also include the sources directly into the documentation by setting INLINE_SOURCES to YES (this can be handy for code reviews for instance).

[另外,使用交叉引用(链接源文件定义片断)在软件分析中十分有效,Doxygen 将在 SOURCE_BROWSER 为 YES 的情况下自动产生交叉引用。如果设置 INLINE_SOURCES 为 YES,可以使源代码直接加入到文档中,这对代码复审非常有用。]

(自己注:记得将 OUTPUT_LANGUAGE=Chinese)

Step 2: Running doxygen [第二步:运行 doxygen]

To generate the documentation you can now enter: [我们可以直接使用以下命令产生文档:]
doxygen <config-file>

Depending on your settings doxygen will create htmlrtflatexxml and/or man directories inside the output directory. As the names suggest these directories contain the generated documentation in HTML, RTF, $\mbox{\LaTeX}$, XML and Unix-Man page format.

[通过不同的设置,doxygen 可以在输出目录中生成各种文件夹,如何 html、rtf、latex、xml 或 man等,并分别代表所生成的 HTML、RTF、XML以及 $\mbox{\LaTeX}$, Unix-Man 格式文档。]

The default output directory is the directory in which doxygen is started. The root directory to which the output is written can be changed using the OUTPUT_DIRECTORY. The format specific directory within the output directory can be selected using the HTML_OUTPUTRTF_OUTPUTLATEX_OUTPUTXML_OUTPUT, and MAN_OUTPUT tags of the configuration file. If the output directory does not exist, doxygen will try to create it for you (but it will nottry to create a whole path recursively, like mkdir -p does).

[默认的输出文件夹为当前运行 doxygen 的文件夹,当然可以使用 OUTPUT_DIRECTORY 修改根目录。另外,根目录下特定的文件夹可以通过以下标签设置,即HTML_OUTPUTRTF_OUTPUTLATEX_OUTPUTXML_OUTPUT, 和 MAN_OUTPUT 。如果输出文件夹不存在,那么 doxygen 将尝试创建一个新的,但是不会象 mkdir -p 一样工作。]

HTML output

The generated HTML documentation can be viewed by pointing a HTML browser to the index.html file in the htmldirectory. For the best results a browser that supports cascading style sheets (CSS) should be used (I'm using Mozilla, Safari, Konqueror, and sometimes IE6 to test the generated output).

[生成的 HTML 文档通过 index.html 起始,这些 HTML 文档采用 CSS。]

Some of the features the HTML section (such as GENERATE_TREEVIEW) require a browser that supports DHTML and Javascript.

[还有一些特性(如 GENERATE_TREEVIEW)需要浏览器支持 DHTML 和 Javascript。]

If you plan to use the search engine (see SEARCHENGINE), you should view the HTML output via a PHP-enabled web server (e.g. apache with the PHP module installed).

[如果你计划使用搜索引擎(见SEARCHENGINE)你应当通过 php web服务器来查看 html 输出。]

LaTeX output

The generated $\mbox{\LaTeX}$ documentation must first be compiled by a $\mbox{\LaTeX}$ compiler (I use a recent teTeX distribution). To simplify the process of compiling the generated documentation, doxygen writes a Makefile into the latexdirectory.

The contents and targets in the Makefile depend on the setting of USE_PDFLATEX. If it is disabled (set to NO), then typing make in the latex directory a dvi file called refman.dvi will be generated. This file can then be viewed using xdvi or converted into a PostScript file refman.ps by typing make ps (this requires dvips).

To put 2 pages on one physical page use make ps_2on1 instead. The resulting PostScript file can be send to a PostScript printer. If you do not have a PostScript printer, you can try to use ghostscript to convert PostScript into something your printer understands.

Conversion to PDF is also possible if you have installed the ghostscript interpreter; just type make pdf (or make pdf_2on1).

To get the best results for PDF output you should set the PDF_HYPERLINKS and USE_PDFLATEX tags to YES. In this case the Makefile will only contain a target to build refman.pdf directly.

RTF output

Doxygen combines the RTF output to a single file called refman.rtf. This file is optimized for importing into the Microsoft Word. Certain information is encoded using field. To show the actual value you need to select all (Edit - select all) and then toggle fields (right click and select the option from the drop down menu).

XML output

The XML output consists of a structured "dump" of the information gathered by doxygen. Each compound (class/namespace/file/...) has its own XML file and there is also an index file called index.xml.

A file called combine.xslt XSLT script is also generated and can be used to combine all XML files into a single file.

Doxygen also generates two XML schema files index.xsd (for the index file) and compound.xsd (for the compound files). This schema file describes the possible elements, their attributes and how they are structured, i.e. it the describes the grammar of the XML files and can be used for validation or to steer XSLT scripts.

In the addon/doxmlparser directory you can find a parser library for reading the XML output produced by doxygen in an incremental way (see addon/doxmlparser/include/doxmlintf.h for the interface of the library)

Man page output

The generated man pages can be viewed using the man program. You do need to make sure the man directory is in the man path (see the MANPATH environment variable). Note that there are some limitations to the capabilities of the man page format, so some information (like class diagrams, cross references and formulas) will be lost.

Step 3: Documenting the sources[第三步:标记源文件]

Although documenting the sources is presented as step 3, in a new project this should of course be step 1. Here I assume you already have some code and you want doxygen to generate a nice document describing the API and maybe the internals as well.

[虽然标记源文件放在了第三步,但实际上对于一个新项目来说,这应该是第一步。这里我们假设你已经有一些代码,并想利用 doxygen 来生成漂亮的文档以描述 API 或内部细节等。]

If the EXTRACT_ALL option is set to NO in the configuration file (the default), then doxygen will only generate documentation for documented members, files, classes and namespaces. So how do you document these? For members, classes and namespaces there are basically two options:

[如果 EXTRACT_ALL 标签设置为 NO(默认值),那么 doxygen 只生成已经标记的成员、文件、类及命名空间。所以我们该如何标记它们,这里对成员、类、命名空间给出两条基本原则:]

  1. Place a special documentation block in front of the declaration or definition of the member, class or namespace. For file, class and namespace members it is also allowed to place the documention directly after the member. See section Special documentation blocks to learn more about special documentation blocks.
  2. Place a special documentation block somewhere else (another file or another location) and put a structural command in the documentation block. A structural command links a documentation block to a certain entity that can be documented (e.g. a member, class, namespace or file). See section Documentation at other places to learn more about structural commands.
      1、在成员、类、命名空间前放置特别的标记块。对于一个文件、类、命名空间等,同样可以直接在成员后面加上标记。详见Special documentation blocks
2、在另一个文件或位置放置特别的标记块,并在标记块中置入结构化命令。结构化命令将提供到某个记录块或某个位置的链接(如链接到成员、类、命名空间等。)详见:Documentation at other places 

Files can only be documented using the second option, since there is no way to put a documentation block before a file. Of course, file members (functions, variable, typedefs, defines) do not need an explicit structural command; just putting a special documentation block in front or behind them will do.

[文件只能以上面第二种方式标记,因为我们是没有方式在一个文件前面置入标记块的。当然,文件成员(包括函数、变量、类型定义、定义等)不需要明确的结构化命令。只要在它们前面或后面放入特别的标记块即可。]

The text inside a special documentation block is parsed before it is written to the HTML and/or $\mbox{\LaTeX}$ output files.

[特别标记块中的文本将在输出前被转换。]

During parsing the following steps take place: [转换步骤:]

  • The special commands inside the documentation are executed. See section Special Commands for an overview of all commands.
  • [标记中的特别命令被执行,详见: Special Commands ]
  • If a line starts with some whitespace followed by one or more asterisks (*) and then optionally more whitespace, then all whitespace and asterisks are removed.
  • [如果某行以 whitespace 加上一个或多个星号开始,后面可能还会有更多 whitespace,那么所有的 whitespace 和星号将被删除]
  • All resulting blank lines are treated as a paragraph separators. This saves you from placing new-paragraph commands yourself in order to make the generated documentation readable.
  • [所有空行将被认为是段落分隔。这会省去加入段落命令的麻烦。]
  • Links are created for words corresponding to documented classes (unless the word is preceded by a %; then the word will not be linked and the % sign is removed).
  • [创建标记类的链接。如果链接文字前标有 %,那么该文字将不会被认为是链接,同时删除 %]
  • Links to members are created when certain patterns are found in the text. See section Automatic link generationfor more information on how the automatic link generation works.
  • [创建标记成员的链接。详见:Automatic link generation ]
  • HTML tags that are in the documentation are interpreted and converted to $\mbox{\LaTeX}$ equivalents for the $\mbox{\LaTeX}$ output. See section HTML Commands for an overview of all supported HTML tags.
  • [文档中的HTML标签被转换。]

Go to the next section or return to the index.

posted on 2012-07-10 16:33 tqsheng 阅读(533) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理