用prel实现的文件头注释工具

最近想开源一套软件,对于一些代码都要在文件头上加上固定格式的版本信息。自己用perl写了一个小工具,拿出来分享。

  1 #!/usr/bin/perl -W
  2 #
  3 # Copyright (c) 2014 Nijie. All rights reserved.
  4 # License: GPL-2
  5 #
  6 # File: comments.pl  用于增加c/c++文件注释
  7 # Create by Nijie 2014.07.23
  8 #
  9
 10 use strict;
 11 use warnings;
 12 use File::Copy;
 13
 14 my $author=‘Nijie‘;            # 作者 - 需修改
 15 my $createyear=‘2014‘;        # 版权时间 - 需修改
 16 my $date="2014.07.23";        # 文件创建时间 - 需修改
 17
 18 # 以下版权信息 - 需修改
 19 my $comments="// Created by $author on $date.
 20 // Copyright (c) $createyear $author. All rights reserved.
 21 // Use of this source code is governed by a GPL-2 license that can be found in the LICENSE file.
 22 //
 23 ";
 24
 25 my @filterDir = ("./lib3rd/");    # 需要过滤的文件,比如不属于你开发的目录等 - 需修改
 26
 27 my %filterList = ();
 28 foreach (@filterDir)
 29 {
 30     $filterList{$_} = 1;
 31 }
 32
 33 my ($dircnt, $filecnt) = (0, 0);
 34
 35 sub lsr_s($) {
 36     my $cwd = shift;
 37     my @dirs = ($cwd.‘/‘);
 38
 39     my ($dir, $file);
 40     while ($dir = pop(@dirs)) {
 41         if (exists($filterList{$dir}))
 42         {
 43             print "skip dir : $dir\n";
 44             next;
 45         }
 46         local *DH;
 47         print "open $dir\n";
 48         if (!opendir(DH, $dir)) {
 49             warn "Cannot opendir $dir: $! $^E";
 50             next;
 51         }
 52         foreach (readdir(DH)) {
 53             if ($_ eq ‘.‘ || $_ eq ‘..‘) {
 54                 next;
 55             }
 56             $file = $dir.$_;
 57             if (!-l $file && -d _) {
 58                 $file .= ‘/‘;
 59                 push(@dirs, $file);
 60             }
 61             process($file, $dir);
 62         }
 63         closedir(DH);
 64     }
 65 }
 66
 67 sub process($) {
 68     my $file = shift;
 69     print "process $file";
 70     if (substr($file, length($file)-1, 1) eq ‘/‘) {
 71         $dircnt++;
 72     }
 73     else {
 74         $filecnt++;
 75         if ($file =~ /\.(h$|c$|cpp$|hpp$|cc$)/)
 76         {
 77             addComments($file);
 78         }
 79     }
 80     print "\n";
 81 }
 82
 83 sub addComments($)
 84 {
 85     my $line = 0;
 86     my $file = shift;
 87     open FILE, $file or die ‘die ($!)‘;
 88     open OUTFILE, ">$file~~~" or die "Open the file $file~~~ failed!\n";
 89
 90     print OUTFILE $comments;
 91     while (<FILE>)
 92     {
 93         print OUTFILE $_;
 94     }
 95     close FILE;
 96     close OUTFILE;
 97     move("$file~~~", $file);
 98 }
 99
100 lsr_s(‘.‘);
101 print "$filecnt files, $dircnt directory.\n";
102 `pause`;

用prel实现的文件头注释工具

时间: 2024-08-16 01:11:51

用prel实现的文件头注释工具的相关文章

VA中用文件头注释和函数头注释Suggestions

写C++代码,不能不用VA,这里贴两个我最常用的注释Suggestions. [1.File Header 文件头注释] /*** @file     $FILE_BASE$.$FILE_EXT$* @brief    * @details  * @author   [email protected]* @date     $YEAR$-$MONTH$-$DAY$*/$end$ [2.Function Header 函数头注释] /*** @brief   $end$* @param   $Me

Eclipse中java文件头注释格式设置

Eclipse中java文件头注释格式设置 Eclipse中java文件头注释格式设置 windows->preferences->java->Code Templates->comments->Type->edit Eclipse注释规范模版总结 新建类文件 /** * @ClassName:     ${file_name} * @Description:   ${todo}(用一句话描述该文件做什么) * * @author          ${user} * 

Pycharm在创建py文件时,自动添加文件头注释

操作如上图所示,一般输入的注释为:

myeclipse中java文件头注释格式设置

windows->preferences->java->Code Templates->comments->Type->edit Eclipse注释规范模版总结 新建类文件 /** * @ClassName:     ${file_name} * @Description:   ${todo}(用一句话描述该文件做什么) * * @author         ${user} * @version        V1.0 * @Date           ${date

Pycharm如何自动添加默认文件头注释

Pycharm在编写Python时,创建一个.py文件时,经常需要在文件中添加头文件注释信息.如下图中: 但是每个新添加的文件中都去输入头文件注释信息,还是繁琐的.其实可以通过配置自动生成,按照如下进入设置: File -> settings -> Editor -> File and Code Templates -> Python Script 在文本框中输入如下信息: #!/usr/bin/env python# -*- coding: utf-8 -*-# @Time :

Pycharm在创建py文件时,如何自动添加文件头注释(类似于钩子特性)?

File->settings->Editor->File and Code Templates->Python Script 添加以下代码: #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : ${DATE} ${TIME} # @Author : Aries # @Site : ${SITE} # @File : ${NAME}.py # @Software: ${PRODUCT_NAME} https://segmen

pycharm在创建py文件时,自动添加文件头注释

File -> settings -> Editor-> File and Code Templates -> Python Script 添加内容: #!/usr/bin/env python # -*- coding: utf-8 -*- """ Time : ${DATE} ${TIME} Author : x File : ${NAME}.py Software: ${PRODUCT_NAME} """

Pycharm自动添加文件头注释

1.选择File -> Settings 2.选择 File and Code Templates -> Files -> Python Script 3.设置 #!/usr/bin/env python # encoding: utf-8 ''' @author: mrwuzs @file: ${NAME}.py @time: ${DATE} ${TIME} @desc: '''

pycharm添加文件头注释

1. 进入setting -> File and Code Templates -> Python Script 2.代码头部分 写入 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : ${DATE} ${TIME} # @Author : Yellow_huang # @Email : [email protected] # @File : ${NAME}.py 3.新建脚本就会出现下面的效果 #!/usr/bin/env pyt