给代码添加版权信息

版权声明:本文系作者原创。未经许可,不得转载。

以前写的代码没有加上版权信息。后来要全部添加,一个一个添加当然很慢,于是写了一个脚本自动添加。
基本思路:
1、列出目录下所有文件
2、得到后缀名,根据后缀名添加不同格式的信息。
脚本如下:AddCopyrightInformation/addInfoToAllFile.sh#!/bin/bash
[ "$1" ] || {echo "Usage: $0 /dir/path"exit 1
}_dir=$1filelist=`./script/getAllFile.sh $_dir`for file in $filelist
do    infotype=`./script/judgeInfoType.sh $file`    ./script/addToSingleFile.sh $file $infotype
doneAddCopyrightInformation/script/addToSingleFile.sh#!/bin/shfilepath=$1
infotype=$2if [ "$infotype"x = "asterisk"x ]; then                cat ./info/cppinfo.txt $filepath > $filepath.tmpmv $filepath.tmp $filepath
elif [ "$infotype"x = "octothorpe"x ]; then        cat ./info/shellinfo.txt $filepath > $filepath.tmpmv $filepath.tmp $filepath
elif [ "$infotype"x = "hyphen"x ]; then        cat ./info/xmlinfo.txt $filepath > $filepath.tmpmv $filepath.tmp $filepath
fiAddCopyrightInformation/script/getAllFile.sh
#!/bin/bash  nowdir=$1   
find $nowdir -type fAddCopyrightInformation/script/judgeInfoType.sh#!/bin/bash
[ "$1" ] || {echo "Usage: $0 filepath"exit 1
}filepath=$1filename=`basename $filepath`  
extensionname=${filename##*.}if [ "$extensionname"x = "cpp"x ]; thenecho "asterisk"
elif [ "$extensionname"x = "qml"x ]; thenecho "asterisk"
elif [ "$extensionname"x = "spec"x ]; thenecho "octothorpe"
elif [ "$extensionname"x = "h"x ]; thenecho "asterisk"
elif [ "$extensionname"x = "pro"x ]; thenecho "octothorpe"
elif [ "$extensionname"x = "pri"x ]; thenecho "octothorpe"  
elif [ "$extensionname"x = "js"x ]; thenecho "asterisk" 
fiAddCopyrightInformation/info/cppinfo.txt/*
  • This file is part of cmos-compositor
    *

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

  • Authors:

  • Peng Huaping

  • Xie Yan

  • Li Jing

  • Liu Jiawei

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

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

    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
    # Xie Yan
    # Li Jing
    # Liu Jiawei
    #
    # This software, including documentation, is protected by copyright controlled
    # by Beijing Yuan Xin Technology Co.,Ltd. All rights are reserved.
    #

    AddCopyrightInformation/info/xmlinfo.txt














    使用方式如下:

    1、将需要添加版权信息的源代码备份。
    2、进入到脚本目录,修改info目录下的三个txt文件,将文件中的模块名称和作者名称修改,保存退出。然后,执行脚本:

       cd AddCopyrightInformation./addInfoToAllFile.sh /home/simba/virtualshare/cmos-photos注:参数为需要添加版权信息的模块的目录,最好是绝对路径.

    3、程序执行完成之后,检查确认。

    注:新建的文件,可以使用IDE自动添加。


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部