欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

Linux下代码中注释删除

程序员文章站 2022-06-27 19:06:02
#!/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