1. 程式人生 > >Doxygen生成美麗註釋文件(1):初體驗

Doxygen生成美麗註釋文件(1):初體驗

Hello Doxygen

[TOC]

Chapter 1 - 準備工作 (Windows環境)

1.1 程式包下載

  1. Doxygen
  1. HTML Help Workshop

用於生成CHM檔案,便於傳播和檢視。

Htmlhelp.exe

  1. Graphviz

用於繪製DOT語言標本描述的圖形。Doxygen 使用 graphviz 自動生成類之間和檔案之間的呼叫關係圖。

  1. Sublime + DoxyDoxygen 外掛

1.2 安裝教程

Chapter 2 - 初嘗 Doxygen

2.1 為原始碼生成文件大致分為兩個步驟:

  1. 為原始碼編寫符合 doxygen 要求的註釋

  2. 使用 doxygenwizard 生成文件

2.2 編寫 Doxygen 註釋

/**< 標準輸入輸出標頭檔案 */
#include <stdio.h>

/**
 * @brief      { Calculate the sum of two doubles }
 *
 * This function will return the sum of two doubles
 *
 * @param[in]  a     { the first number }
 * @param[in]  b     { the second number }
 *
 * @return  double   {  the sum of a and b  }
 */
double add(double a,double b) { return a+b; } /** * @brief { Calculate the different of two doubles } * * This function will return the different of two doubles * * @param[in] a { the first number } * @param[in] b { the second number } * * @return double { the different of a and b } */ double subtract(double a,double b) { return a-b; } /** * @brief { Calculate the product of two doubles } * * This function will return the product of two doubles * * @param[in] a { the first number } * @param[in] b { the second number } * * @return double { the product of a and b } */ double multiply(double a,double b) { return a*b; } /** * @brief { Calculate the quotient of two doubles } * * This function will return the quotient of two doubles * * @param[in] a { the first number } * @param[in] b { the second number } * * @return double { the quotient of a and b } */ double divide(double a,double b) { return a/b; } /** * @brief { This is the main function } * * This function is the main function. * It will print something in the screen. * * @return int { The exit code. } */ int main(void) { int a = 5,b = 6; printf("%lf\n",add(a,b)); printf("%lf\n",subtract(a,b)); printf("%lf\n",multiply(a,b)); printf("%lf\n",divide(a,b)); return 0; }

Doxygen 命令規範文件:官網

2.3 使用 Doxygen 生成文件

步驟:

  1. 開啟 doxywizard
  2. 設定工作目錄、專案名稱、原始檔目錄、生成文件的目錄等
  3. 設定註釋抽取的模式、語言種類
  4. 設定輸出格式
  5. 設定如何輸出圖表
  6. 生成文件