zoukankan      html  css  js  c++  java
  • 一段用来清除C++/C代码中空白行的perl脚本

    用Umbrello自动生成框架之后,里面有很多临时用不着的空行,而且生成的头文件都是单词开头大写字母,但是到了内部的#include就成了小写,于是写了个脚本解决这个问题

    对于#ifndef..#define .. #endif在 #define行之后及 #endif行之前会各加一个空行

    perl对我而言是救急语言,写的草率,将就着用吧……

    使用:

    ls *.cpp *.h|./changeFile.pl

    #!/usr/bin/perl -w
    #TO DO:
    #replace all header includes which are in lowercase
    #remove all blank lines
    #among all the .cpp files in the argument list

    @headers= qw/ActThread.h InvalidSettingsException.h PacketHeader.h QString.h QObject.h QThread.h SniffThread.h DialogManager.h LuaSetDialog.h PacketList.h Thread.h Exception.h LuaSettings.h SetDialog.h ThreadManager.h HttpSetDialog.h LuaThread.h Settings.h HttpSettings.h MainWindow.h SniffSetDialog.h HttpThread.h Packet.h SniffSettings.h/;
    sub editFile {
    $fileName=$_[0];
    $tmpFileName=$fileName.".tmp";
    if($fileName ne "." && $fileName ne "..") {
    if(! open READFILE,$fileName) {
    die "Cannot open file";
    }
    if(! open TMPFILE,">".$tmpFileName) {
    die "Cannot create file";
    }
    print "File Name :".$fileName."\n";
    while(<READFILE>) {
    if(/^\n/) {
    #print "BlankLine";
    }else{
    $line=$_;
    if(!/_H/) {
    foreach $headerFile (@headers) {
    if(/($headerFile)/i){
    $line=~s/$1/$headerFile/;
    }
    }
    }
    if(/endif/){ print TMPFILE "\n";}
    print TMPFILE $line;
    if(/define/){ print TMPFILE "\n";}
    }
    }
    close READFILE;
    close TMPFILE;
    `rm $fileName`;
    `mv $tmpFileName $fileName`;
    }
    }
    while(<>){
    chomp($_);
    editFile($_);
    }



  • 相关阅读:
    编译 | 更新标准库_交叉编译工具链
    论文 | 图文_学科
    编码 | 二进制格式设计方案
    图片 | 图片上传管理
    进程 | 查询进程中包含多少线程
    第二周02:Fusion ICP逐帧融合
    exe文件当前目录搜索文件
    第一周:读取XML深度数据并将其重建为三维点云
    第二周:01 ICP迭代交互
    C++文件读写(转载)
  • 原文地址:https://www.cnblogs.com/qianyuming/p/2312760.html
Copyright © 2011-2022 走看看