Linux下代码中注释删除
程序员文章站
2022-04-07 17:55:57
#!/bin/bash# ------------------------------------------------------------# name: delete_code_note.sh# version: 1.0# createTime: 2018-07-27# description: 代码注释删除# ------------------------------------------------------------#删除拷贝代码的注释....
#!/bin/bash
# ------------------------------------------------------------
# name: delete_code_note.sh
# version: 1.0
# createTime: 2018-07-27
# description: 代码注释删除
# ------------------------------------------------------------
#删除拷贝代码的注释
function del_comment_file()
{
sed -i "/^[ \t]*\/\//d" $file
sed -i "s/\/\/[^\"]*//" $file
sed -i "s/\/\*.*\*\///" $file
sed -i "/^[ \t]*\/\*/,/.*\*\//d" $file
}
#删除代码中的“other/"字符
function del_other_file()
{
sed -i "s/other\///" $file
}
function del_comment()
{
for file in `ls `; do
case $file in
*.c)
del_comment_file
#del_other_file
;;
*.cpp)
del_comment_file
#del_other_file
;;
*.h)
del_comment_file
#del_other_file
;;
*.ui)
#del_other_file
;;
*)
if [ -d $file ]; then
cd $file
del_comment
cd ..
fi
;;
esac
done
}
#获取源代码文件夹位置
code_dir=$1
if [ ! -e $code_dir ]; then
echo "The file or directory does not exist."
exit 1;
fi
if [ -f $code_dir ]; then
file=`basename $code_dir`
if [[ `echo $code_dir | grep /` == $code_dir ]]; then
cd `echo $code_dir | sed -e "s/$file//"`
del_comment_file
else
del_comment_file
fi
exit 0;
fi
if [ -d $code_dir ]; then
cd $code_dir
del_comment
exit 0;
fi
本文地址:https://blog.csdn.net/zx547326zx/article/details/107321576