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.
- Find all included header files, grep/sort/uniq
- For each header file, if it exists, it is not processed
- 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.
- 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.
- If you find one, you can simply replace Perl with it, or SED? I like Perl.
- 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