Script solution for case-insensitive header files

Source: Internet
Author: User

Linux File names are case sensitive. Therefore, we need to convert the case sensitivity of the include header file in the code.

Manually modify -- when I did not say ......

I used scripts to solve this problem. I used Perl to write such a script. However, for a long time, I cannot find it.

A brief analysis is a few steps.

  1. Find all included header files, grep/sort/uniq
  2. For each header file, if it exists, it is not processed
  3. If this parameter does not exist, the case-insensitive find-INAME is ignored. In this case, there are three different results. If no result is found, one or more results are found, and the results are recorded in different files as output results.
  4. If the file cannot be found, it may be a system file, or it may not be found for other reasons. One by one confirmation is required.
  5. If you find one, you can simply replace Perl with it, or SED? I like Perl.
  6. For multiple items found, wait for manual confirmation.

The above is a simple process for most of the cases, so we can simply process the scripts in seven to eight. If it can be processed, it must be processed. If it cannot be processed, it should be recorded.

Based on past experience, in a large and complex system, such results may be found in many ways, which is very troublesome, but there is no way.

The following is a shell script that can work after testing.

#!/bin/bashworkdir=.modify=0while [ $# -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    shiftdoneecho "work-dir: $workdir, modify: $modify"h_files=$(tempfile)none_files=files_noneok_files=files_onemore_files=files_more>$none_files>$ok_files>$more_filesgrep -Prsh ‘^\s*#\s*include‘ $workdir | grep -Po ‘\w+\.h‘ | sort | uniq | while read hfiledo    echo -n .    if [ $(find $workdir -name "$hfile" | wc -l) -eq 0 ]    then        find $workdir -iname "$hfile" | 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            # for ok, deal it            if [ $modify -eq 1 ]            then                grep -Pril "\b$hfile\b" $workdir | xargs perl -i -pe "s/\b$hfile\b/$newfile/"            fi        else            echo -- $hfile -- >> $more_files            cat $h_files >> $more_files        fi    fidoneecho Done!echo the result in file: $none_files, $ok_files and $more_files

 

Script solution for case-insensitive header files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.