Warning, file /sdk/kde-dev-scripts/c++-copy-class-and-file was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 #!/bin/sh
0002 
0003 if [ $# != 2 ]; then
0004     echo "Usage: $0 old_classname new_classname"
0005     exit 1
0006 fi
0007 
0008 oldname=$1
0009 newname=$2
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 echo "Copying $oldfile.{cpp,h} to $newfile.{cpp,h}"
0020 
0021 if [ ! -f $newfile.h ]; then
0022     cp $oldfile.h $newfile.h
0023     cp $oldfile.cpp $newfile.cpp
0024     if [ -f ${oldfile}_p.h ]; then
0025         cp ${oldfile}_p.h ${newfile}_p.h
0026     fi
0027 
0028     git add $newfile.h
0029     git add $newfile.cpp
0030     if [ -f ${newfile}_p.h ]; then
0031         git add ${newfile}_p.h
0032     fi
0033     if [ -f ${newfile}.ui ]; then
0034         git add ${newfile}.ui
0035     fi
0036 fi
0037 
0038 # Update build system
0039 if test -f CMakeLists.txt; then
0040     buildsystemfile=CMakeLists.txt
0041     separator=
0042 else
0043     buildsystemfile=`ls -1 *.pro 2>/dev/null | head -n 1`
0044     separator=' \\'
0045 fi
0046 if test -n "$buildsystemfile"; then
0047     perl -pi -e '$_ .= "$1'$newfile.cpp"$separator"'\n" if (m/^(\s*)'$oldfile'\.cpp/)' $buildsystemfile
0048     perl -pi -e '$_ .= "$1'$newfile.h"$separator"'\n" if (m/^(\s*)'$oldfile'\.h/)' $buildsystemfile
0049     perl -pi -e '$_ .= "$1'$newfile.ui"$separator"'\n" if (m/^(\s*)'$oldfile'\.ui/)' $buildsystemfile
0050 fi
0051 
0052 # Rename class
0053 perl -pi -e "s/$oldname/$newname/g" $newfile.h $newfile.cpp
0054 if [ -f ${newfile}_p.h ]; then
0055     perl -pi -e "s/$oldname/$newname/g" ${newfile}_p.h
0056 fi
0057 if [ -f ${newfile}.ui ]; then
0058     perl -pi -e "s/$oldname/$newname/g" ${newfile}.ui
0059 fi
0060 
0061 oldinclguard=`echo $oldname | tr a-z A-Z`
0062 newinclguard=`echo $newname | tr a-z A-Z`
0063 
0064 # Update include guard
0065 perl -pi -e "s/$oldinclguard/$newinclguard/g" $newfile.h
0066 
0067 # Update includes in cpp file
0068 perl -pi -e 's/\b'$oldfile'\.h/'$newfile'\.h/' $newfile.cpp
0069 perl -pi -e 's/\b'$oldfile'\.moc/'$newfile'\.moc/' $newfile.cpp
0070