在source insight 的工程文件中,即以em为后缀的文件中增加如下宏:
macro InsertHeader()
{
/* 获取光标所在行 */
handle = GetCurrentWnd()
process_line = GetWndSelLnFirst(handle)
/* 获取函数所在行文本 */
file_txt = GetCurrentBuf()
process_txt = GetBufLine(file_txt,process_line + 1)
process_txt_len = strlen(process_txt)
if(process_txt == "")
{
stop
}
/* 获取函数名 */
symbol_rec = GetSymbolLocationFromLn (handle, process_line + 1)
if(symbol_rec == "")
{
stop
}
fuction_name = symbol_rec.Symbol
/* 获取参数个数及参数名 */
param_num = 0
param_list = SymListNew()
i=0,j=0
while(i < process_txt_len)
{
if(process_txt[i] == "," || process_txt[i] == ")")
{
j = i
while(j > 0)
{
if(process_txt[j] == " " || process_txt[j] == "*" || process_txt[j] == "&" ||
process_txt[j] == "(")
{
symbol_rec.Symbol = strmid(process_txt,j+1,i)
SymListInsert(param_list,param_num,symbol_rec)
param_num = param_num + 1
break;
}
j = j - 1
}
}
i = i + 1
}
/* 输出注释 */
PutBufLine(handle,process_line + 0,"/** ")
var temp_buffer
temp_buffer = cat(" * [",fuction_name)
temp_buffer = cat(temp_buffer," description]")
InsBufLine(handle,process_line + 1,temp_buffer)
InsBufLine(handle,process_line + 2," * \@Author xxx")
sys_time = GetSysTime(1)
temp_buffer = " * \@DateTime "
temp_buffer = cat(temp_buffer,sys_time.date)
temp_buffer = cat(temp_buffer,"T")
temp_buffer = cat(temp_buffer,sys_time.time)
temp_buffer = cat(temp_buffer,"+0800")
InsBufLine(handle,process_line + 3,temp_buffer)
param_line = process_line + 4
InsBufLine(handle,param_line," */")
if(strmid(process_txt,0,4) != "void")
{
InsBufLine(handle,param_line," * \@return [description]")
}
while(param_num > 0)
{
param_num = param_num - 1
symbol_rec = SymListItem(param_list,param_num)
temp_buffer = " * \@param "
temp_buffer = cat(temp_buffer,symbol_rec.Symbol)
temp_buffer_len = strlen(temp_buffer)
temp_buffer_len = 38 - temp_buffer_len
while(temp_buffer_len > 0)
{
temp_buffer_len = temp_buffer_len - 1
temp_buffer = cat(temp_buffer," ")
}
temp_buffer = cat(temp_buffer,"[description]")
InsBufLine(handle,param_line,temp_buffer)
}
SymListFree(param_list)
}
效果如下:
/**
* [Work.RemoveWatcher description]
* @Author xxx
* @DateTime 2021年2月21日T17:25:54+0800
* @param pWatcher [description]
* @return [description]
*/
int RemoveWatcher(WatcherSubscriber *pWatcher)
{
list<WatcherSubscriber*>::iterator it;
for(it = mWatcher.begin();it!= mWatcher.end();it++)
{
if(pWatcher == *it)
{
mWatcher.remove(pWatcher);
break;
}
}
}