source insight用于C语言编程的工具脚本
简单来说,source insight提供的功能功能还不够傻瓜,用起来还不够方便,所以写了此脚本,提高开发效率。
部分source insight提供的功能也包含了进来,主要是因为我不喜欢使用太多的快捷键。
将代码中wcjMain关联到alt+a快捷键,随后输入你想操作的指令:如cb代表在本行之前添加注释即可。
目前提供的指令有20种左右,后面根据需要在补充。
1. 这个source insight中用的脚本,将其另存为任意名称.em文件
2. base工程中add该脚本
3. 在option->key assignment中将wcjMain关联某个快捷键后即可使用
4. 该脚本功能包括:
- 类型替换
- 注释添加
- 标准的C头文件及实现文件的标准格式添加
- 部分宏操作
- 自动添加include
- 增加var支持
macro _wcjFileName(fullname)
{
length = strlen(fullname)
if (length == )
return "" index = length
while ("\\" != fullname[--index]); purename = ""
while (index < length)
purename = cat(purename, fullname[++index]) return purename
}
/* 获取当前的文件名*/
macro _wcjCurrentFileName()
{
hbuf = GetCurrentBuf()
fullname = GetBufName(hbuf) return _wcjFileName(fullname)
} /*头文件定义名称*/
macro wcjIncDefName()
{
filename = _wcjCurrentFileName();
length = strlen(filename); defname = "__"
index = ;
while (index < length)
{
if (filename[index] == ".")
defname = cat(defname, "_")
else
defname = cat(defname, toupper(filename[index])) ++index
} defname = cat(defname, "__") return defname
} /*获取当前时间*/
macro wcjGetTime()
{
var year
var month
var day
var commTime
var sysTime sysTime = GetSysTime()
year = sysTime.Year
month = sysTime.month
day = sysTime.day
commTime = "@year@-@month@-@day@"
return commTime
} /**************************************new file related***********************************************/
macro _wcjCommentFile()
{
szMyName = "wangchunjie w00361341" hbuf = GetCurrentBuf()
ln =
InsBufLine(hbuf, ln++, "/*-------------------------------------------------------------------------")
InsBufLine(hbuf, ln++, cat(" File: ", _wcjCurrentFileName())
InsBufLine(hbuf, ln++, cat(" Author: ", szMyName))
InsBufLine(hbuf, ln++, cat(" Date: ", wcjGetTime())
InsBufLine(hbuf, ln++, cat(" Desc: ", ""))
InsBufLine(hbuf, ln++, "-------------------------------------------------------------------------*/") /* 设置光标正确的位置 */
SetBufIns(hbuf, ln, ) return true
} /*在当前行的前一行添加注释*/
macro _wcjCommentBefore()
{
hbuf = GetCurrentBuf()
ln = GetBufLnCur(hbuf) comment = "" /*补足空格*/
text = GetBufLine(hbuf, ln)
index =
while (true)
{
c = text[index++]
if (c != " " && c != " ")
break; comment = cat(comment, c)
} comment = cat(comment, "/**< */") InsBufLine(hbuf, ln, comment) /* 设置光标正确的位置 */
SetBufIns(hbuf, ln, strlen(comment) - ) return true
} macro _wcjCommentHeader()
{
hbuf = GetCurrentBuf() szFunc = GetCurSymbol()
ln = GetSymbolLine(szFunc)
SetBufIns(hbuf, ln, ) return _wcjCommentBefore() } /**************************************new file related***********************************************/
macro _wcjNewFile(bInc)
{
defname = wcjIncDefName() _wcjCommentFile() hbuf = GetCurrentBuf()
ln = GetBufLnCur(hbuf) if (bInc)
{
InsBufLine(hbuf, ln++, "#ifndef @defname@")
InsBufLine(hbuf, ln++, "#define @defname@")
InsBufLine(hbuf, ln++, "")
} InsBufLine(hbuf, ln++, "#ifdef _cplusplus")
InsBufLine(hbuf, ln++, "#if _cplusplus")
InsBufLine(hbuf, ln++, "extern \"C\"{")
InsBufLine(hbuf, ln++, "#endif")
InsBufLine(hbuf, ln++, "#endif") InsBufLine(hbuf, ln++, "")
cursorln = ln
InsBufLine(hbuf, ln++, "")
InsBufLine(hbuf, ln++, "") InsBufLine(hbuf, ln++, "#ifdef _cplusplus")
InsBufLine(hbuf, ln++, "#if _cplusplus")
InsBufLine(hbuf, ln++, "}")
InsBufLine(hbuf, ln++, "#endif")
InsBufLine(hbuf, ln++, "#endif") if (bInc)
InsBufLine(hbuf, ln++, "#endif /* @defname@ */") /* 设置光标正确的位置 */
SetBufIns(hbuf, cursorln, )
}
macro _wcjHandleNewFile(key)
{
/*插入C标准的include文件内容*/
if (key == "newinc") return _wcjNewFile(true)
/*插入C标准的C文件内容*/
if (key == "newc") return _wcjNewFile(false) return false
} /**************************************ufp type related***********************************************/
macro _wcjInsertCursorText(data)
{
/* 获得指定行文本 */
hbuf = GetCurrentBuf()
ln = GetBufLnCur(hbuf)
text = GetBufLine(hbuf, ln) /* 获得光标位置 */
hwnd = GetCurrentWnd()
sel = GetWndSel(hwnd)
column = sel.ichFirst /* 为当前位置插入正确内容 */
DelBufLine(hbuf, ln)
before = strtrunc(text, column)
after = strmid(text, column, strlen(text))
newtext = "@before@@data@@after@"
InsBufLine(hbuf, ln, newtext) /* 设置光标正确的位置 */
pos = column + strlen(data)
SetBufIns(hbuf, ln, pos)
}
/*快捷内容插入*/
macro _wcjHandleUfpType(key)
{
/*key = Ask("Enter ufp type short key");*/
ufptype = _wcjGetUfpType(key)
if (ufptype == "")
return false; _wcjInsertCursorText(ufptype); return true;
} /**************************************macro related***********************************************/
/*插入ifdef*/
macro _wcjIfdefSz()
{
data = Ask("Enter ifdef condition:")
if (data == "")
return true hwnd = GetCurrentWnd()
lnFirst = GetWndSelLnFirst(hwnd)
lnLast = GetWndSelLnLast(hwnd) hbuf = GetCurrentBuf()
InsBufLine(hbuf, lnFirst, "#ifdef @data@")
InsBufLine(hbuf, lnLast+, "#endif /* @data@ */") return true
} /*插入if*/
macro _wcjIfSz(data)
{
hwnd = GetCurrentWnd()
lnFirst = GetWndSelLnFirst(hwnd)
lnLast = GetWndSelLnLast(hwnd) hbuf = GetCurrentBuf()
InsBufLine(hbuf, lnFirst, "#if @data@")
InsBufLine(hbuf, lnLast+, "#endif") return true
} /**************************************windows related***********************************************/
macro _wcjCloseWindows()
{
cwnd = WndListCount()
iwnd =
while ()
{
hwnd = WndListItem()
hbuf = GetWndBuf(hwnd)
SaveBuf(hbuf)
CloseWnd(hwnd)
iwnd = iwnd +
if(iwnd >= cwnd)
break
} return true;
} /**************************************other related***********************************************/
macro _wcjAddInclude()
{
hbuf = GetCurrentBuf()
ln = GetBufLnCur(hbuf) /* 获得光标位置 */
hwnd = GetCurrentWnd()
sel = GetWndSel(hwnd)
column = sel.ichFirst /*找到正确的符号*/
//symbol = GetSymbolLocationFromLn(hbuf, ln)
symbol = GetSymbolFromCursor(hbuf, ln, column)
if (symbol.Symbol == "")
{
msg("check cursor, can't find symbol")
return true
} /*文件名抽取*/
filename = _wcjFileName(symbol.file);
len = strlen(filename)
filetype = strmid(filename, len-, len)
if (filetype == ".c")
filename = Ask("func imp in @filename@, enter include file name or cancel:") if (filename == "")
return true includetext = "#include \"@filename@\"" /* 正确的插入位置 */
count = GetBufLineCount(hbuf)
ln =
text = ""
lasttext = "invalid"
while(ln < count)
{
if(ln != )
lasttext = text
text = GetBufLine(hbuf, ln) /*找到合适位置*/
if (text == "#ifdef _cplusplus")
{
/*保证保留一个空格*/
if (lasttext == "")
ln--
else
InsBufLine(hbuf, ln, "") /* 插入 */
InsBufLine(hbuf, ln, includetext) return true
} /*已添加*/
if (text == includetext)
{
return true
} ln++
} msg("can't add include, do it by youself")
return true
} macro _wcjHandleVar()
{
key = Ask("Enter variable name:")
if (key == "")
return true hbuf = GetCurrentBuf() text = ""
if (strtrunc(key, ) == "i") text = "UFP_INT32 @key@"
if (strtrunc(key, ) == "ui") text = "UFP_UINT32 @key@"
if (strtrunc(key, ) == "ull") text = "UFP_UINT64 @key@"
if (strtrunc(key, ) == "uv") text = "UFP_UINTPTR @key@"
if (strtrunc(key, ) == "v") text = "UFP_VOID @key@"
if (strtrunc(key, ) == "vp") text = "UFP_PHYS_ADDR @key@"
if (strtrunc(key, ) == "n") text = "UFP_NULL_PTR @key@" _wcjInsertCursorText(text) return true
} /**************************************罗列所有快捷键***********************************************/
macro _wcjHandleWindows(key)
{
if (key == "winclose" || key == "wc") return _wcjCloseWindows() return false;
}
macro _wcjHandleOther(key)
{
if (key == "addinc") return _wcjAddInclude() return false
} macro _wcjHandleMacro(key)
{
if (key == "if0") return _wcjIfSz()
if (key == "ifdef") return _wcjIfdefSz() return false
}
macro _wcjHandleComment(key)
{
if (key == "commentfile" || key == "cf") return _wcjCommentFile()
if (key == "commentbefore" || key == "commentbef" || key == "cb") return _wcjCommentBefore()
if (key == "commentheader" || key == "ch") return _wcjCommentHeader() return false
} /*程序中用到的自定义快捷键*/
macro _wcjGetUfpType(key)
{
key = tolower(key); if (key == "i") return "UFP_INT32"
if (key == "ui" || key=="u") return "UFP_UINT32"
if (key == "ull") return "UFP_UINT64"
if (key == "uv") return "UFP_UINTPTR"
if (key == "v") return "UFP_VOID"
if (key == "vp") return "UFP_PHYS_ADDR"
if (key == "n") return "UFP_NULL_PTR" return ""
} /* 主入口 */
macro wcjMain()
{
key = Ask("Enter anthing you want:")
if (key == "")
return "" key = tolower(key); /*ufp type处理*/
if (_wcjHandleUfpType(key)) return ""
/*macro相关*/
if (_wcjHandleMacro(key)) return ""
/*new file*/
if (_wcjHandleNewFile(key)) return ""
/*comment*/
if (_wcjHandleComment(key)) return ""
/*窗体相关*/
if (_wcjHandleWindows(key)) return ""
/*变量*/
if (key == "var") return _wcjHandleVar() return _wcjHandleOther(key)
}
source insight用于C语言编程的工具脚本的更多相关文章
- Source Insight 中使用 AStyle 代码格式工具
Source Insight 中使用 AStyle 代码格式工具 彭会锋 2015-05-19 23:26:32 Source Insight是较好的代码阅读和编辑工具,不过source in ...
- Ideone:在线多语言编程执行器工具
Ideone:在线多语言编程执行器工具此网站提供40种编程语言以上, 能在线直接做编译和执行的动作,该工具是一款简易的编程测试工具,虽然不能替代专业版的工具,但是其功能非常全面. Ideone,一款在 ...
- 免费的文件比较工具和beyondcomare和source insight的比较工具
Linux下,meld就够了,命令行用用diff也行,kdiff3也不错. 参考 http://www.cnblogs.com/itech/archive/2009/08/13/1545344.htm ...
- 华为C语言编程规范
DKBA华为技术有限公司内部技术规范DKBA 2826-2011.5C语言编程规范2011年5月9日发布 2011年5月9日实施华为技术有限公司Huawei Technologies Co., Ltd ...
- 打造linux下的source insight——vim插件安装使用总结
source insight是windows下的优秀编辑器,适合阅读管理代码,主要有以下功能: 查找函数,变量或者宏的定义. 查找函数,变量或者宏的引用位置. 查找函数被调用的位置 查找某个符号在工程 ...
- source insight 注册码
分享一下google来的 呵呵 Source Insight,一个无比强大的工具.一个很好的查看代码的工具.到它的官网上去看一下,就知道,世界上基本上所有的大的软件公司,都在用这个工具.习惯了这个工具 ...
- 代码阅读工具:Source Navigator和Source Insight
(摘自http://www.cnblogs.com/yc_sunniwell/archive/2010/08/25/1808322.html) 一.Source Insight实用技巧: Source ...
- 【工利其器】必会工具之(一)Source Insight篇
前言 “Source Insight(以下简称SI)是世界上最好的编辑器”,说这句话不知道会不会出门被打呢?-_- 中国古话说得好,“文无第一,武无第二”,所以不敢说SI是最好的,但是 ...
- 阅读linux内核代码的工具-- Source Insight
http://blog.csdn.net/luckyaslan/article/details/7869235 Step 1:安装Source Insight并启动程序 可以进入图1界面,在工具条上有 ...
随机推荐
- [HDU 1114] Piggy-Bank (动态规划)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114 简单完全背包,不多说. #include <cstdio> #include < ...
- Regional Changchun Online--Elven Postman(裸排序二叉树)
Elven Postman Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Tot ...
- 安装和卸载windows程序
安装windows service通常有两种工具 1.Framework目录下的installutil.exe工具.2.visual studio命令行工具 在这里我要说的是当我们使用的系统是64位的 ...
- 将Excel中数据导入数据库(二)
在上篇文章中介绍到将Excel中数据导入到数据库中,但上篇文章例子只出现了nvachar类型,且数据量很小.今天碰到将Excel中数据导入数据库中的Excel有6419行,其中每行均有48个字段,有i ...
- Entity FrameWork 与 NHibernate
1 Nhibernate 展示了NHibernate在数据库和用程序之间提供了一个持久层. 应用程序自己提供ADO.NET连接,并且自行管理事务.NHibernate体系结构如图1-51所示.它体 ...
- 《App研发录》知识点汇总
原文链接:http://www.jianshu.com/p/fc8c4638937e <App研发录>这部书是包建强写的,说来也巧,在读这边书之前在看池建强的<Mac 人生元编程&g ...
- 【drp 9】Servlet生命周期
一.基本概念 Servlet(Server Applet):全称Java Servlet,是用Java编写的服务器端程序.其主要功能在于交互式地浏览和修改数据,生成动态Web内容.狭义的Servlet ...
- APUE第五章:标准IO库
5.2流和file对象 #include <wchar.h> int fwide(FILE *fp, int mode); Returns: positive if stream is w ...
- 2016-03-24:Windows内存泄露分析工具
参考资料 100%正确的内存泄漏分析工具 ------ tMemMonitor (TMM)
- .Net 乱序方法
前两天开发一个奇葩的功能,突然间想到了用打乱顺序的方式解决.记录代码如下: /// <summary> /// 把收集回来的列表打乱顺序之后返回 /// </summary> ...