任何工具/脚本可用于转换c99
风格的评论/* ..*/
c
风格的评论/* ..*/
到整个项目?
如果我有这样的代码
// printf("stcakoverflow");
那么它会像转换一样
/* printf("stcakoverflow"); */
并且
int temp // this is temp varialbe
转换成
int temp /* this is temp varialbe */
对于命令行示例,请尝试如下所示:
echo "int temp; // this is temp variable" | sed 's@//\(.*\)$@/*\1 */@'
以上结果
int temp; / *这是临时变量* /
对于一个真正的文件,你可以使用例如cat
而不是echo
,这是sed
的管道和执行“魔术”的sed
命令。
编辑:如何做很多文件
这样的事情可能是:
cd /your/source/directory mkdir converted-files for f in *.cpp; do cat $f | sed 's@//\(.*\)$@/*\1 */@' > converted-files/$f done
现在所有转换的源文件都将在一个文件夹converted-files
。
对于使用IDE /编辑器的人来说,使用Notepad ++(你也可以在Linux上使用Notepad ++运行它)正则表达式匹配,并替换你可以做一堆文件。
找到什么 : //(.*?)$
?) //(.*?)$
替换为 : /\*\1\*/
ccmtcnvt – 将C ++注释转换为C注释
在Joachim Pileborg的帮助下
我做了这个
find /path/to/project/ -type f -exec sed -i 's@//\(.*\)$@/*\1 */@' {} \;
在这里它工作正常..但它适用于所有文件。
如果你希望它只适用于.c和.h文件
find /path/to/project/ -name '*.c' -o -name '*.h' -exec sed -i 's@//\(.*\)$@/*\1 */@' {} \;