給代碼添加版權信息

版權聲明:本文系做者原創。未經許可,不得轉載。shell

之前寫的代碼沒有加上版權信息。後來要所有添加,一個一個添加固然很慢,因而寫了一個腳本自動添加。
基本思路:
一、列出目錄下全部文件
二、獲得後綴名,根據後綴名添加不一樣格式的信息。
腳本以下:

AddCopyrightInformation/addInfoToAllFile.sh

#!/bin/bash
[ "$1" ] || {
        echo "Usage: $0 /dir/path"
        exit 1
}

_dir=$1

filelist=`./script/getAllFile.sh $_dir`

for file in $filelist
do    
    infotype=`./script/judgeInfoType.sh $file`    
    ./script/addToSingleFile.sh $file $infotype
done


AddCopyrightInformation/script/addToSingleFile.sh

#!/bin/sh

filepath=$1
infotype=$2

if [ "$infotype"x = "asterisk"x ]; then                
    cat ./info/cppinfo.txt $filepath > $filepath.tmp
    mv $filepath.tmp $filepath
elif [ "$infotype"x = "octothorpe"x ]; then        
    cat ./info/shellinfo.txt $filepath > $filepath.tmp
    mv $filepath.tmp $filepath
elif [ "$infotype"x = "hyphen"x ]; then        
    cat ./info/xmlinfo.txt $filepath > $filepath.tmp
    mv $filepath.tmp $filepath
fi


AddCopyrightInformation/script/getAllFile.sh
#!/bin/bash  
  
nowdir=$1   
find $nowdir -type f


AddCopyrightInformation/script/judgeInfoType.sh

#!/bin/bash
[ "$1" ] || {
        echo "Usage: $0 filepath"
        exit 1
}

filepath=$1

filename=`basename $filepath`  
extensionname=${filename##*.}

if [ "$extensionname"x = "cpp"x ]; then
       echo "asterisk"
elif [ "$extensionname"x = "qml"x ]; then
       echo "asterisk"
elif [ "$extensionname"x = "spec"x ]; then
       echo "octothorpe"
elif [ "$extensionname"x = "h"x ]; then
       echo "asterisk"
elif [ "$extensionname"x = "pro"x ]; then
       echo "octothorpe"
elif [ "$extensionname"x = "pri"x ]; then
       echo "octothorpe"  
elif [ "$extensionname"x = "js"x ]; then
       echo "asterisk" 
fi

AddCopyrightInformation/info/cppinfo.txt

/*
  • This file is part of cmos-compositor
    *api

  • Copyright (C) 2014 Beijing Yuan Xin Technology Co.,Ltd. All rights reserved.
    *bash

  • Authors:code

  • Peng Huaping <penghuaping@syberos.com>orm

  • Xie Yan <xieyan@syberos.com>xml

  • Li Jing <lijing@syberos.com>ip

  • Liu Jiawei <liujiawei@syberos.com>get

  • This software, including documentation, is protected by copyright controlledit

  • by Beijing Yuan Xin Technology Co.,Ltd. All rights are reserved.
    */io

    AddCopyrightInformation/info/shellinfo.txt

    #
    # This file is part of cmos-compositor
    #
    # Copyright (C) 2014 Beijing Yuan Xin Technology Co.,Ltd. All rights reserved.
    #
    # Authors:
    # Peng Huaping <penghuaping@syberos.com>
    # Xie Yan <xieyan@syberos.com>
    # Li Jing <lijing@syberos.com>
    # Liu Jiawei <liujiawei@syberos.com>
    #
    # This software, including documentation, is protected by copyright controlled
    # by Beijing Yuan Xin Technology Co.,Ltd. All rights are reserved.
    #

    AddCopyrightInformation/info/xmlinfo.txt

    <!-- -->
    <!-- This file is part of cmos-compositor -->
    <!-- -->
    <!-- Copyright (C) 2014 Beijing Yuan Xin Technology Co.,Ltd. All rights reserved. -->
    <!-- -->
    <!-- Authors: -->
    <!-- Peng Huaping <penghuaping@syberos.com> -->
    <!-- Xie Yan <xieyan@syberos.com> -->
    <!-- Li Jing <lijing@syberos.com> -->
    <!-- Liu Jiawei <liujiawei@syberos.com> -->
    <!-- -->
    <!-- This software, including documentation, is protected by copyright controlled -->
    <!-- by Beijing Yuan Xin Technology Co.,Ltd. All rights are reserved. -->
    <!-- -->

    使用方式以下:

    一、將須要添加版權信息的源代碼備份。
    二、進入到腳本目錄,修改info目錄下的三個txt文件,將文件中的模塊名稱和做者名稱修改,保存退出。而後,執行腳本:

    cd AddCopyrightInformation
       ./addInfoToAllFile.sh /home/simba/virtualshare/cmos-photos
       注:參數爲須要添加版權信息的模塊的目錄,最好是絕對路徑.

    三、程序執行完成以後,檢查確認。

    注:新建的文件,能夠使用IDE自動添加。

相關文章
相關標籤/搜索