在写程序的时候有时候需要添加函数注释或者头文件注释,在source insight中可以通过宏定义快捷键一键添加注释模板。但是需要添加环境变量,这里一开始没有明白是什么意思,后来搜索到了。添加环境变量:就是在我们电脑里设置环境变量,之所以要添加是因为source insight 注释中要提取名字。这里是两个函数:
添加函数注释:
macro MyInsertHeader() { // Get the owner's name from the environment variable: MYNAME. // If the variable doesn't exist, then the owner field is skipped. szMyName = getenv(MYNAME) // Get a handle to the current file buffer and the name // and location of the current symbol where the cursor is. hbuf = GetCurrentBuf() szFunc = GetCurSymbol() ln = GetSymbolLine(szFunc) InsBufLine(hbuf, ln, "/************************************************************"); ln = ln +1 // begin assembling the title string sz = "** 函数名称: " /* convert symbol name to T E X T L I K E T H I S */ cch = strlen(szFunc) ich = 0 while (ich < cch) { ch = szFunc[ich] if (ich > 0) if (isupper(ch)) sz = cat(sz, " ") else sz = cat(sz, " ") sz = Cat(sz, toupper(ch)) ich = ich + 1 } InsBufLine(hbuf, ln, sz) ln = ln + 1 InsBufLine(hbuf, ln, "** 功能描述: ") ln = ln + 1 InsBufLine(hbuf, ln, "** 输入参数:") ln = ln + 1 InsBufLine(hbuf, ln, "** 输出参数: ") ln = ln + 1 InsBufLine(hbuf, ln, "** 返 回 值 :") ln = ln + 1 /* if owner variable exists, insert Owner: name */ if (strlen(szMyName) > 0) { InsBufLine(hbuf, ln, "** 作 者 : @szMyName@") } else { InsBufLine(hbuf, ln, "** 作 者 : ") } ln = ln + 1 // Get current time szTime = GetSysTime(1) Day = szTime.Day Month = szTime.Month Year = szTime.Year if (Day < 10) szDay = "0@Day@" else szDay = Day InsBufLine(hbuf, ln, "** 日 期 : @Year@年@Month@月@szDay@日") ln = ln + 1 InsBufLine(hbuf, ln, "** 版 本 : 1.0") ln = ln + 1 InsBufLine(hbuf, ln, "** 修改日期 版本号 修改人 修改内容") ln = ln + 1 InsBufLine(hbuf, ln, "**************************************************************/") }
以下是添加头文件注释宏:
macro MyInsertFileHeader() { szMyName = getenv(MYNAME) hbuf = GetCurrentBuf() InsBufLine(hbuf, 0, "/***************************************************************************") InsBufLine(hbuf, 1, "** 版权所有: Desay Copyright (c) 2016-2026 ******************** ") filename = GetBufName(hbuf) InsBufLine(hbuf, 2, "** 文件名称: @filename@") InsBufLine(hbuf, 3, "** 文件标识: ") InsBufLine(hbuf, 4, "** 内容摘要: ") InsBufLine(hbuf, 5, "** 当前版本: v1.0") /* if owner variable exists, insert Owner: name */ if (strlen(szMyName) > 0) { sz = "** 作 者 : @szMyName@" } else { sz = "** 作 者 :" } InsBufLine(hbuf, 6, sz) // Get current time szTime = GetSysTime(1) Day = szTime.Day Month = szTime.Month Year = szTime.Year if (Day < 10) szDay = "0@Day@" else szDay = Day InsBufLine(hbuf, 7, "** 完成日期: @Year@年@Month@月@szDay@日") InsBufLine(hbuf, 8, "** 修改记录: ") InsBufLine(hbuf, 9, "** 修改记录: ") InsBufLine(hbuf, 10, "** 修改日期: ") InsBufLine(hbuf, 11, "** 版本号 : ") InsBufLine(hbuf, 12, "** 修改人 : ") InsBufLine(hbuf, 13, "** 修改内容: ") InsBufLine(hbuf, 14, "***************************************************************************/") }
以上添加完就可以配置快捷方式,具体操作方式看另一篇文章就可以了。
添加环境变量:计算机->右键属性->(左上角)高级系统设置->环境变量->(在用户环境变量中)新建->变量名:MYNAME,变量值:XXX(你的名字)
需要注意:
1、设置完成环境变量后,需要重启source insight ,以上配置才起作用,至少我的电脑是这样的。
2、环境变量的具体位置,不同系统可能不同,我是w7,具体根据自己的实际系统找到即可。
3、添加函数注释的时候首先要先写出函数的名字,再用快捷键添加函数注释,不然不报错。