-rwxr-xr-x | scripts/fixincludes | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/scripts/fixincludes b/scripts/fixincludes index 95fc129..da8613c 100755 --- a/scripts/fixincludes +++ b/scripts/fixincludes @@ -11,158 +11,158 @@ sub find_fixable_headers($); sub find_removable_includes ($); sub warn_before_modifying ($); sub remove_include ($$$); sub replace_include ($$$); sub fix_duplicates($); sub fix_compat_includes($); sub fix_unnecessary($); sub copy_file($$); sub process_source_file($); # some global variables $verbose = 0; # turns on debugging $modify = 0; # if 1 it should try to fix the files as well $experimental = 0; # try&error if an include is obsolete (slow!!) @explicitfiles = (); # filled in if passing files on the command line # statistic variables $exp_success = 0; $exp_failure = 0; while (defined ($ARGV[0])) { $_ = shift; if (/^--help$|^-h$/) { print "Usage: fixincludes [--verbose | -v] [--experimental | -e ] [--modify | -m ]\n"; exit 0; } elsif (/^--verbose$|^-v$/) { $verbose = 1; # Oh is there a problem...? } elsif (/^--modify$|^-m$/) { $modify = 1; } elsif (/^--experimental$|^-e$/) { $modify = 1; $experimental = 1; } elsif (!/^-/) { push @explicitfiles, $_; } } $cppExt = "(cpp|cc|cxx|C|c\\+\\+)"; $hExt = "(h|H|hh|hxx|hpp|h\\+\\+)"; # list of compat headers. scroll down ... much of boring stuff here.. %compatmap = ( 'qapp.h' => "qapplication.h", - 'qarray.h' => "qmemarray.h", - 'qbitarry.h' => "qbitarray.h", + #'qarray.h' => "qmemarray.h", + #'qbitarry.h' => "qbitarray.h", 'qbttngrp.h' => "qbuttongroup.h", - 'qchkbox.h' => "qcheckbox.h", + #'qchkbox.h' => "qcheckbox.h", 'qclipbrd.h' => "qclipboard.h", - 'qcollect.h' => "qptrcollection.h", - 'qcollection.h' => "qptrcollection.h", + #'qcollect.h' => "qptrcollection.h", + #'qcollection.h' => "qptrcollection.h", 'qcombo.h' => "qcombobox.h", 'qconnect.h' => "qconnection.h", 'qdatetm.h' => "qdatetime.h", 'qdrawutl.h' => "qdrawutil.h", 'qdstream.h' => "qdatastream.h", - 'qfiledef.h' => "private/qfiledefs_p.h", + #'qfiledef.h' => "private/qfiledefs_p.h", 'qfiledlg.h' => "qfiledialog.h", 'qfileinf.h' => "qfileinfo.h", 'qfontdta.h' => "qfontdata.h", 'qfontinf.h' => "qfontinfo.h", 'qfontmet.h' => "qfontmetrics.h", 'qgrpbox.h' => "qgroupbox.h", 'qintcach.h' => "qintcache.h", 'qiodev.h' => "qiodevice.h", 'qlcdnum.h' => "qlcdnumber.h", 'qlined.h' => "qlineedit.h", - 'qlist.h' => "qptrlist.h", + #'qlist.h' => "qptrlist.h", 'qmenudta.h' => "qmenudata.h", 'qmetaobj.h' => "qmetaobject.h", 'qmlined.h' => "qtmultilineedit.h", 'qmsgbox.h' => "qmessagebox.h", 'qmultilinedit.h' => "qmultilineedit.h", 'qobjcoll.h' => "qobjectlist.h>\n\#include <qobjectdict.h", 'qobjdefs.h' => "qobjectdefs.h", 'qpaintd.h' => "qpaintdevice.h", 'qpaintdc.h' => "qpaintdevicedefs.h", 'qpdevmet.h' => "qpaintdevicemetrics.h", 'qpmcache.h' => "qpixmapcache.h", 'qpntarry.h' => "qpointarray.h", 'qpopmenu.h' => "qpopupmenu.h", 'qprndlg.h' => "qprintdialog.h", 'qprogbar.h' => "qprogressbar.h", 'qprogdlg.h' => "qprogressdialog.h", 'qpsprn.h' => "<private/qpsprinter_p.h>", 'qpushbt.h' => "qpushbutton.h", 'qqueue.h' => "qptrqueue.h", 'qradiobt.h' => "qradiobutton.h", 'qrangect.h' => "qrangecontrol.h", 'qscrbar.h' => "qscrollbar.h", 'qsocknot.h' => "qsocketnotifier.h", - 'qstack.h' => "qptrstack.h", +# 'qstack.h' => "qptrstack.h", 'qtabdlg.h' => "qtabdialog.h", 'qtstream.h' => "qtextstream.h", - 'qvector.h' => "qptrvector.h", +# 'qvector.h' => "qptrvector.h", 'qwidcoll.h' => "qwidgetlist.h\n\#include <qwidgetintdict.h", 'qwindefs.h' => "qwindowdefs.h", # and now the KDE specific compat includes - 'kapp.h' => "kapplication.h", - 'kstddirs.h' => "kstandarddirs.h", - 'kuniqueapp.h' => "kuniqueapplication.h", - 'ktmainwindow.h'=> "kmainwindow.h", - 'kcolorbtn.h' => "kcolorbutton.h", - 'kcolordlg.h' => "kcolordialog.h", - 'kxmlgui.h' => "kxmlguifactory.h", +# 'kapp.h' => "kapplication.h", +# 'kstddirs.h' => "kstandarddirs.h", +# 'kuniqueapp.h' => "kuniqueapplication.h", +# 'ktmainwindow.h'=> "kmainwindow.h", +# 'kcolorbtn.h' => "kcolorbutton.h", +# 'kcolordlg.h' => "kcolordialog.h", +# 'kxmlgui.h' => "kxmlguifactory.h", ); # now it starts to get interesting again # Look for source files in the given directory ($dir, first parameter) sub find_fixable_sources ($) { # for now I grep the directory (requires srcdir==builddir) # actually it should read the Makefile and # find the _SOURCES / _OBJECTS tags that are put there by # automake and am_edit, but thats an excercise to the reader ;-) my ( $dir ) = @_; opendir (DIR, "$dir") || die "Couldn't read '$dir'\n"; my @sources = grep { /^.*\.$cppExt$/o } readdir(DIR); closedir(DIR); print "found sources: [ " . join(' ', @sources) . " ] in $dir\n" if ($verbose); # prefix them with $dir my @retsources = (); foreach $source(@sources) { push @retsources, "$dir/$source"; } return @retsources; } # Look for header files in the given directory ($dir, first parameter) sub find_fixable_headers ($) { # for now I grep the directory (requires srcdir==builddir) # actually it should read the Makefile and # find the _HEADERS tags that are put there by # automake and am_edit, but thats an excercise to the reader ;-) my ( $dir ) = @_; opendir (DIR, "$dir") || die "Couldn't read '$dir'\n"; my @headers = grep { /^.*\.$hExt$/o } readdir(DIR); closedir(DIR); print "found headers: [ " . join(' ', @headers) . " ] in $dir\n" if ($verbose); # prefix them with $dir my @retheaders = (); @@ -417,97 +417,97 @@ sub fix_unnecessary($) my $tot = $exp_success + $exp_failure; print "=============== $srcfile (successes: $exp_success; total: $tot)\n"; $srcfile = basename($srcfile); # first figure out some details my @includes = &find_removable_includes($srcfile); my $blanksrc = $srcfile; $blanksrc =~ s/(.*)\.[^\.]+/$1/; print "Checking for initial compilation: "; chdir($builddir); my $objextension = "BUG"; unlink "$blanksrc.lo"; my $output = `$makecmd $blanksrc.lo 2>&1`; $objextension = ".lo" if ( 0 == ($? >> 8)); if($objextension eq "BUG") { print "failed with .lo... "; unlink "$blanksrc.o"; $output = `$makecmd $blanksrc.o 2>&1`; $objextension = ".o" if ( 0 == ($? >> 8)); } if($objextension eq "BUG") { warn "can't figure out right compile command for $srcfile :-(\n??? unused, or didn't compile in the first place?\n"; warn "$output"; chdir($origdir); return; } print "worked with $objextension\n"; # now try to drop some includes foreach $include (@includes) { # kdatastream is special because # it will break the application if removed even # if it continues to compile next if( $include eq "kdatastream.h"); # I also like to have kdebug.h still in # so that it's easy to add kdDebug calls next if( $include eq "kdebug.h"); # avoid this one as it might cause # certain code parts to be disabled from compilation next if( $include eq "qmodules.h"); # check if it is its own header file my $blankhdr = $include; $blankhdr =~ s/(.*)\.[^\.]+/$1/; - next if ($blankhdr eq $blanksrc); + next if ($blankhdr eq $blanksrc); chdir($srcdir); local $localbackup = $srcfile . "#fixincludes"; # preserve timestamp if possible for CVS unlink $localbackup; rename $srcfile, $localbackup; copy_file($localbackup, $srcfile); # revert to backup in case of interrupt (Ctrl+C) $SIG{'INT'} = \&sighandler_fix_unnecessary; # check if it still compiles if($verbose) { chdir($builddir); unlink "$builddir/$blanksrc$objextension"; `$makecmd $blanksrc$objextension 2>&1`; die "unexpected error $output\nexitcode=" . ($? >> 8) if($? >> 8); chdir($srcdir); } # duplicates have to be nuked here , so it will be dropped maximum once print "trying without $include: "; &remove_include($srcfile, $include, 1); chdir($builddir); # try if it compiles unlink "$builddir/$blanksrc$objextension"; $output=`$makecmd $blanksrc$objextension 2>&1`; my $retcode = ($? >> 8); #print "retcode=$retcode\n$output" if ($verbose); chdir($srcdir); if($retcode == 0) { # wow, it worked, lets continue! print "SUCCESS!\n"; $SIG{'INT'} = 'DEFAULT'; unlink $localbackup; $exp_success = $exp_success + 1; } else { # better luck next time print "failed\n"; unlink $srcfile; rename $localbackup, $srcfile; $SIG{'INT'} = 'DEFAULT'; |