File indexing completed on 2024-04-21 05:41:59
0001 ## kDebug2kDebug.sh 0002 ## Script to port from qDebug, kdebug, kDebugInfo etc. to kDebug/kWarning/... 0003 ## Example: 0004 ## kDebugInfo( [area,] "format %a - %b", arga, argb ) 0005 ## becomes 0006 ## kDebug( [area] ) << "format " << arga << " - " << argb << endl; 0007 ## 0008 ## Written by David Faure <faure@kde.org>, licensed under GPL. 0009 ## 17/03/2000 0010 0011 find $1 -name '*[cCph]' -type f | xargs grep -H -i 'ebug(\|warning(' \ 0012 | grep -v 'kDebug\|kWarning' \ 0013 | grep -v include \ 0014 | sed -e "s#:.*##" \ 0015 | sort -u \ 0016 | while read file; do 0017 echo -n "working on $file " 0018 cp $file $file.tmp 0019 perl -w -i -e \ 0020 ' 0021 $inkdebug=0; 0022 while (<>) 0023 { 0024 if ( $inkdebug ) 0025 { 0026 chop; 0027 #print "Reading line : " . $_ . "\n"; 0028 $statement .= $_; 0029 } 0030 elsif ( /kdebug\s*\(/ || /kDebug[a-zA-Z]*\s*\(/ || /qDebug\s*/ || /qWarning\s*/ ) 0031 { 0032 # Very old kdebug stuff :) 0033 s/kdebug\s*\(\s*KDEBUG_INFO,/kDebugInfo\(/; 0034 s/kdebug\s*\(\s*0,/kDebugInfo\(/; 0035 s/kdebug\s*\(\s*KDEBUG_WARN,/kDebugWarning\(/; 0036 s/kdebug\s*\(\s*KDEBUG_ERROR,/kDebugError\(/; 0037 s/kdebug\s*\(\s*KDEBUG_FATAL,/kDebugFatal\(/; 0038 0039 $inkdebug = 1; 0040 chop; 0041 $statement = $_; 0042 } 0043 0044 if ( $inkdebug ) 0045 { 0046 if ( /\)\s*;/ ) # look for ); 0047 { 0048 $inkdebug = 0; 0049 $_ = $statement; 0050 ## Ok, now we have the full line 0051 ## 1 - Parse 0052 if (s/(^.*kDebug[a-zA-Z]*)\s*\(\s*//) { 0053 $line=$1; # has the indentation, //, and the kDebug* name 0054 } elsif (s/(^.*qDebug)\s*\(\s*// || s/(^.*qWarning)\s*\(\s*//) { 0055 $line=$1; 0056 } else { die "parse error on kDebug/qDebug/qWarning..."; } 0057 $line=$1; # has the indentation, //, and the kDebug* name 0058 $line =~ s/kDebugInfo/kDebug/; 0059 $line =~ s/kDebugArea/kDebug/; 0060 $line =~ s/qDebug/kDebug/; 0061 $line =~ s/qWarning/kWarning/; 0062 $line =~ s/kDebugWarning/kWarning/; 0063 $line =~ s/kDebugError/kError/; 0064 $line =~ s/kDebugFatal/kFatal/; 0065 $area = ""; 0066 if ( s/^([0-9]+)\s*,\s*//) # There is an area 0067 { 0068 $area = $1; # Store it 0069 $line .= "(" . $area . ")"; 0070 } elsif ( s/^(KBABEL[^,]*)\s*,\s*//) 0071 { # Example of support for #defined area (here KBABEL.*) 0072 $area = $1; # Store it 0073 $line .= "(" . $area . ")"; 0074 } else 0075 { $line .= "()"; } # You can set an area here if converting qDebugs 0076 0077 $arguments = ""; # for final test 0078 $commented = 0; 0079 if ( !s/^\"([^\"]*)\"// ) # There is no format 0080 { 0081 s/\s*\)\s*;\s*$//; 0082 $commented = s/\s*\)\s*;\s*\*\/$//; # terminating with */ 0083 $line = $line . " << " . $_ ; 0084 } else 0085 { 0086 $format = $1; 0087 # If we stopped on a \" we need to keep adding to format 0088 while ( $format =~ m/\\$/ ) 0089 { s/^([^\"]*)\"// || die "problem"; $format .= "\"" . $1; } 0090 s/\s*\)\s*;\s*$/,/; # replace trailing junk with , for what follows 0091 $commented = s/\s*\)\s*;\s*\*\/$/,/; # terminating with */ 0092 $arguments = $_; 0093 0094 ## 2 - Look for %x 0095 @stringbits = split( "(%[0-9]*[a-z])", $format ); 0096 foreach ( @stringbits ) 0097 { 0098 #print $_ . "\n"; 0099 if ( /(%[0-9]*[a-z])/ ) # This item is a format 0100 { 0101 ## 3 - Find argument 0102 # kludge for QString(a,b) constructions 0103 $arguments =~ s/(QString\s*\([^,]+,[^,]+\))/QStrKLUDGE/; 0104 $kludge = $1; 0105 $arguments =~ s/\s*([^,]+)\s*,//; 0106 # Remove trailing .ascii() and latin1() 0107 $arg = $1; 0108 $arg =~ s/QStrKLUDGE/$kludge/; ## restore original arg 0109 $arg =~ s/\.ascii\(\)$//; # remove 0110 $arg =~ s/\.latin1\(\)$//; # remove 0111 $arg =~ s/debugString\(([^\)]+)\)/$1/; # remove 0112 # If "a ? b : c" then add parenthesis 0113 if ( $arg =~ m/.+\s*\?\s*.+\s*:\s*.+/ ) { 0114 $arg = "(" . $arg . ")"; 0115 } 0116 $line = $line . " << " . $arg; 0117 } else # This item is some litteral 0118 { 0119 $line = $line . " << \"" . $_ . "\"" if ($_); 0120 } 0121 } 0122 0123 } 0124 $arguments =~ s/,$//; # Remove trailing slash before next check 0125 if ( $arguments ) { 0126 print STDERR "Non-processed (Information lost! Check the file!) : " . $arguments . "\n"; 0127 } 0128 $line = $line . " << endl;\n"; 0129 if ( $commented ) { $line .= "\*/"; } 0130 print $line; 0131 } 0132 } 0133 else 0134 { 0135 # Normal line 0136 print; 0137 } 0138 } 0139 if ( $inkdebug ) 0140 { 0141 print STDERR "Warning, unterminated kDebug call !! Check the file !\n"; 0142 print $arguments; 0143 } 0144 ' $file.tmp 0145 if cmp -s $file $file.tmp > /dev/null 2>&1 ; then 0146 echo "unchanged" 0147 rm $file.tmp 0148 else 0149 echo "patching" 0150 mv $file.tmp $file 0151 fi 0152 0153 done 0154