搜索
bottom↓
回复: 2

source insight 常用宏

[复制链接]

出0入0汤圆

发表于 2013-1-31 14:16:40 | 显示全部楼层 |阅读模式

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

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)
}
/* 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()
{
    szMyName = getenv(MYNAME)
   
    hbuf = GetCurrentBuf()

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



// 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 <sz> .. 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

}

/*

    written by yubind

                                                            */

macro SingleLineComment()
{
szMyName = "Phenix"
// Get a handle to the current file buffer and the name
// and location of the current symbol where the cursor is.
hbuf = GetCurrentBuf()
ln = GetBufLnCur(hbuf)

// Get current time
szTime = GetSysTime(1)
Hour = szTime.Hour
Minute = szTime.Minute
Second = szTime.Second
Day = szTime.Day
Month = szTime.Month
Year = szTime.Year
if (Day < 10)
szDay = "0@Day@"
else
szDay = Day
//szMonth = NumToName(Month)
if (Month < 10)
     szMonth = "0@Month@"
else
szMonth = Month

szDescription = Ask("Input prefix(such as: added、modified、...):") //modified by Phenix
szPrepWord = "by" //added by Phenix 2008-01-16
// begin assembling the title string
InsBufLine(hbuf, ln+1, "/* @szDescription@ @szPrepWord@ @szMyName@, @Year@-@szMonth@-@szDay@ */")
}

macro MultiLineCommentHeader()
{
szMyName = "Phenix"
// Get a handle to the current file buffer and the name
// and location of the current symbol where the cursor is.
hbuf = GetCurrentBuf()
ln = GetBufLnCur(hbuf)

// Get current time
szTime = GetSysTime(1)
Hour = szTime.Hour
Minute = szTime.Minute
Second = szTime.Second
Day = szTime.Day
Month = szTime.Month
Year = szTime.Year
if (Day < 10)
szDay = "0@Day@"
else
szDay = Day
//szMonth = NumToName(Month)
if (Month < 10)
     szMonth = "0@Month@"
else
szMonth = Month

szDescription = Ask("Input prefix(such as: added、modified、...):")
szPrepWord = "by" //added by Phenix 2008-01-16
// begin assembling the title string
InsBufLine(hbuf, ln + 1, "/* @szDescription@ @szPrepWord@ @szMyName@ @Year@-@szMonth@-@szDay@ begin */")
}

macro MultiLineCommentEnd()
{
szMyName = "Phenix"
// Get a handle to the current file buffer and the name
// and location of the current symbol where the cursor is.
hbuf = GetCurrentBuf()
ln = GetBufLnCur(hbuf)

// Get current time
szTime = GetSysTime(1)
Hour = szTime.Hour
Minute = szTime.Minute
Second = szTime.Second
Day = szTime.Day
Month = szTime.Month
Year = szTime.Year
if (Day < 10)
szDay = "0@Day@"
else
szDay = Day
//szMonth = NumToName(Month)
if (Month < 10)
     szMonth = "0@Month@"
else
szMonth = Month

InsBufLine(hbuf, ln + 1, "/*@szMyName@ @Year@-@szMonth@-@szDay@ end*/")
}

/* Phenix add start,2008-04-07 */

/*-------------------------------------------------------------------------
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 "szMyName" and set it
to your email name. eg. set szMyName=raygr
-------------------------------------------------------------------------*/

macro InsFileHeader()
{

/*#########################################################
#########################################################
####### Set szMyName variable to your name    ########
####### for example    szMyName = "t357"     ########
#########################################################   
#########################################################*/
szMyName = "Phenix"

// Get current time
szTime = GetSysTime(1)
Day = szTime.Day
Month = szTime.Month
Year = szTime.Year
if (Day < 10)
szDay = "0@Day@"
else
szDay = Day
//szMonth = NumToName(Month)
if (Month < 10)
     szMonth = "0@Month@"
else
     szMonth = Month

hBuf = GetCurrentBuf()
szpathName = GetBufName(hBuf)
szfileName = GetFileName(szpathName)
nlength = StrLen(szfileName)
//szInf = Ask("Enter the information of file:")
//   szDescription = Ask("Enter the description of file:")

hbuf = GetCurrentBuf()
// begin assembling the title string
InsBufLine(hbuf, 0, "/******************************************************************************")
InsBufLine(hbuf, 1, " * @szfileName@ - ")
InsBufLine(hbuf, 2, " * ")
InsBufLine(hbuf, 3, " * Copyright 2005-2008 ZTESec Co.,Ltd.")
InsBufLine(hbuf, 4, " * ")
InsBufLine(hbuf, 5, " * DESCRIPTION: - ")
InsBufLine(hbuf, 6, " * ")
InsBufLine(hbuf, 7, " * modification history")
InsBufLine(hbuf, 8, " * --------------------")
InsBufLine(hbuf, 9, " * v1.0   @Year@/@szMonth@/@szDay@, @szMyName@ create this file")
InsBufLine(hbuf, 10, " * ")
InsBufLine(hbuf, 11, " ******************************************************************************/")

// put the insertion point inside the header comment
SetBufIns(hbuf, 1, nlength + strlen(szInf) + 8)
}

/******************************************************************************
* InsFunHeader -- insert function's information
*
* modification history
* --------------------
* 01a, 23mar2003, added DESCRIPTION by t357
* 01a, 05mar2003, t357 written
* --------------------
******************************************************************************/
macro InsFunHeader()
{
// Get the owner's name from the environment variable: szMyName.
// If the variable doesn't exist, then the owner field is skipped.

/*#########################################################
#########################################################
####### Set szMyName variable to your name    ########
####### for example    szMyName = "t357"     ########
#########################################################   
#########################################################*/
szMyName = "Phenix"

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

// Get current time
szTime = GetSysTime(1)
Day = szTime.Day
Month = szTime.Month
Year = szTime.Year
if (Day < 10)
szDay = "0@Day@"
else
szDay = Day
//szMonth = NumToName(Month)
if (Month < 10)
     szMonth = "0@Month@"
else
     szMonth = Month
//szInf = Ask("Enter the information of function:")
//szDescription = Ask("Enter the description of function:")

// begin assembling the title string
sz = "/******************************************************************************"
InsBufLine(hbuf, ln, sz)
InsBufLine(hbuf, ln + 1, " * @szFunc@: ")
//InsBufLine(hbuf, ln + 2, " * DESCRIPTION: - ")
    InsBufLine(hbuf, ln + 2, " *")
// remove by t357.    CutWord(szDescription)
InsBufLine(hbuf, ln + 3, " * Parameter:")
InsBufLine(hbuf, ln + 4, " * Input: ")
InsBufLine(hbuf, ln + 5, " * Output: ")
InsBufLine(hbuf, ln + 6, " * Returns: ")
InsBufLine(hbuf, ln + 7, " * ")
InsBufLine(hbuf, ln + 8, " * modification history")
InsBufLine(hbuf, ln + 9, " * --------------------")
InsBufLine(hbuf, ln + 10, " *    @Year@/@szMonth@/@szDay@, @szMyName@ create this function")
InsBufLine(hbuf, ln + 11, " * ")
InsBufLine(hbuf, ln + 12, " ******************************************************************************/")

// put the insertion point inside the header comment
SetBufIns(hbuf, ln + 1, strlen(szFunc) + strlen(szInf) + 8)
}

/******************************************************************************
* NumToName -- change the month number to name
*
* modification history
* --------------------
* 01a, 05mar2003, t357 written
* --------------------
******************************************************************************/
macro NumToName(Month)
{
if (Month == 1)
return "jan"
if (Month == 2)
return "feb"
if (Month == 3)
return "mar"
if (Month == 4)
return "apr"
if (Month == 5)
return "may"
if (Month == 6)
return "jun"
if (Month == 7)
return "jul"
if (Month == 8)
return "aug"
if (Month == 9)
return "sep"
if (Month == 10)
return "oct"
if (Month == 11)
return "nov"
if (Month == 12)
return "dec"
}

/******************************************************************************
* GetFileName -- get the filename only from the path
*
* modification history
* --------------------
* 01a, 05mar2003, t357 written
* --------------------
******************************************************************************/
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
}

阿莫论坛20周年了!感谢大家的支持与爱护!!

月入3000的是反美的。收入3万是亲美的。收入30万是移民美国的。收入300万是取得绿卡后回国,教唆那些3000来反美的!

出0入0汤圆

发表于 2019-5-9 21:24:12 | 显示全部楼层
不知道怎么用,

出0入0汤圆

发表于 2019-7-25 21:53:17 | 显示全部楼层
是的,不知如何用。V3.5 可以用不?还是要新的 V4.0 版的。
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-4-27 10:41

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表