Warning, file /sdk/kde-dev-scripts/clean-forward-declaration.sh 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 # Laurent Montel <montel@kde.org> (2014)
0004 # cd <directory> ; ./clean-forward-declaration.sh 
0005 
0006 #list all .h files.
0007 list=`find -name '*.h' | egrep -v '(\.svn|build)'`;
0008  # list=`ls *.H | egrep -v '(\.svn|build)'`;
0009 for file in $list ; do
0010         #get class line (don't get it when we have "friend"/"template" or "public" word or *Private class)
0011         class=`echo "$file" | xargs grep "class" | egrep -v '(public|friend|template|Private)' `;
0012         if test ! -z "$class" ; then
0013                 echo "filename :$file";
0014                 #By default it's defined as "class Kurl;" => remove "class " and ";"
0015                 newval=`echo "$class" | perl -pi -e 's!class !!g'`;
0016                 newval=`echo "$newval" | perl -pi -e 's!;!!g'`;
0017                 
0018                 #need to have all class name => use awk to split string, separator is "\n";
0019                 splitline=`echo $newval | awk -F' ' 'END { for (i = 1 ; i <= NF ; i++) { tab[i] = $i ; print tab[i] } } '`;
0020                 for i in $splitline ; do
0021                         #Look at into file if there is multiple defined of class name => if number == 1 => it's not used
0022                         val=`echo "$file" | xargs grep "$i" | wc -l`;
0023                         if test "$val" = "1" ; then
0024                                 # Remove "class <classname>;" when it's not used
0025                                 perl -pi -e "s!^\s*class $i;\n!!" $file;        
0026                                 echo "$i is unique, we will remove it from file";
0027                         fi
0028                 done
0029         fi
0030 done
0031 #look at diff
0032 git diff .
0033