Linux环境下添加doxygen对C语言的更好的支持

  1. 云栖社区>
  2. 博客>
  3. 正文

Linux环境下添加doxygen对C语言的更好的支持

技术小甜 2017-11-16 14:37:00 浏览1042
展开阅读全文

doxygen能够从代码的注释中自动生成文档。因此,熟练掌握doxygen的注释格式、配置方法和使用模式,能够极大地方便代码阅读、文档制作和代码评审。doxygen的使用可以从软件安装、配置设置、文档生成这几个方面分别介绍。

 

1. 软件安装

 

以centos 为例,首先安装doxgyen:

 

 install doxygen

 yum search doxygen

yum install doxygen-latex.x86_64 doxygen.x86_64 doxygen-doxywizard.x86_64 polkit-qt-doc.noarch

 

接着安装依赖的图形绘制工具软件:grahpviz

 

install graphviz

yum search graphviz

 yum install graphviz-devel.x86_64 graphviz-doc.x86_64 graphviz-gd.x86_64 graphviz-guile.x86_64 graphviz-java.x86_64 graphviz-lua.x86_64 graphviz-perl.x86_64 graphviz-php.x86_64 graphviz-python.x86_64 graphviz-ruby.x86_64 graphviz-tcl.i686 graphviz-tcl.x86_64 graphviz.x86_64 graphviz-guile.x86_64

 

 

为了便于在vim中直接生成doxygen能识别的常用注释,需要添加vim插件的支持:

首先下载vim 插件:

https://vim.sourceforge.io/scripts/script.php?script_id=987



从其中选择 DoxygenToolkit.vim 0.2.13

   


然后依次执行下面的命令和操作:

cp DoxygenTookkit.vim ~/root/.vim/plugin/

在~/.vimrc最后加入下面几行:

[root@localhost plugin]# tail -f /root/.vimrc

"let Tlist_Auto_Open=1

"let g:vimmake_mode = { 'gcc':'quickfix', 'run':'normal' }

let g:vimmake_mode = { 'gcc' : 'async', 'run' : 'normal' }

let g:doxygenToolkit_authorName="TiShai Hua"

let g:doxygenToolkit_briefTag_funcName="yes"

 

map <F2>a :DoxAuthor

map <F2>f :Dox

map <F2>b :DoxBlock

map <F2>c O/** */<Left><Left>

 

这样就可以参考下面的说明来利用Dox/DoxBlock/DoxAuthor来自动生成可被Doxygen理解的注释了:

//// below generated by : DoxAuthor

/**

 * @file test.c

 * @brief

 * @author hongmei

 * @version 0.01

 * @date 2017-09-21

 */

 

//// below generated by : 'Dox ' command in vim

/**

 * @brief

 *

 * @param a

 * @param b

 *

 * @return

 */

int test(int a ,int b)

{

    int c,i;

//// below generated by : 'DoxBlock' command in vim

    /**

     * @name

     * @{ */

    /**  @} */

 

    c = i = 1;

    a++;

 

    return a;

}

 

 

2. 配置设置

可以运行下面的命令来生成doxygen 配置文件:

doxygen -g

接着编辑Doxyfile, 添加对C inline/static/typedef 的支持,实现对目录、文件、函数的递归解析,支持生产引用和被调用的分析图。我主要的设置如下,仅供参考:

[root@localhost]# cat Doxyfile  | grep -v "#" | egrep -v "^$" | egrep -v "=$" | grep -v "NO"

DOXYFILE_ENCODING      = UTF-8

PROJECT_NAME           = "Low-3-sistr"

PROJECT_NUMBER         = "0.01"

OUTPUT_DIRECTORY       = doc/

OUTPUT_LANGUAGE        = Chinese

BRIEF_MEMBER_DESC      = YES

REPEAT_BRIEF           = YES

ALWAYS_DETAILED_SEC    = YES

FULL_PATH_NAMES        = YES

OPTIMIZE_OUTPUT_FOR_C  = YES

MARKDOWN_SUPPORT       = YES

AUTOLINK_SUPPORT       = YES

IDL_PROPERTY_SUPPORT   = YES

TYPEDEF_HIDES_STRUCT   = YES

LOOKUP_CACHE_SIZE      = 0

EXTRACT_ALL            = YES

EXTRACT_PRIVATE        = YES

EXTRACT_STATIC         = YES

EXTRACT_LOCAL_CLASSES  = YES

CASE_SENSE_NAMES       = YES

SHOW_INCLUDE_FILES     = YES

INLINE_INFO            = YES

SORT_MEMBER_DOCS       = YES

GENERATE_TODOLIST      = YES

GENERATE_TESTLIST      = YES

GENERATE_BUGLIST       = YES

GENERATE_DEPRECATEDLIST= YES

MAX_INITIALIZER_LINES  = 30

SHOW_USED_FILES        = YES

SHOW_FILES             = YES

SHOW_NAMESPACES        = YES

INPUT                  = /home/AndiGu

INPUT_ENCODING         = UTF-8

FILE_PATTERNS          = *.c *.cpp *.java *.h

RECURSIVE              = YES

SOURCE_BROWSER         = YES

STRIP_CODE_COMMENTS    = YES

REFERENCED_BY_RELATION = YES

REFERENCES_RELATION    = YES

REFERENCES_LINK_SOURCE = YES

SOURCE_TOOLTIPS        = YES

VERBATIM_HEADERS       = YES

ALPHABETICAL_INDEX     = YES

COLS_IN_ALPHA_INDEX    = 5

GENERATE_HTML          = YES

ENUM_VALUES_PER_LINE   = 4

TREEVIEW_WIDTH         = 250

FORMULA_FONTSIZE       = 10

FORMULA_TRANSPARENT    = YES

MATHJAX_FORMAT         = HTML-CSS

SEARCHENGINE           = YES

GENERATE_LATEX         = YES

LATEX_OUTPUT           = latex

LATEX_CMD_NAME         = latex

MAKEINDEX_CMD_NAME     = makeindex

PAPER_TYPE             = a4

PDF_HYPERLINKS         = YES

USE_PDFLATEX           = YES

LATEX_BIB_STYLE        = plain

RTF_OUTPUT             = rtf

MAN_OUTPUT             = man

MAN_EXTENSION          = .3

XML_OUTPUT             = xml

XML_PROGRAMLISTING     = YES

DOCBOOK_OUTPUT         = docbook

PERLMOD_PRETTY         = YES

ENABLE_PREPROCESSING   = YES

SEARCH_INCLUDES        = YES

CLASS_DIAGRAMS         = YES

HIDE_UNDOC_RELATIONS   = YES

DOT_NUM_THREADS        = 0

DOT_FONTSIZE           = 10

CLASS_GRAPH            = YES

COLLABORATION_GRAPH    = YES

GROUP_GRAPHS           = YES

UML_LOOK               = YES

UML_LIMIT_NUM_FIELDS   = 10

INCLUDE_GRAPH          = YES

INCLUDED_BY_GRAPH      = YES

CALL_GRAPH             = YES

CALLER_GRAPH           = YES

GRAPHICAL_HIERARCHY    = YES

DIRECTORY_GRAPH        = YES

INTERACTIVE_SVG        = YES

MAX_DOT_GRAPH_DEPTH    = 8

 

3. 文档生成

 

然后进入上面配置文件设置的INPUT目录,执行“doxygen", 命令执行完成之后,在output制定的目录里面 就可以看到生产了html目录和latex目录。如果需要用HTML看整个代码,可以在IE或者firefox浏览器中打开annotated.html,可以看到所有的代码结构和注释。

 

wKiom1nEnn6jUBBHAADM8HStLOc172.png


 















本文转自存储之厨51CTO博客,原文链接:http://blog.51cto.com/xiamachao/1967738 ,如需转载请自行联系原作者



网友评论

登录后评论
0/500
评论
技术小甜
+ 关注