Skip to content

Update fixInludesCase.sh #520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions scripts/cpp/fixInludesCase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ Details:
Script tries to find included file in include paths. (first relative to source
file's directory, then in specified include paths). First it tries
case-sensitive search in all paths. If that fails, it tries case-insensitive
search in all include paths (excpet for nofix paths). If it succseeds, it fixes
filename in include directory as necessary. If it fails no change is done.
search in all include paths (except for nofix paths). If it succeeds, it fixes
filename in include directory as necessary. If it fails, no change is done.
Slashes are fixed either way, if necessary ( \\ -> / ).

Limitations:
Expand All @@ -43,14 +43,14 @@ except for fixing slashes.
OPTIONS:
-I [PATH]
--include-path [PATH]
include path, where to search included files. Also used to fix filename
Include path, where to search included files. Also used to fix filename
case as necessary, if possible. This argument can be specified
more than once.

-N [PATH]
--include-paths-nofix [PATH]
similar include-path, but files here are not considered when trying to fix
case (only in search, if file exists) This argument can be specified
Similar include-path, but files here are not considered when trying to fix
case (only in search, if file exists). This argument can be specified
more than once.
EOF
exit 0
Expand All @@ -63,39 +63,39 @@ ignoredIncludes=""
fixFile() {
file="$1"
regex='^[[:space:]]*#[[:space:]]*include[[:space:]]*["<](.*[.][hH])[">].*$'
includeLines="$( cat "$file" | grep -E "$regex" )" || :
includeLines="$(grep -E "$regex" "$file")" || :
if [ -z "${includeLines}" ] ; then
return
fi
dir="$(dirname "${file}" )"

printf "%s\n" "${includeLines}" | while IFS='' read -r includeL ; do
includeOrig="$( echo "$includeL" | sed -E "s;${regex};\\1;g" )"
include="$( echo "$includeOrig" | sed -E 's;\\+;/;g' )"
includeOrig="$(echo "$includeL" | sed -E "s;${regex};\\1;g")"
include="$(echo "$includeOrig" | sed -E 's;\\+;/;g')"

if echo "${ignoredIncludes:-}" | grep -qi "^${include}\$" ; then
continue
fi
found=0
for path in "$( dirname "${file}" )" ${includePaths:-} ${includePathsNofix:-} ; do
for path in "$(dirname "${file}")" ${includePaths:-} ${includePathsNofix:-} ; do
if [ -e "${path}/${include}" ] ; then
found=1
break
fi
done
includeOrigEscaped="$( echo "${includeOrig}" | sed 's;\\;[\\];g' )"
includeOrigEscaped="$(echo "${includeOrig}" | sed 's;\\;[\\];g')"
updated=0
if [ $found -eq 0 ]; then
echo "Srcfile: ${file}"
echo "missing: ${include}"

includeLower="$( echo "${include}" | tr '[:upper:]' '[:lower:]' )"
for path in "$( dirname "${file}" )" ${includePaths:-} ; do
for testedFile in $( find "${path}" -iname "$( basename "${include}" )" ) ; do
testedLower="$( echo "${testedFile}" | tr '[:upper:]' '[:lower:]' )"
includeLower="$(echo "${include}" | tr '[:upper:]' '[:lower:]')"
for path in "$(dirname "${file}")" ${includePaths:-} ; do
for testedFile in $(find "${path}" -iname "$(basename "${include}")") ; do
testedLower="$(echo "${testedFile}" | tr '[:upper:]' '[:lower:]')"
if echo "${testedLower}" | grep -q "${includeLower}\$" ; then
fixed="${testedFile#${path}/}"
fixedLower="$( echo "$fixed" | tr '[:upper:]' '[:lower:]' )"
fixedLower="$(echo "$fixed" | tr '[:upper:]' '[:lower:]')"
if [ "${includeLower}" = "${fixedLower}" ] ; then
echo "fix: ${testedFile#${path}/}"
updated=1
Expand Down Expand Up @@ -132,16 +132,16 @@ main() {
printHelp
;;
-I|--include-path)
includePaths="$( printf '%s\nx' "${includePaths:-}$2" )"
includePaths="$(printf '%s\nx' "${includePaths:-}$2")"
includePaths="${includePaths%x}" # to keep newline
shift;
shift;
shift
shift
;;
-N|--include-paths-nofix)
includePathsNofix="$( printf '%s\nx' "${includePathsNofix:-}$2" )"
includePathsNofix="$(printf '%s\nx' "${includePathsNofix:-}$2")"
includePathsNofix="${includePathsNofix%x}" # to keep newline
shift;
shift;
shift
shift
;;
*)
printf "SRC_DIR:\n%s\n" "$@"
Expand All @@ -153,7 +153,7 @@ main() {
fi
echo
fixTree "$@"
break;
break
;;
esac
done
Expand Down