From d758f4b9cda67b37ee1452f3568cedf64ef8b16e Mon Sep 17 00:00:00 2001 From: Sylvain Thery Date: Tue, 20 Dec 2011 13:18:41 +0100 Subject: [PATCH] add script for app duplication update scripts --- scripts/README.TXT | 7 +++++ scripts/duplicate_apps.sh | 64 +++++++++++++++++++++++++++++++++++++++ scripts/skeleton_apps.sh | 23 ++++++++------ scripts/skeleton_test.sh | 4 +-- 4 files changed, 86 insertions(+), 12 deletions(-) create mode 100755 scripts/duplicate_apps.sh diff --git a/scripts/README.TXT b/scripts/README.TXT index 38dd5b91..79ee009d 100644 --- a/scripts/README.TXT +++ b/scripts/README.TXT @@ -12,4 +12,11 @@ This must be done in a CGoGN_Apps directory. It create an empty debug applicatio with only one source (no header, no ui, no Debug/Release) +duplicate_apps.sh: +Usage duplicate_apps src_dir dest_dir +Duplicate an application: + - files that have the name of directory src are changed to dst + - includes are modified to follow these changes + - Classes and vars in .h & .cpp file that have the name (with first + letter in uppercase) are changed with dst name diff --git a/scripts/duplicate_apps.sh b/scripts/duplicate_apps.sh new file mode 100755 index 00000000..1ae2b080 --- /dev/null +++ b/scripts/duplicate_apps.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +if test $# -lt 2; then + echo $0 application_directory_source application_directory_destination + exit 2 +fi + +if test -d $2; then + echo Directory $2 already exist + exit 3 +fi + +if test ! -d $1; then + echo Directory $1 does not exist + exit 4 +fi + + +echo "copying ..." +cp -r $1 $2 +echo "cleanin ..." + +cd $2 +find . -name "CMakeFiles" -exec rm -rf {} \; 2> /dev/null +find . -name "cmake_install.cmake" -exec rm -f {} \; 2> /dev/null +find . -name "CMakeCache.txt" -exec rm -f {} \; 2> /dev/null +find . -name "Makefile" -exec rm -f {} \; 2> /dev/null +cd bin +rm -rf * +cd .. + + +app1=`basename $1` +app2=`basename $2` +echo remplace $app1 by $app2 in CMakeLists.txt ... +find . -name "CMakeLists.txt" -exec sed -i s/$app1/$app2/g {} \; + +echo "renaming files:" +list_of_files=`find . -name $app1\*` + +for f in $list_of_files; do + nf=`echo $f | sed s/$app1/$app2/` + echo " "$f -\> $nf + mv $f $nf + # search into files for inclusion + bf=`basename $f` + bnf=`basename $nf` + list2=`fgrep -wl $bf *` +# if test -n """$list2"""; then +# echo " files to modify (includes)" $list2 + for xx in $list2; do + sed -i s/$bf/$bnf/g $xx + done +# fi +done + +echo Modify contents ... +find . -name "*.cpp" -o -name "*.hpp" -o -name "*.h" -exec sed -i s/${app1^}/${app2^}/g {} \; +find . -name "*.cpp" -exec sed -i s/${app1^}/${app2^}/g {} \; +find . -name "*.h" -exec sed -i s/${app1^}/${app2^}/g {} \; + + +echo finished + diff --git a/scripts/skeleton_apps.sh b/scripts/skeleton_apps.sh index bd8e7ae0..9c6d5017 100755 --- a/scripts/skeleton_apps.sh +++ b/scripts/skeleton_apps.sh @@ -1,12 +1,12 @@ #!/bin/bash if test $# -lt 1; then - echo $0 application_repertory [src_files] + echo $0 application_directory [src_files] exit 2 fi if test -d $PWD/$1; then - echo Repertory $1 already exist + echo Directory $1 already exist exit 3 fi @@ -64,7 +64,7 @@ echo link_directories\( \$\{CGoGN_ROOT_DIR\}/lib/Debug/ \$\{CGoGN_ROOT_DIR\}/lib echo "" >> CMakeLists.txt echo QT4_WRAP_UI\( ${apps}_ui \$\{CMAKE_SOURCE_DIR\}/${apps}.ui \) >> CMakeLists.txt echo QT4_WRAP_CPP\( ${apps}_moc \$\{CMAKE_SOURCE_DIR\}/${apps}.h \) >> CMakeLists.txt -echo "" >> CMakeLists.tx +echo "" >> CMakeLists.txt echo add_executable\( ${apps}D $sources >> CMakeLists.txt echo " " \$\{${apps}_moc\} >> CMakeLists.txt echo " " \$\{${apps}_ui\} \) >> CMakeLists.txt @@ -88,7 +88,7 @@ echo link_directories\( \$\{CGoGN_ROOT_DIR\}/lib/Release \$\{Boost_LIBRARY_DIRS\ echo "" >> CMakeLists.txt echo QT4_WRAP_UI\( ${apps}_ui \$\{CMAKE_SOURCE_DIR\}/${apps}.ui \) >> CMakeLists.txt echo QT4_WRAP_CPP\( ${apps}_moc \$\{CMAKE_SOURCE_DIR\}/${apps}.h \) >> CMakeLists.txt -echo "" >> CMakeLists.tx +echo "" >> CMakeLists.txt echo add_executable\( ${apps} $sources >> CMakeLists.txt echo " " \$\{${apps}_moc\} >> CMakeLists.txt echo " " \$\{${apps}_ui\} \) >> CMakeLists.txt @@ -128,12 +128,14 @@ echo \#include \"Utils/Qt/qtui.h\" >> ${apps}.h echo "" >> ${apps}.h echo "using namespace CGoGN;" >> ${apps}.h echo "" >> ${apps}.h -echo "class ${apps}: public Utils::QT::SimpleQT" >> ${apps}.h +echo "class ${apps^}: public Utils::QT::SimpleQT" >> ${apps}.h echo "{" >> ${apps}.h echo " Q_OBJECT" >> ${apps}.h echo "public:" >> ${apps}.h echo "" >> ${apps}.h -echo " ${apps}() {}" >> ${apps}.h +echo " ${apps^}() {}" >> ${apps}.h +echo "" >> ${apps}.h +echo " ~${apps^}() {}" >> ${apps}.h echo "" >> ${apps}.h echo " void cb_redraw();" >> ${apps}.h echo "" >> ${apps}.h @@ -186,10 +188,10 @@ echo "************************************************************************** echo "" >> ${apps}.cpp echo \#include \"${apps}.h\" >> ${apps}.cpp echo "" >> ${apps}.cpp -echo "void Interface::cb_initGL()" >> ${apps}.cpp +echo "void ${apps^}::cb_initGL()" >> ${apps}.cpp echo "{}" >> ${apps}.cpp echo "" >> ${apps}.cpp -echo "void Interface::cb_redraw()" >> ${apps}.cpp +echo "void ${apps^}::cb_redraw()" >> ${apps}.cpp echo "{}" >> ${apps}.cpp echo "" >> ${apps}.cpp @@ -197,7 +199,8 @@ echo "int main(int argc, char **argv)" >> ${apps}.cpp echo "{" >> ${apps}.cpp echo "" >> ${apps}.cpp echo " QApplication app(argc, argv);" >> ${apps}.cpp -echo " ${apps} sqt;" >> ${apps}.cpp +echo " ${apps^} sqt;" >> ${apps}.cpp +echo " "sqt.setWindowTitle\(\"${apps^}\"\)\; >> ${apps}.cpp echo "" >> ${apps}.cpp echo " Utils::QT::uiDockInterface dock;" >> ${apps}.cpp echo " sqt.setDock(&dock);" >> ${apps}.cpp @@ -238,7 +241,7 @@ echo " " >> ${apps}.ui echo " QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable" >> ${apps}.ui echo " " >> ${apps}.ui echo " " >> ${apps}.ui -echo " Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea" >> ${apps}.uit +echo " Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea" >> ${apps}.ui echo " " >> ${apps}.ui echo " " >> ${apps}.ui echo " Control" >> ${apps}.ui diff --git a/scripts/skeleton_test.sh b/scripts/skeleton_test.sh index af924f42..02239855 100755 --- a/scripts/skeleton_test.sh +++ b/scripts/skeleton_test.sh @@ -1,14 +1,14 @@ #!/bin/bash if test $# -lt 1; then - echo $0 application_repertory + echo $0 application_directory exit 2 fi echo "Warning do not forget to check the CGoGN_ROOT_DIR variable (ccmake)" if test -d $PWD/$1; then - echo Repertory $1 already exist + echo Directory $1 already exist exit 3 fi -- GitLab