怎么创建网站后台,网站如何投放广告,泰安高端网站设计建设,表白网页生成制作脚本一#xff1a;格式化指定目录下的源文件(*.h, *.cpp...)
#!/bin/sh# 格式化某目录下所有*.h, *.c, *.cpp, *.hh文件, 并将文件换行符转换成Linux下的格式if [ $# -lt 1 ]; thenecho Usage: $0 direxit 1elsedir$1fi# format a source file(*.c, *.h,…脚本一格式化指定目录下的源文件(*.h, *.cpp...)
#!/bin/sh
# 格式化某目录下所有*.h, *.c, *.cpp, *.hh文件, 并将文件换行符转换成Linux下的格式
if [ $# -lt 1 ]; then
echo Usage: $0 dir
exit 1
else
dir$1
fi
# format a source file(*.c, *.h, *.cpp, *.hh)
formatSrcfile()
{
dos2unix $1
indent -npro -nip -lp -npsl -npcs -i4 -ts4 -sob -l140 -ci4 -ss -nsaf -nsai -nsaw -bl -bli0 $1
rm -f $1~
}
# save file path to file
find $dir -name *.h -o -name *.c -o -name *.cpp -o -name *.hh tmp
# format every file in tmp
while read file
do
formatSrcfile $file
done tmp
# remove tmp file
rm -f tmp
脚本二格式化指定的文件
#!/bin/sh
# 格式化指定的文件, 并将文件换行符转换成Linux下的格式
if [ $# -lt 1 ]; then
echo Usage: $0 file1 file2 file*.cpp ...
exit 1
fi
# format a source file(*.c, *.h, *.cpp, *.hh)
formatSrcfile()
{
dos2unix $1
indent -npro -nip -lp -npsl -npcs -i4 -ts4 -sob -l140 -ci4 -ss -nsaf -nsai -nsaw -bl -bli0 $1
rm -f $1~
}
for i in $*
do
formatSrcfile $i
done
因为indent的参数很多我这里用的格式不一定是所有人都喜欢的所以如果不符合您的要求请大家自己修改。 我这两个脚本都有一个bug一直没找到解决办法若有人解决了还望告知下。bug如下 就是上图左边的代码会被格式成右边的样子但是事实上对于左边这样的格式我希望他能保持不变不知如何修改indent参数呢? 另外如果一个宏单独一行且没有分号作结尾他会将下一行的内容给捞上来的哈哈