sourceinsight 宏管理1

/* Utils.em - a small collection of useful editing macros */

/*-------------------------------------------------------------------------
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 InsertHeader()
{
// 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)

// 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
    }

sz = Cat(sz, "   */")
InsBufLine(hbuf, ln, sz)
InsBufLine(hbuf, ln+1, "/*-------------------------------------------------------------------------")

/* if owner variable exists, insert Owner: name */
if (strlen(szMyName) > 0)
    {
    InsBufLine(hbuf, ln+2, "    Owner: @szMyName@")
    InsBufLine(hbuf, ln+3, " ")
    ln = ln + 4
    }
else
    ln = ln + 2

InsBufLine(hbuf, ln,   "    ") // provide an indent already
InsBufLine(hbuf, ln+1, "-------------------------------------------------------------------------*/")

// put the insertion point inside the header comment
SetBufIns(hbuf, ln, 4)

}

/* InsertFileHeader:

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 InsertFileHeader()
{
MyName = GetMyName()
C_Time = GetSysTime(1)
Year = C_Time.Year
E_Year = Year + 1
Date = GetDateTime(0)
MyFilename = GetFileName(GetBufName(GetCurrentBuf()))

hbuf = GetCurrentBuf()
InsBufLine(hbuf, 0,  "/*********************************************************************")
InsBufLine(hbuf, 1,  " * 版权所有: Copyright (c) @Year@-@E_Year@  Company. All rights reserved.")
InsBufLine(hbuf, 2,  " * 系统名称: ")
InsBufLine(hbuf, 3,  " * 文件名称: @MyFilename@")
InsBufLine(hbuf, 4,  " * 内容摘要: ")
InsBufLine(hbuf, 5,  " * 当前版本: ")
InsBufLine(hbuf, 6,  " * 作    者: @MyName@")
InsBufLine(hbuf, 7,  " * 设计日期: @Date@")
InsBufLine(hbuf, 8,  " * 修改记录: ")
InsBufLine(hbuf, 9,  " * 修改日期          版本          修改人          修改摘要")
InsBufLine(hbuf, 10, " * xxxx-xx-xx         xx             xxx             xxxxxxx")
InsBufLine(hbuf, 11, "**********************************************************************/")
InsBufLine(hbuf, 12, "")
InsBufLine(hbuf, 13, "")
InsBufLine(hbuf, 14, "")
InsBufLine(hbuf, 15, "")

SetBufIns(hbuf, 2, 20)}

// Inserts “Returns True … or False…” at the current line
macro ReturnTrueOrFalse()
{
hbuf = GetCurrentBuf()
ln = GetBufLineCur(hbuf)

InsBufLine(hbuf, ln, "    Returns True if successful or False if errors.")

}

/* Inserts ifdef REVIEW around the selection */
macro IfdefReview()
{
IfdefSz(“REVIEW”);
}

/* Inserts ifdef BOGUS around the selection */
macro IfdefBogus()
{
IfdefSz(“BOGUS”);
}

/* Inserts ifdef NEVER around the selection */
macro IfdefNever()
{
IfdefSz(“NEVER”);
}

// Ask user for ifdef condition and wrap it around current
// selection.
macro InsertIfdef()
{
sz = Ask(“Enter ifdef condition:”)
if (sz != “”)
IfdefSz(sz);
}

macro InsertCPlusPlus()
{
IfdefSz("__cplusplus");
}

// Wrap ifdef … endif around the current selection
macro IfdefSz(sz)
{
hwnd = GetCurrentWnd()
lnFirst = GetWndSelLnFirst(hwnd)
lnLast = GetWndSelLnLast(hwnd)

hbuf = GetCurrentBuf()
InsBufLine(hbuf, lnFirst, "#ifdef @sz@")
InsBufLine(hbuf, lnLast+2, "#endif /* @sz@ */")

}

// Delete the current line and appends it to the clipboard buffer
macro KillLine()
{
hbufCur = GetCurrentBuf();
lnCur = GetBufLnCur(hbufCur)
hbufClip = GetBufHandle(“Clipboard”)
AppendBufLine(hbufClip, GetBufLine(hbufCur, lnCur))
DelBufLine(hbufCur, lnCur)
}

// Paste lines killed with KillLine (clipboard is emptied)
macro PasteKillLine()
{
Paste
EmptyBuf(GetBufHandle(“Clipboard”))
}

// delete all lines in the buffer
macro EmptyBuf(hbuf)
{
lnMax = GetBufLineCount(hbuf)
while (lnMax > 0)
{
DelBufLine(hbuf, 0)
lnMax = lnMax - 1
}
}

// Ask the user for a symbol name, then jump to its declaration
macro JumpAnywhere()
{
symbol = Ask(“What declaration would you like to see?”)
JumpToSymbolDef(symbol)
}

// list all siblings of a user specified symbol
// A sibling is any other symbol declared in the same file.
macro OutputSiblingSymbols()
{
symbol = Ask(“What symbol would you like to list siblings for?”)
hbuf = ListAllSiblings(symbol)
SetCurrentBuf(hbuf)
}

// Given a symbol name, open the file its declared in and
// create a new output buffer listing all of the symbols declared
// in that file. Returns the new buffer handle.
macro ListAllSiblings(symbol)
{
loc = GetSymbolLocation(symbol)
if (loc == “”)
{
msg ("@symbol@ not found.")
stop
}

hbufOutput = NewBuf("Results")

hbuf = OpenBuf(loc.file)
if (hbuf == 0)
    {
    msg ("Can't open file.")
    stop
    }
    
isymMax = GetBufSymCount(hbuf)
isym = 0;
while (isym < isymMax)
    {
    AppendBufLine(hbufOutput, GetBufSymName(hbuf, isym))
    isym = isym + 1
    }

CloseBuf(hbuf)

return hbufOutput

}

//多行注释
macro MultiLineComment()
{
hwnd = GetCurrentWnd()
selection = GetWndSel(hwnd)
LnFirst = GetWndSelLnFirst(hwnd) //取首行行号
LnLast = GetWndSelLnLast(hwnd) //取末行行号
hbuf = GetCurrentBuf()

if(GetBufLine(hbuf, 0) == "//magic-number:tph85666031"){
    stop
}

Ln = Lnfirst
buf = GetBufLine(hbuf, Ln)
len = strlen(buf)

while(Ln <= Lnlast) {
    buf = GetBufLine(hbuf, Ln)  //取Ln对应的行
    if(buf == ""){                    //跳过空行
        Ln = Ln + 1
        continue
    }

    if(StrMid(buf, 0, 1) == "/") {       //需要取消注释,防止只有单字符的行
        if(StrMid(buf, 1, 2) == "/"){
            PutBufLine(hbuf, Ln, StrMid(buf, 2, Strlen(buf)))
        }
    }

    if(StrMid(buf,0,1) != "/"){          //需要添加注释
        PutBufLine(hbuf, Ln, Cat("//", buf))
    }
    Ln = Ln + 1
}

SetWndSel(hwnd, selection)

}

//添加“#ifdef 0”和“#endif”的宏代码
macro AddMacroComment()
{
hwnd = GetCurrentWnd();
sel = GetWndSel ( hwnd );
lnFirst = GetWndSelLnFirst ( hwnd );
lnLast = GetWndSelLnLast ( hwnd );
hbuf = GetCurrentBuf();

if ( LnFirst == 0 )
{
    szIfStart = "";
}
else
{
    szIfStart = GetBufLine ( hbuf, LnFirst - 1 );
}

szIfEnd = GetBufLine ( hbuf, lnLast + 1 );

if ( szIfStart == "#if 0" && szIfEnd == "#endif" )
{
    DelBufLine ( hbuf, lnLast + 1 );
    DelBufLine ( hbuf, lnFirst - 1 );
    //sel.lnFirst = sel.lnFirst + 1;
    //sel.lnLast = sel.lnLast + 1;
}
else
{
    InsBufLine ( hbuf, lnFirst, "#if 0" );
    InsBufLine ( hbuf, lnLast + 2, "#endif" );
    sel.lnFirst = sel.lnFirst + 1;
    sel.lnLast = sel.lnLast + 1;
}

SetWndSel ( hwnd, sel );

}

//把光标所在的行注释掉
macro CommentSingleLine()
{
hbuf = GetCurrentBuf()
ln = GetBufLnCur(hbuf)
str = GetBufLine (hbuf, ln)
str = cat("/",str)
str = cat(str,"
/")
PutBufLine (hbuf, ln, str)
}

//将一行中鼠标选中部分注释掉

macro CommentSelStr()
{
hbuf = GetCurrentBuf()
ln = GetBufLnCur(hbuf)
str = GetBufSelText(hbuf)
str = cat("/",str)
str = cat(str,"
/")
SetBufSelText (hbuf, str)
}

//获取自己的Name
macro GetMyName()
{
return “zhp”
}

//格式化日期时间,就是补0
macro FormatNum(Num)
{
if (Num < 10)
{
szNum = “0@Num@”;
}
else
{
return Num;
}
return szNum
}

//获取日期
macro GetDate()
{
G_Date = GetSysTime(1)
Year = G_Date.Year
Month = FormatNum(G_Date.Month)
Day = FormatNum(G_Date.Day)

return "@Year@-@Month@-@Day@"

}
//获取日期时间
macro GetDateTime(Flag)
{
G_Time = GetSysTime(1)
Date = GetDate()
Hour = FormatNum(G_Time.Hour)
Minute = FormatNum(G_Time.Minute)

if (Flag)
{
    Second = FormatNum(G_Time.Second)
    return "@Date@ @Hour@:@Minute@:@Second@"
}
else
{
    return "@Date@ @Hour@:@Minute@"
}

}

//获取文件名
macro GetFileName(PathName)
{
nLength = strlen(PathName)
i = nLength - 1
Name = “”
while (i + 1)
{
ch = PathName[i]
if ("\" == “@ch@”)
{
break
}
i = i - 1
}

i = i + 1

while (i < nLength)
{
    Name = cat(Name, PathName[i])
    i = i + 1
}

return Name

}

//获取当前文件路径
macro Flinger_GetPath()
{
hwnd = GetCurrentWnd()
hbuf = GetCurrentBuf()
lnFirst = GetWndSelLnFirst(hwnd)
FilePath = GetBufName(hbuf)

InsBufLine(hbuf, lnFirst + 1, "@FilePath@")

Sel = GetWndSel(hwnd)         //创建一个Selection Record
Sel.LnFirst = lnFirst + 1;    //赋值起始行
Sel.LnLast = lnFirst + 1;     //赋值结束行
Sel.ichFirst = 0;             //赋值选中起始字符
Sel.ichLim = StrLen(FilePath);    //赋值选中结束字符

SetWndSel(hwnd, Sel)    //设置选中

}

macro Lifotronic_InsertFuncHeader()
{
MyName = GetMyName()
Date = GetDateTime(0)
hbuf = GetCurrentBuf()
FunName = GetCurSymbol()
lnFirst = GetSymbolLine(FunName)
if (lnFirst < 0)
{
lnFirst = GetWndSelLnFirst(GetCurrentWnd())
}
InsBufLine(hbuf, lnFirst + 0, “”)
InsBufLine(hbuf, lnFirst + 1, “/")
InsBufLine(hbuf, lnFirst + 2, " * @@brief: “)
InsBufLine(hbuf, lnFirst + 3, " * @@input: None”)
InsBufLine(hbuf, lnFirst + 4, " * @@output: None")
InsBufLine(hbuf, lnFirst + 5, " * @@retval: None")
InsBufLine(hbuf, lnFirst + 6, "
/”)

SetBufIns(hbuf, lnFirst + 2, 13)

}

//函数前插入的信息(光标放在函数名 才可获取到函数名信息 否则报错)
macro Flinger_InsertFuncHeader()
{
MyName = GetMyName()
Date = GetDateTime(0)
hbuf = GetCurrentBuf()
FunName = GetCurSymbol()
lnFirst = GetSymbolLine(FunName)
if (lnFirst < 0)
{
lnFirst = GetWndSelLnFirst(GetCurrentWnd())
}
InsBufLine(hbuf, lnFirst + 0, “”)
InsBufLine(hbuf, lnFirst + 1, “/***********************************************************************”)
InsBufLine(hbuf, lnFirst + 2, " * 函数名称: @FunName@")
InsBufLine(hbuf, lnFirst + 3, " * 作 者: @MyName@")
InsBufLine(hbuf, lnFirst + 4, " * 设计日期: @Date@")
InsBufLine(hbuf, lnFirst + 5, " * 功能描述: “)
InsBufLine(hbuf, lnFirst + 6, " * 参 数: “)
InsBufLine(hbuf, lnFirst + 7, " * 返 回 值: “)
InsBufLine(hbuf, lnFirst + 8, " * 修改日期 修改人 修改内容”)
InsBufLine(hbuf, lnFirst + 9, " * xxxx-xx-xx xxx xxxxxxx”)
InsBufLine(hbuf, lnFirst + 10, " ***********************************************************************/”)

SetBufIns(hbuf, lnFirst + 5, 28)

}

//头文件布局
macro Flinger_InsertHeaderFileLayout()
{
InsertFileHeader()
FileHeaderLine = 15

hbuf = GetCurrentBuf()
InsBufLine(hbuf, 0 +FileHeaderLine, "#ifndef __XXX_H__")
InsBufLine(hbuf, 1 +FileHeaderLine, "#define __XXX_H__")
InsBufLine(hbuf, 2 +FileHeaderLine, "/********************************** 其它条件编译选项 ***********************************/")
InsBufLine(hbuf, 3 +FileHeaderLine, "")
InsBufLine(hbuf, 4 +FileHeaderLine, "")
InsBufLine(hbuf, 5 +FileHeaderLine, "#ifdef __cplusplus")
InsBufLine(hbuf, 6 +FileHeaderLine, "extern \"C\" {")
InsBufLine(hbuf, 7 +FileHeaderLine, "#endif")
InsBufLine(hbuf, 8 +FileHeaderLine, "")
InsBufLine(hbuf, 9 +FileHeaderLine, "")
InsBufLine(hbuf, 10+FileHeaderLine, "/********************************** 标准库头文件 ***********************************/")
InsBufLine(hbuf, 11+FileHeaderLine, "#include <xxx.h>")
InsBufLine(hbuf, 12+FileHeaderLine, "")
InsBufLine(hbuf, 13+FileHeaderLine, "")
InsBufLine(hbuf, 14+FileHeaderLine, "/********************************** 非标准库头文件 ***********************************/")
InsBufLine(hbuf, 15+FileHeaderLine, "#include \"xxx.h\"")
InsBufLine(hbuf, 16+FileHeaderLine, "")
InsBufLine(hbuf, 17+FileHeaderLine, "")
InsBufLine(hbuf, 18+FileHeaderLine, "/********************************** 常量定义 ***********************************/")
InsBufLine(hbuf, 19+FileHeaderLine, "")
InsBufLine(hbuf, 20+FileHeaderLine, "")
InsBufLine(hbuf, 21+FileHeaderLine, "/********************************** 全局宏 ***********************************/")
InsBufLine(hbuf, 22+FileHeaderLine, "")
InsBufLine(hbuf, 23+FileHeaderLine, "")
InsBufLine(hbuf, 24+FileHeaderLine, "/********************************** 数据类型 ***********************************/")
InsBufLine(hbuf, 25+FileHeaderLine, "")
InsBufLine(hbuf, 26+FileHeaderLine, "")
InsBufLine(hbuf, 27+FileHeaderLine, "/********************************** 函数声明 ***********************************/")
InsBufLine(hbuf, 28+FileHeaderLine, "")
InsBufLine(hbuf, 29+FileHeaderLine, "")
InsBufLine(hbuf, 30+FileHeaderLine, "/********************************** 类定义 ***********************************/")
InsBufLine(hbuf, 31+FileHeaderLine, "")
InsBufLine(hbuf, 32+FileHeaderLine, "")
InsBufLine(hbuf, 33+FileHeaderLine, "/********************************** 模板 ***********************************/")
InsBufLine(hbuf, 34+FileHeaderLine, "")
InsBufLine(hbuf, 35+FileHeaderLine, "#ifdef __cplusplus")
InsBufLine(hbuf, 36+FileHeaderLine, "}")
InsBufLine(hbuf, 37+FileHeaderLine, "#endif")
InsBufLine(hbuf, 38+FileHeaderLine, "")
InsBufLine(hbuf, 39+FileHeaderLine, "#endif /* __XXX_H__ */")
InsBufLine(hbuf, 40+FileHeaderLine, "")

SetBufIns(hbuf, 32+FileHeaderLine, 20)

}

//源文件布局
macro Flinger_InsertSourceFileLayout()
{
InsertFileHeader()
FileHeaderLine = 15

hbuf = GetCurrentBuf()
InsBufLine(hbuf, 0 +FileHeaderLine, "/********************************** 标准库头文件 ***********************************/")
InsBufLine(hbuf, 1 +FileHeaderLine, "#include <xxx.h>")
InsBufLine(hbuf, 2 +FileHeaderLine, "")
InsBufLine(hbuf, 3 +FileHeaderLine, "")
InsBufLine(hbuf, 4 +FileHeaderLine, "/********************************** 非标准库头文件 ***********************************/")
InsBufLine(hbuf, 5 +FileHeaderLine, "#include \"xxx.h\"")
InsBufLine(hbuf, 6 +FileHeaderLine, "")
InsBufLine(hbuf, 7 +FileHeaderLine, "")
InsBufLine(hbuf, 8 +FileHeaderLine, "/********************************** 常量定义 ***********************************/")
InsBufLine(hbuf, 9 +FileHeaderLine, "")
InsBufLine(hbuf, 10+FileHeaderLine, "")
InsBufLine(hbuf, 11+FileHeaderLine, "/********************************** 文件内部使用的宏 ***********************************/")
InsBufLine(hbuf, 12+FileHeaderLine, "")
InsBufLine(hbuf, 13+FileHeaderLine, "")
InsBufLine(hbuf, 14+FileHeaderLine, "/********************************** 文件内部使用的数据类型 ***********************************/")
InsBufLine(hbuf, 15+FileHeaderLine, "")
InsBufLine(hbuf, 16+FileHeaderLine, "")
InsBufLine(hbuf, 17+FileHeaderLine, "/********************************** 静态全局变量 ***********************************/")
InsBufLine(hbuf, 18+FileHeaderLine, "")
InsBufLine(hbuf, 19+FileHeaderLine, "")
InsBufLine(hbuf, 20+FileHeaderLine, "/********************************** 全局变量 ***********************************/")
InsBufLine(hbuf, 21+FileHeaderLine, "")
InsBufLine(hbuf, 22+FileHeaderLine, "")
InsBufLine(hbuf, 23+FileHeaderLine, "/********************************** 局部函数声明 ***********************************/")
InsBufLine(hbuf, 24+FileHeaderLine, "")
InsBufLine(hbuf, 25+FileHeaderLine, "")
InsBufLine(hbuf, 26+FileHeaderLine, "/********************************** 局部函数 ***********************************/")
InsBufLine(hbuf, 27+FileHeaderLine, "")
InsBufLine(hbuf, 28+FileHeaderLine, "")
InsBufLine(hbuf, 29+FileHeaderLine, "/********************************** 全局函数 ***********************************/")
InsBufLine(hbuf, 30+FileHeaderLine, "")
InsBufLine(hbuf, 31+FileHeaderLine, "")
InsBufLine(hbuf, 32+FileHeaderLine, "/********************************** 类的实现 ***********************************/")
InsBufLine(hbuf, 33+FileHeaderLine, "")
InsBufLine(hbuf, 34+FileHeaderLine, "")

SetBufIns(hbuf, 34+FileHeaderLine, 20)

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值