zoukankan      html  css  js  c++  java
  • 头文件大小写问题的脚本解决方案

    linux的文件名是大小写敏感的,所以,我们要将代码中include的头文件大小写做个转换。

    手动修改——当我没说……

    用脚本去解决,之前我用perl写过这样功能的脚本,但是时间久远,我已经找不到了。

    简单分析一下,大概是一下几步

    1. 找到所有的被包含过的头文件,grep/sort/uniq
    2. 对每一个头文件,如果存在,则不处理
    3. 如果不存在,则忽略大小写find -iname,这样会有三种不同的结果,找不到,找到一个和找到多个,将结果分别记录在不同的文件,作为输出结果
    4. 对于找不到的,这个可能是系统文件,也可能是因为别的原因找不到,这需要一个一个的确认
    5. 对于找到一个的,简单的perl替换就可以了,或者sed?我喜欢perl
    6. 对于找到多个的,直接等待手工确认

    以上就简单处理了大部分的情况,就此打住,脚本么,简简单单的处理个七七八八就可以了。能处理的就要处理对,不能处理的就记录下来。

    根据以往的经验,在一个大而复杂的系统里面,这样的结果可能会出现找到多个的很多,这样就会很麻烦,但也没办法。

    一下是shell脚本,经测试,能工作。

    #!/bin/bash
    
    workdir=.
    modify=0
    
    while [ $# -gt 0 ]
    do
        case $1 in
        "--modify")
            modify=1
            ;;
        "--work-dir")
            shift
            workdir=$1
            ;;
        *)
            echo "USAGE: $0 [--work-dir <work-dir>] [--modify] [--help]"
            exit 1
        esac
        shift
    done
    
    echo "work-dir: $workdir, modify: $modify"
    
    h_files=$(tempfile)
    none_files=files_none
    ok_files=files_one
    more_files=files_more
    
    >$none_files
    >$ok_files
    >$more_files
    
    all_find=$(tempfile)
    deal_files=$(tempfile)
    
    grep -Prsh '^s*#s*include' $workdir | grep -Po 'w+.h' | sort | uniq | while read hfile
    do
        echo -n .
        if [ $(find $workdir -name "$hfile" | wc -l) -eq 0 ]
        then
            find $workdir -iname "$hfile" > $all_find
            cat $all_find | grep -Po 'w+.h$' | sort | uniq > $h_files
            file_cnt=$(cat $h_files | wc -l)
            if [ $file_cnt -eq 0 ]
            then
                echo $hfile >> $none_files
            elif [ $file_cnt -eq 1 ]
            then
                newfile=$(cat $h_files)
                echo $hfile '->' $newfile >> $ok_files
                cat $all_find >> $ok_files
                # for ok, deal it
                if [ $modify -eq 1 ]
                then
                    grep -Prsn "^s*#s*include.*$hfile" $workdir > $deal_files
                    if [ $(cat $deal_files | wc -l) -gt 0 ]
                    then
                        cat $deal_files | awk -F: '{print $1}' | xargs perl -i -pe "s/$hfile/$newfile/"
                        echo modified: >> $ok_files
                        cat $deal_files >> $ok_files
                    fi
                fi
            else
                echo -- $hfile -- >> $more_files
                cat $all_find >> $more_files
            fi
        fi
    done
    
    echo Done!
    echo the result in file: $none_files, $ok_files and $more_files
  • 相关阅读:
    openstack controller ha测试环境搭建记录(七)——配置glance
    openstack controller ha测试环境搭建记录(六)——配置keystone
    openstack controller ha测试环境搭建记录(五)——配置rabbitmq集群
    spring classpath & classpath*
    SVN相关
    eclipse安装springboot插件
    Hbase Shell常用命令
    CentOS下安装Hbase
    CentOS安装JDK-tar.gz文件
    Linux常用命令
  • 原文地址:https://www.cnblogs.com/sig3/p/3979668.html
Copyright © 2011-2022 走看看