为Qt Creator 开发astyle代码格式化插件
2015-12-16 16:17
531 查看
与VS2008系列的IDE相比Qt
Creator开发代码插件比较简单
闲话不说,看我的步骤:
(1)Qt Creator中“菜单”-“工具”-“选项”-“环境”-“外部工具”-“文本”
(2)接下来说明一下如何写一个工具处理输入的文本
这个输入文本通过控制台的管道传入到工具程序中也就是stdout ,从工具那边就是stdin可以读取到使用如下代码进行读取输入文本:
void _FormatCode(constCStringA& IN strSelectCode, CStringA& OUT strOutput);
#define MAX_CODE_LEN (3*1024*1024)
int _tmain(int argc, _TCHAR*argv[])
{
#ifdef _DEBUG
MessageBox(NULL,L"srcFormater Attach", L"please Attach", 0);
#endif
//通过stdin读取输入的代码
//
char*pbuf = new(nothrow) char[MAX_CODE_LEN];
if(pbuf)
{
intp = 0;
while(TRUE)
{
intc = fgetc(stdin);
if(c== EOF)
{
break;
}
pbuf[p++]= (char)c;
}
pbuf[p]= 0;
intcodeLen = p;
CStringAstrInput = pbuf;
//将pbuf的字符串进行astyle格式化
//
//
CStringAstrOutput;
_FormatCode(strInput,strOutput);
//输出格式化后的代码
//
if(!strOutput.IsEmpty())
{
printf(strOutput);
}
else
{
printf(strInput);//没有输入就把输入输出,当作没有变化
}
delete[]pbuf;
}
return0;
}
(3)_FormatCode 这个函数大家去自己实现一个就行了,可以调用astyle等工具进行处理,最后通过printf打印出来,注意QtCreator的换行符是"\n"如果你指定"\r\n"则会产生多余一个空行
astyle格式化工具的VS2008插件的代码在me的资源中有
Creator开发代码插件比较简单
闲话不说,看我的步骤:
(1)Qt Creator中“菜单”-“工具”-“选项”-“环境”-“外部工具”-“文本”
(2)接下来说明一下如何写一个工具处理输入的文本
这个输入文本通过控制台的管道传入到工具程序中也就是stdout ,从工具那边就是stdin可以读取到使用如下代码进行读取输入文本:
void _FormatCode(constCStringA& IN strSelectCode, CStringA& OUT strOutput);
#define MAX_CODE_LEN (3*1024*1024)
int _tmain(int argc, _TCHAR*argv[])
{
#ifdef _DEBUG
MessageBox(NULL,L"srcFormater Attach", L"please Attach", 0);
#endif
//通过stdin读取输入的代码
//
char*pbuf = new(nothrow) char[MAX_CODE_LEN];
if(pbuf)
{
intp = 0;
while(TRUE)
{
intc = fgetc(stdin);
if(c== EOF)
{
break;
}
pbuf[p++]= (char)c;
}
pbuf[p]= 0;
intcodeLen = p;
CStringAstrInput = pbuf;
//将pbuf的字符串进行astyle格式化
//
//
CStringAstrOutput;
_FormatCode(strInput,strOutput);
//输出格式化后的代码
//
if(!strOutput.IsEmpty())
{
printf(strOutput);
}
else
{
printf(strInput);//没有输入就把输入输出,当作没有变化
}
delete[]pbuf;
}
return0;
}
(3)_FormatCode 这个函数大家去自己实现一个就行了,可以调用astyle等工具进行处理,最后通过printf打印出来,注意QtCreator的换行符是"\n"如果你指定"\r\n"则会产生多余一个空行
astyle格式化工具的VS2008插件的代码在me的资源中有
相关文章推荐
- android 代码实现控件之间的间距
- [Android]在代码里运行另一个程序的方法
- QT学习 第一章:基本对话框
- 使用Shiboken为C++和Qt库创建Python绑定
- 肯特·贝克:改变人生的代码整理魔法
- 网页恶意代码的预防
- 高手写的Tracer-Flash代码调试类代码下载
- CSS代码缩写技巧
- 非主流Q-zOne代码代码搜集第1/2页
- CreateWeb.vbs 代码
- Lua中编译执行代码相关的函数详解
- 如何解决ORA-01843与NLS_DATE_FORMAT问题
- 更有效率的css代码编写第1/3页
- 常用Extjs工具:Extjs.util.Format使用方法
- 代码中到底应不应当写注释?
- SQL语言查询基础:连接查询 联合查询 代码
- 论坛头像随机变换代码
- .NET 常用功能和代码小结
- C#实现压缩HTML代码的方法
- asp编程中常用的javascript辅助代码第1/2页