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

注:更新后的脚本,支持原路径中是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);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值