posts - 45,  comments - 232,  trackbacks - 0

最近在为文档的书写苦恼,本来想自己写一个文档解析程序,名字都想好了。后来竟然在找资料的过程中发现了一个很好的C/C++ java文档生成器Doxygen,真是无心插柳柳成行,我的原则是不要重复发明车轮,所以就是用这个开源的项目。给大家一些学习的链接看看,很容易入门的。
http://www.cppblog.com/richardzeng/archive/2006/03/23/4508.html
http://www.chinaitpower.com/A/2003-01-19/47536.html
如果你要看全面的介绍文档,可以在它的主页去看:http://www.stack.nl/~dimitri/doxygen/,不过都是英文的。
问题:我的一个C文档的注释在Eclipse里面是中文写的,所以编码格式为utf-8。无论我Doxygen改成english或者chinese都没有办法正确显示。我查看了生成的html的编码竟然不是utf-8编码,我想解决的办法就是要自己来定义生成的html文档。
高兴,Show我生成的文档。下面是C语言写得一个函数

/* *
*@brief read string in initialization file
*
*retrieves a string from the specified section in an initialization file
*@param section [name of the section containing the key name]
*@param key [name of the section containing the key name]
*@param value [pointer to the buffer that receives the retrieved string]
*@param size [size of value buffer]
*@param file [name of the initialization file]
*@return [1 : read success; 0 : read fail]
*/
int  read_profile_string(  const   char   * section,  const   char   * key, char   * value,   int  size,  const   char   * file)
{
    
char  buf[MAX_FILE_SIZE] = { 0 };
    
int  file_size;
    
int  sec_s,sec_e,key_s,key_e, value_s, value_e;

    
// check parameters
    assert(section  !=  NULL  &&  strlen(section));
    assert(key 
!=  NULL  &&  strlen(key));
    assert(value 
!=  NULL);
    assert(size 
>   0 );
    assert(file 
!= NULL  && strlen(key));

    
if ! load_ini_file(file,buf, & file_size))
        
return   0 ;

    
if ( ! parse_file(section,key,buf, & sec_s, & sec_e, & key_s, & key_e, & value_s, & value_e))
    {
        
return   0 // not find the key
    }
    
else
    {
        
int  cpcount  =  value_e  - value_s;

        
if ( size - 1   <  cpcount)
        {
            cpcount 
=   size - 1 ;
        }
    
        memset(value, 
0 , size);
        memcpy(value,buf
+ value_s, cpcount );
        value[cpcount] 
=   ' \0 ' ;

        
return   1 ;
    }
}

生成的HTML文档如下:

函数文档

int read_profile_string (const char * section,
const char * key,
char * value,
int size,
const char * file 
)

read string in initialization file

retrieves a string from the specified section in an initialization file

参数:
section [name of the section containing the key name]
key [name of the section containing the key name]
value [pointer to the buffer that receives the retrieved string]
size [size of value buffer]
file [name of the initialization file]
返回:
[1 : read success; 0 : read fail]
posted on 2007-01-16 13:41 天下无双 阅读(2842) 评论(4)  编辑 收藏 引用 所属分类: C/C++

FeedBack:
# 找到一个解决utf-8的方法
2007-01-16 16:22 | 天下无双

> Hi,
> does doxygen support unicode comments? If so, are there any options I
> should enable to get this working?

By default iso-8859-1 is used. It depends on what encoding you are
using. It seems like if you encode as UTF-8 things works nice. Note
that the MS-world often use the word unicode to mean unicode
encoded as UCS-2 or UTF-16. Both of these encodings have deficiencies;
UCS-2 does not cover all unicode code-points, UTF-16 is not
endianess-neutral. UTF-8 does not have any of these problems.

To make it work, you have to supply your own HTML_HEADER that creates
HTML tag like this
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">

Feature Request:
It would be nice if the encoding could be supplied as a paremter, so
you don't have to supply your own header just to change encoding.

Jarl

  回复  更多评论
  
# re: Doxygen-C/C++ java文档生成器入门心得
# re: Doxygen-C/C++ java文档生成器入门心得
2007-08-16 17:29 | 天下无双
关于源文件是utf-8的问题我找到了解决的办法。通过doxywizard 把文档的语言配置成中文,然后把utf-8的源文件通过iconv转化为gb2312,然后运行doxygen就可以了。如果有多个文件,可能需要写一个脚本来执行这些机械的人物,不过都应该很简单。  回复  更多评论
  
# re: Doxygen-C/C++ java文档生成器入门心得
2007-08-17 10:52 | 天下无双
下面是我为一个工程写的转化utf-8到GB2312的BASH脚本(由于是C语言,只针对.h .c文件进行转化:
#!/bin/bash
#(C)2007 GEC written by Deng Yangjun
DOXY_DIR="doxygen/"

echo "convert *.h *.c form UTF-8 to GB2312"
for f in *.[hc]
do
echo $f" -> "$DOXY_DIR$f
iconv -s -f utf-8 -t gb2312 $f > $DOXY_DIR$f
done
cd $DOXY_DIR
echo "build doxygen..."
doxygen 1>/dev/null
echo "OK"  回复  更多评论
  

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



常用链接

留言簿(15)

随笔分类

随笔档案

相册

我的其它领域Blog

搜索

  •  

积分与排名

  • 积分 - 202678
  • 排名 - 128

最新评论

阅读排行榜

评论排行榜