您的位置:首页 > 编程语言 > C语言/C++

source insight中cpp文件和h文件的切换(使用si的内置语言实现)[增加src/include目录切换]

2009-12-24 11:23 756 查看
注:更新后的脚本,支持原路径中是include或src的目录切换,而不再要求是在同一目录中的cpp和h文件切换,

相对第一版的修改部分的代码后面也用红色标注。

研究了si的编程语言,总算实现了cpp和h文件的切换,好爽(不知道网上的有没),自制的,希望对大家有帮助。

这里是此个函数的代码,只要将open_cpp_h函数绑定到一个快捷键就方便了哦

至于函数怎么使用,可以参见:

一个处理
source insight
中中文乱码问题的例子:

http://www.sourceinsight.com.cn/tech2.htm

Source insight
官方帮助文档中关于
macro
使用:

http://www.sourceinsight.com/docs35/Macro%20Language.htm#Xag957533

代码如下:

/**

cpp和h文件互换

*/

macro open_cpp_h()

{

hwnd = GetCurrentWnd();

hbuf = GetCurrentBuf();

if (hbuf == 0)

stop;   // empty buffer

fn = GetBufName(hbuf);

fl = strlen(fn);

strbuf = NewBuf("temp");

ClearBuf(strbuf);

AppendBufLine(strbuf, ".h");

AppendBufLine(strbuf, ".hpp");

AppendBufLine(strbuf, ".c");

AppendBufLine(strbuf, ".cpp");

AppendBufLine(strbuf, ".cx");

AppendBufLine(strbuf, ".cxx");

idx_c = 2;//开始cpp的下标

idx_end = GetBufLineCount(strbuf);

i = 0;

dest_type=0;//0表示h,1表示cpp

//for(i=0; i<idx_end; i++)

while(i < idx_end)

{

rec = GetBufLine(strbuf, i);

len = strlen(rec);

last = strmid(fn, fl - len, fl);

if(last == rec)

{

ext = "";

if(i<idx_c) //h

{

ext = ".cpp";

dest_type = 1;

}else

{

ext = ".h";

dest_type = 0;

}

name = strmid(fn, 0, fl - len);

fn = cat(name, ext);

break;

}

i = i + 1;

}

CloseBuf(strbuf);

//替代src、include的目录. 针对type,互换目录

orig = "//include//";

dest = "//src//";

if(dest_type == 0) //如果要变成h,则src变成include

{

temp = orig;

orig = dest;

dest = temp;

}

orig_len = strlen(orig);

dest_len = strlen(dest);

fl = strlen(fn);

//从文件目录中查找并替换,从后向前找

i = strlen(fn) - orig_len - 1;

while(i>=0)

{

cut = strmid(fn, i, i+orig_len);

if(orig == cut)

{

head = strmid(fn, 0, i);

tail_p = i+orig_len;

tail = strmid(fn, tail_p, fl);

fn = cat(head, dest);

fn = cat(fn, tail);

}

i = i - 1;

}

hbuf = OpenBuf(fn);

if(hbuf != 0)

SetCurrentBuf(hbuf);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐