给代码添加版权信息

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


    以前写的代码没有加上版权信息。后来要全部添加,一个一个添加当然很慢,于是写了一个脚本自动添加。
基本思路:
1、列出目录下所有文件
2、得到后缀名,根据后缀名添加不同格式的信息。
脚本如下:

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
    *

  • 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/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. -->
    <!-- -->

    使用方式如下:

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

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

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

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


辛巴
it男
256 声望
4 粉丝
0 条评论
推荐阅读
mac下编译go-ethereum
macos: 10.14.4 下载go-ethereum源码,按照文档执行命令编译: $ make all 报错:fatal error: 'stdlib.h' file not found /usr/include 查看xcode是否安装: $ xcode-select --install xcode-select: error: com...

lansheng2282阅读 3.3k

`hadoop fs -mkdir <path>` 创建的目录位置
linux创建文件夹命令mkdir 绝对路径 {代码...} mkdir 相对路径 {代码...} hadoop创建文件夹命令hadoop fs -mkdir 绝对路径 {代码...} hadoop fs -mkdir 相对路径 {代码...} [链接]

guyu阅读 634

Flink start-cluster.sh
关键的函数 TMWorkers(启动TaskManager)、readMasters(读取masters信息)、readWorkers(读取worker信息),定义了一些环境变量

journey阅读 576

MySQL和MongoDB如何JOIN查询?一个直接在本地运行的SQL执行引擎
在微服务和云原生愈发流行的今天,数据的分布也愈发脱离单库单机而更加复杂,使用的数据库类型也会更多,但业务的复杂依然会带来了大量的数据查询和导出需求,而很多时候我们很难为数据量的大部分系统创建完整的B...

snower阅读 415

Shell在日常工作中的应用实践
作者:京东物流 李光新1 Shell可以帮我们做什么作为一名测试开发工程师,在与linux服务器交互过程中,大都遇到过以下这些问题:•一次申请多台服务器,多台服务器需要安装相同软件,配置相同的环境,同样的操作需...

京东云开发者阅读 367

封面图
Linux7上安装Oracle RAC 19C一键配置脚本(后续补充其他版本)
Linux7上安装Oracle RAC 19C一键配置脚本(后续补充其他版本) {代码...}

特立独行阅读 317

shell相关
关于引号""**字符串作为参数字符串作为参数,输送给函数、executable、builtin等。 . 如果参数不加"" ,则shell会按照空白符(空格,换行等),分割为多个参数。 . 如果加"",则整体作为一个参数。

黑暗森林阅读 302

256 声望
4 粉丝
宣传栏