File indexing completed on 2025-01-26 05:13:48
0001 #!/bin/sh 0002 0003 oldname=$1 0004 newname=$2 0005 0006 if [ $# != 2 ]; then 0007 echo "Usage: $0 old_classname new_classname" 0008 exit 1 0009 fi 0010 0011 if [ -f $oldname.cpp ]; then 0012 oldfile=$oldname 0013 newfile=$newname 0014 else 0015 oldfile=`echo $oldname | tr A-Z a-z` 0016 newfile=`echo $newname | tr A-Z a-z` 0017 fi 0018 0019 findup() { 0020 parg="$1" 0021 _hit="" 0022 spwd="$PWD" 0023 if test -z "$parg"; then return 1; fi 0024 0025 while ! test -e "$parg"; do 0026 cd .. 0027 if test "$PWD" = "/"; then 0028 cd "$spwd" 0029 return 1 0030 fi 0031 done 0032 _hit="$PWD/$parg" 0033 cd "$spwd" 0034 } 0035 0036 my_mv() { 0037 _src="$1" 0038 _dest="$2" 0039 findup .svn 0040 if test -n "$_hit"; then 0041 svn mv "$_src" "$_dest" || mv "$_src" "$_dest" 0042 return 0043 fi 0044 findup .git 0045 if test -n "$_hit"; then 0046 git mv "$_src" "$_dest" || mv "$_src" "$_dest" 0047 return 0048 fi 0049 mv "$_src" "$_dest" 0050 } 0051 0052 0053 if [ ! -f $newfile.h ]; then 0054 if [ -f ${oldfile}.h ]; then 0055 my_mv $oldfile.h $newfile.h 0056 fi 0057 my_mv $oldfile.cpp $newfile.cpp 0058 if [ -f ${oldfile}_p.h ]; then 0059 my_mv ${oldfile}_p.h ${newfile}_p.h 0060 fi 0061 if [ -f ${oldfile}.ui ]; then 0062 my_mv ${oldfile}.ui ${newfile}.ui 0063 fi 0064 fi 0065 0066 # Update buildsystem 0067 if test -f CMakeLists.txt; then 0068 buildsystemfile=CMakeLists.txt 0069 else 0070 buildsystemfile=`ls -1 *.pro 2>/dev/null | head -n 1` 0071 fi 0072 if test -n "$buildsystemfile"; then 0073 perl -pi -e "s/\b$oldfile\.cpp/$newfile.cpp/;s/\b$oldfile\.h/$newfile\.h/;s/\b$oldfile\.ui/$newfile\.ui/" $buildsystemfile 0074 fi 0075 0076 # Rename class 0077 if [ -f ${newfile}.h ]; then 0078 perl -pi -e "s/$oldname/$newname/g" ${newfile}.h 0079 fi 0080 perl -pi -e "s/$oldname/$newname/g" $newfile.cpp 0081 if [ -f ${newfile}_p.h ]; then 0082 perl -pi -e "s/$oldname/$newname/g" ${newfile}_p.h 0083 fi 0084 if [ -f ${newfile}.ui ]; then 0085 perl -pi -e "s/$oldname/$newname/g" ${newfile}.ui 0086 fi 0087 0088 oldinclguard=`echo $oldname | tr a-z A-Z` 0089 newinclguard=`echo $newname | tr a-z A-Z` 0090 oldinclguard_lower=`echo $oldname | tr A-Z a-z` 0091 newinclguard_lower=`echo $newname | tr A-Z a-z` 0092 0093 # Update include guard 0094 if [ -f ${newfile}.h ]; then 0095 perl -pi -e "s/$oldinclguard/$newinclguard/g" $newfile.h 0096 perl -pi -e "s/$oldinclguard_lower/$newinclguard_lower/g" $newfile.h 0097 fi 0098 if [ -f ${newfile}_p.h ]; then 0099 perl -pi -e "s/$oldinclguard/$newinclguard/g" ${newfile}_p.h 0100 fi 0101 0102 # Update include in cpp file 0103 perl -pi -e 's/\b'$oldfile'\.h/'$newfile'\.h/;s/\b'$oldfile'_p\.h/'$newfile'_p\.h/' $newfile.cpp 0104