Source Insight 宏 - 头文件与源文件切换

当前宏功能:

1、.h/.hpp与.c/.cpp/.cx/.cxx/.cc等类型的呼唤,如果有其它对应的关系,也可以加入脚本中;

2、同一目录下相同文件名,不同扩展名文件之间的切换。


见脚本:


/*
  cpp和hpp文件互换(当前只支持同一目录下的文件互换)
*/
macro switch_cpp_hpp()
{
	hwnd = GetCurrentWnd()
	hCurOpenBuf = GetCurrentBuf()
	if (hCurOpenBuf == 0)
		stop 
	curOpenFileName = GetBufName(hCurOpenBuf)
	curOpenFileNameLen = strlen(curOpenFileName)

	// 文件类型临时缓冲区
	strFileExt = NewBuf("strFileExtBuf")
	ClearBuf(strFileExt)
	
	// 头文件类型
	index_hpp_begin = 0 							// 头文件开始索引
	AppendBufLine(strFileExt, ".h")
	AppendBufLine(strFileExt, ".hpp")
	index_hpp_end = GetBufLineCount(strFileExt) 		// 头文件结束索引
	
	// 源文件类型
	index_cpp_begin = index_hpp_end 			// 源文件开始索引
	AppendBufLine(strFileExt, ".c")
	AppendBufLine(strFileExt, ".cpp")
	AppendBufLine(strFileExt, ".cc")
	AppendBufLine(strFileExt, ".cx")
	AppendBufLine(strFileExt, ".cxx")
	index_cpp_end = GetBufLineCount(strFileExt)		// 源文件结束索引

	isCppFile = 0 						// 0:未知 1:头文件 2:源文件,默认未知扩展名
	curOpenFileExt = "" 					// 当前打开文件的扩展名
	index = index_hpp_begin 
	// 遍历头文件,判断是否当前打开文件是头文件类型
	while(index < index_cpp_end)	
	{
		curExt = GetBufLine(strFileExt, index) 
		curExtLen = strlen(curExt) 
		curOpenFileExt = strmid(curOpenFileName, curOpenFileNameLen-curExtLen, curOpenFileNameLen) 		// 当前打开文件的扩展名
		
		// 调试
		// AppendBufLine(debugBuf, curExt)
		// AppendBufLine(debugBuf, curOpenFileExt)

		
		if(curOpenFileExt == curExt)			// 匹配成功
		{
			if (index < index_hpp_end)
				isCppFile = 1 			// 当前打开文件是头文件
			else
				isCppFile = 2 			// 源文件
			break 
		}
		index = index + 1 
	}// while(index < index_cpp_end)
	
	// 调试
	// AppendBufLine(debugBuf, isCppFile)

	index_replace_begin = index_hpp_begin 
	index_replace_end = index_hpp_end 
	
	if (isCppFile == 1)					// 当前打开文件是头文件			
	{
		index_replace_begin = index_cpp_begin 
		index_replace_end = index_cpp_end 
	}
	else if(isCppFile == 2)					// 当前打开文件是源文件
	{
		index_replace_begin = index_hpp_begin 
		index_replace_end = index_hpp_end 
	
		// 调试
		// AppendBufLine(debugBuf, "cpp")
	}
	else							// 未知类型
	{
		//CloseBuf(strFileExt)				// 关闭缓冲区

		//stop 
	
		index_replace_begin = 9999 					
		index_replace_end = index_replace_begin 	// 下面循环不会执行
	}
	
	index = index_replace_begin 
	while(index < index_replace_end)
	{
		destExt = GetBufLine(strFileExt, index) 
		destFileName = strmid(curOpenFileName, 0, curOpenFileNameLen-strlen(curOpenFileExt)) 	// 不包括扩展名,绝对路径
		
		// 尝试当前目标扩展名是否能够打开
		destFilePath = cat(destFileName, destExt)	// 文件名(包括扩展名)
		
		hCurOpenBuf = OpenBuf(destFilePath)
		if(hCurOpenBuf != 0)
		{
			SetCurrentBuf(hCurOpenBuf)
			break 
		}
		
		// 尝试进行目录替换,看能否打开文件(如何设计:支持多个目录)
		// ...(赞不支持)

		
		index = index + 1 
	}
	CloseBuf(strFileExt)							// 关闭缓冲区
	// 调试
	// AppendBufLine(debugBuf, "finished")
	
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值