/* 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 REVI