File indexing completed on 2024-06-09 05:37:52

0001 #!/usr/bin/perl -w
0002 
0003 # KParts was cleaned up to have one include file for each class, while in kdelibs4 #include <kparts/part.h> included many things
0004 # Usage: add_missing_kpart_include.pl *.h *.cpp
0005 # Recursive usage: find -iname "*.cpp" -o -iname "*.h" |xargs kde-dev-scripts/kf5/add_missing_kpart_include.pl
0006 #
0007 # Laurent Montel <montel@kde.org> (2014)
0008 # David Faure <faure@kde.org> (2014)
0009 
0010 use strict;
0011 use File::Basename;
0012 use lib dirname($0);
0013 use functionUtilkde;
0014 
0015 my @classes = (
0016         'BrowserArguments',
0017         'BrowserExtension',
0018         'BrowserHostExtension',
0019         'BrowserInterface',
0020         'BrowserOpenOrSaveQuestion',
0021         'BrowserRun',
0022         'Event',
0023         'FileInfoExtension',
0024         'GUIActivateEvent',
0025         'HistoryProvider',
0026         'HtmlExtension',
0027         'HtmlSettingsInterface',
0028         'ListingFilterExtension',
0029         'ListingNotificationExtension',
0030         'LiveConnectExtension',
0031         'MainWindow',
0032         'OpenUrlArguments',
0033         'OpenUrlEvent',
0034         'Part',
0035         'PartActivateEvent',
0036         'PartBase',
0037         'PartManager',
0038         'PartSelectEvent',
0039         'Plugin',
0040         'ReadOnlyPart',
0041         'ReadWritePart',
0042         'ScriptableExtension',
0043         'SelectorInterface',
0044         'StatusBarExtension',
0045         'TextExtension',
0046         'WindowArgs'
0047 );
0048 
0049 foreach my $file (@ARGV) {
0050 
0051     my %includesToBeAdded = ();
0052     my %fwdDecls = ();
0053     my $wasIncludingPartH = 0;
0054     my $modified;
0055     open(my $FILE, "<", $file) or warn "We can't open file $file:$!\n";
0056     my @l = map {
0057         my $orig = $_;
0058         foreach my $class (@classes) {
0059             if (/class $class;/) {
0060                 $fwdDecls{$class} = 1;
0061             }
0062             if (/KParts::$class/ && !defined $fwdDecls{$class}) {
0063                 # include the necessary header, unless we saw a fwd decl
0064                 $includesToBeAdded{"KParts/$class"} = 1;
0065                 $modified = 1;
0066             }
0067         }
0068         # get rid of lowercase includes, to avoid duplicates
0069         if (/^#include .kparts\/(\w+).h/) {
0070             $wasIncludingPartH = 1 if ($1 eq 'part');
0071             $_ = "";
0072         }
0073         $modified ||= $orig ne $_;
0074         $_;
0075     } <$FILE>;
0076 
0077     if ($modified) {
0078         open (my $OUT, ">", $file);
0079         print $OUT @l;
0080         close ($OUT);
0081         if ($wasIncludingPartH) {
0082             foreach my $include (keys %includesToBeAdded) {
0083                 functionUtilkde::addIncludeInFile($file, $include);
0084             }
0085         }
0086     }
0087 }
0088 
0089 functionUtilkde::diffFile( "@ARGV" );