File: c%2B%2B-copy-class-and-file

package info (click to toggle)
kde-dev-scripts 4%3A18.08.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,496 kB
  • sloc: perl: 15,466; lisp: 5,627; sh: 4,157; python: 3,892; ruby: 2,158; makefile: 16; sed: 9
file content (56 lines) | stat: -rwxr-xr-x 1,408 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/sh

if [ $# != 2 ]; then
    echo "Usage: $0 old_classname new_classname"
    exit 1
fi

oldname=$1
newname=$2

oldfile=`echo $oldname | tr A-Z a-z`
newfile=`echo $newname | tr A-Z a-z`

echo "Copying $oldfile.{cpp,h} to $newfile.{cpp,h}"

if [ ! -f $newfile.h ]; then
    cp $oldfile.h $newfile.h
    cp $oldfile.cpp $newfile.cpp
    if [ -f ${oldfile}_p.h ]; then
        cp ${oldfile}_p.h ${newfile}_p.h
    fi

    git add $newfile.h
    git add $newfile.cpp
    if [ -f ${newfile}_p.h ]; then
        git add ${newfile}_p.h
    fi
fi

# Update build system
if test -f CMakeLists.txt; then
    buildsystemfile=CMakeLists.txt
else
    buildsystemfile=`ls -1 *.pro 2>/dev/null | head -n 1`
fi
if test -n "$buildsystemfile"; then
    perl -pi -e '$_ .= "$1'$newfile.cpp'\n" if (m/^(\s*)'$oldfile'\.cpp/)' $buildsystemfile
    perl -pi -e '$_ .= "$1'$newfile.h'\n" if (m/^(\s*)'$oldfile'\.h/)' $buildsystemfile
fi

# Rename class
perl -pi -e "s/$oldname/$newname/g" $newfile.h $newfile.cpp
if [ -f ${newfile}_p.h ]; then
    perl -pi -e "s/$oldname/$newname/g" ${newfile}_p.h
fi

oldinclguard=`echo $oldname | tr a-z A-Z`
newinclguard=`echo $newname | tr a-z A-Z`

# Update include guard
perl -pi -e "s/$oldinclguard/$newinclguard/g" $newfile.h

# Update includes in cpp file
perl -pi -e 's/\b'$oldfile'\.h/'$newfile'\.h/' $newfile.cpp
perl -pi -e 's/\b'$oldfile'\.moc/'$newfile'\.moc/' $newfile.cpp