python 使用CppHeaderParser库 根据c++头文件生成html说明文档表格

‘‘‘
/**
* @brief                设置NTP开关
* @param[in]    hHandle      对应设备的有效句柄
* @param[in]    fEnable          NTP服务开关 0:关闭,1:打开
* @return               成功:S_OK;失败:E_FAIL  传入参数异常:S_FALSE
*/
HV_API_EX HRESULT CDECL HVAPI_SetNTPEnable(HVAPI_HANDLE_EX hHandle, BOOL fEnable );
效果图



‘‘‘


#!/usr/bin/python
#coding=GBK
import sys
sys.path = ["../"] + sys.path
import CppHeaderParser
import re
try:
    cppHeader = CppHeaderParser.CppHeader("e:\test.h")
except CppHeaderParser.CppParseError,  e:
    print e
    sys.exit(1)

#print "CppHeaderParser view of %s"%cppHeader


htmlfilebegin = r‘<html><body>‘
htmlfileend = r‘</body></html>‘

head = r‘<h3>%s</h3><table border="1" cellspacing="0" cellpadding="0" width="643">‘\
r‘    <tr>‘\
r‘      <td width="87"><p><strong>函数名称 </strong></p></td>‘\
r‘      <td width="480" colspan="2"><p>%s</p></td>‘\
r‘    </tr>‘\
r‘    <tr>‘\
r‘      <td width="87"><p><strong>功能描述 </strong></p></td>‘\
r‘      <td width="480" colspan="2"><p>%s</p></td>‘\
r‘    </tr>‘\
r‘    <tr>‘

canshu = r‘   <tr>‘\
r‘      <td width="73" rowspan="%d"><p><strong>参数说明 </strong></p></td>‘\
r‘      <td width="106"><p>%s</p></td>‘\
r‘      <td width="388"><p>%s</p></td>‘\
r‘    </tr>‘

unit = r‘    <tr>‘\
r‘      <td width="106"><p>%s</p></td>‘\
r‘      <td width="388"><p>%s</p></td>‘\
r‘    </tr>‘

tailtableend = r‘</table>‘

tail=r‘<tr><td width="87" rowspan="2"><p><strong>返回值</strong></p></td><td width="132"><p>S_OK</p></td><td width="348"><p>成功</p></td></tr><tr><td width="132"><p>E_FAIL</p></td><td width="348"><p>失败</p></td></tr></table>‘

tailAdv=r‘<tr><td width="87" rowspan="3"><p><strong>返回值</strong></p></td><td width="132"><p>S_OK</p></td><td width="348"><p>成功</p></td></tr><tr><td width="132"><p>E_FAIL</p></td><td width="348"><p>失败</p></td></tr> <tr><td width="132"><p>S_FALSE</p></td><td width="348"><p>传入参数异常</p></td></tr> </table>‘


print "\nFree functions are:"

file= open("t.html", ‘w+‘)
file.write(htmlfilebegin)
for func in cppHeader.functions:
     strbrief =  re.findall(r"brief(.+?)"+"\n",  func["doxygen"])
     file.write( head %(func["name"], func["debug"], strbrief[0])   )
    
     params = func["parameters"]
     count = len(params)
    
     if 1 <= count:
          ParamDiscr = re.findall(params[0]["name"]+r"(.+?)"+"\n", func["doxygen"])
          file.write(  canshu %(count, params[0]["name"],  ParamDiscr[0] )   )
          for i in range(1, count):
               print params[i]["name"]
               ParamDiscr = re.findall(params[i]["name"]+r"(.+?)"+"\n", func["doxygen"])
               file.write(  unit %(params[i]["name"], ParamDiscr[0])  )         
         
          if ( -1 == func["doxygen"].find(‘S_FALSE‘)):
               file.write(  tail  )
          else:
               file.write( tailAdv )
          file.write( tailtableend )
          file.write(  "<br>"  )

file.write(htmlfileend)
file.close()


python 使用CppHeaderParser库 根据c++头文件生成html说明文档表格,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。