source insight 宏 添加函数注释
来源:互联网 发布:yii2返回json 编辑:程序博客网 时间:2024/06/10 03:55
无意中发现source insight有宏信息,具体的编码规则可以在 source insight下面按 F1,查看Macro Language Guide进行参考,查阅
此版本是基于source insight内部的base工程,也参考了网上的资料
主要就是解析字符串,使用了 strmid() strtrunc()函数来裁剪字符串
在此记录一下...
/*-------------------------------------------------------------------------
I N S E R T H E A D E R
Inserts a comment header block at the top of the current function.
This actually works on any type of symbol, not just functions.
To use this, define an environment variable "MYNAME" and set it
to your email name. eg. set MYNAME=raygr
-------------------------------------------------------------------------*/
macro AddFuncHeader()
{
hSysBuf = OpenBuf( "system.ini" ) // 打开当前工程下面的配置文件,有版本号及作者的信息
if( hSysBuf == hNil ){
return 1
}
// 一行行读取配置文件信息
szMyName = GetBufLine( hSysBuf, 0 ) // 著者
szVersion = GetBufLine( hSysBuf, 1 ) // 软件版本号
SysTime = GetSysTime( 0 )
year = SysTime.Year
month = SysTime.Month
day = SysTime.Day
hour = SysTime.Hour + 8
minute= SysTime.Minute
// Get a handle to the current file buffer and the name
// and location of the current symbol where the cursor is.
hbuf = GetCurrentBuf()
if( hbuf == hNil ){
return 1
}
ln = GetBufLnCur( hbuf )
totalLine = 0
tmpLine = ln +1
i = 0;
find_flag = 0 // 该表示用来表示是否找到 "{",从而判断是否可以开始解析字符
/*
* 分两步来添加函数的注释
* 1. 获取函数名字
* 2. 获取函数参数
*/
funcContent = " " // 初始化函数的所有注释信息为空
while ( totalLine < 20 ) // 防止函数名跨越的行数太长
{
// 1. 逐行获取数据
tmpLineContent = GetBufLine( hbuf, tmpLine )
tmpLineLen = GetBufLineLength( hbuf, tmpLine)
tmpIndex = 0
// 遍历 该句来判断是否有 "{"存在,有则证明函数头已包含在缓冲数据中
while ( tmpIndex < tmpLineLen )
{
if ( "{" == tmpLineContent[tmpIndex] )
{
find_flag = 1;
break;
}
tmpIndex = tmpIndex + 1
}
// 说明该行函数仍未结束,添加改行信息到总的信息后面
funcContent = cat ( funcContent, tmpLineContent )
if ( find_flag == 1 )
{
break;
}
totalLine = totalLine + 1
tmpLine = tmpLine +1
}
// InsBufLine( hbuf, ln ++, "/**\@all @funcContent@" )
// 找到所有需要的字符信息之后,开始找出函数名出来,只需要从 "("处断开即可
indexLeft = 0;
while ( (funcContent[indexLeft]) != "(" )
{
indexLeft = indexLeft +1
}
funName = strtrunc(funcContent, indexLeft)
InsBufLine( hbuf, ln ++, "/* Function @funName@()" )
InsBufLine( hbuf, ln ++, " * Description " )
//InsBufLine( hbuf, ln ++, "/**\@param @funcContent@" )
// 再找到右括号 ")"的位置
indexRight = 0
while ( (funcContent[indexRight]) != ")" )
{
indexRight = indexRight + 1
}
// 接下去解析函数内部的参数
index = 0
paramEnd = 0
paramStr = " "
index = indexLeft + 1 // 跳过 左括号 "("
while ( index <= indexRight )
{
paramEnd = index
if ( (funcContent[index] == ",") || (funcContent[index] == ")") ) // 说明一个参数结束
{
// 再往前找到的字符为 空格" ","*" , "&",则说明是参数的起始位置
index = index -1
while ( index > indexLeft )
{
if ( ( funcContent[index] == " " )
|| ( funcContent[index] == "*" )
|| ( funcContent[index] == "&" )
)
{
paramStr = strmid(funcContent, index+1, paramEnd)
InsBufLine( hbuf, ln ++, " * param[in] @paramStr@ :" )
break;
}
else
{
index = index -1
}
}
}
index = paramEnd + 1
}
InsBufLine( hbuf, ln++, " * return " )
InsBufLine( hbuf, ln++, " * modify @szMyName@ @szVersion@ @year@-@month@-@day@ @hour@:@minute@ " )
// 注释结束
InsBufLine( hbuf, ln++, " */" )
// put the insertion point inside the header comment
SetBufIns( hbuf, ln, 10 )
CloseBuf( hSysBuf )
}
通过类似的方式还可以添加文件头,结构体等注释,提高代码的可读性...
- source insight 宏 添加函数注释
- Source Insight 注释快捷键的宏添加
- source insight 自动注释函数宏
- source insight 添加注释快捷方式
- Source Insight添加快键键注释
- source insight 添加注释,添加环境变
- 给Source Insight添加块注释宏、全部选择宏
- 利用Source Insight宏语言脚本添加注释
- 利用Source Insight宏语言脚本添加注释
- 利用Source Insight宏语言脚本添加注释
- Source Insight中快速添加注释
- 给source insight添加doxygen注释风格
- Source Insight 宏-单行注释
- Source Insight 批量注释宏
- source insight增加注释宏
- source insight 添加宏定义
- source insight 头文件注释与函数注释
- Source Insight 宏-多行注释
- 广西一警局大队长办公室自缢
- 编写一个程序,实现二叉树的各种运算
- 嵌入式经典面试题
- 技术三事
- 求fibnacci序列的第20项。
- source insight 宏 添加函数注释
- 深入理解TCP/IP协议栈之TCP协议(TCP报文格式+三次握手+四次挥手实例)
- 几个有意思的算法题
- IOS Block(块)编程初步
- CentOS 6.0 tftp服务安装与配置,
- Python--中文乱码
- linux内核数据结构以及内核调试
- 排序二叉树和红黑树
- JS判断页面是否出现滚动条