-rwxr-xr-x | scripts/fixincludes | 61 |
1 files changed, 3 insertions, 58 deletions
diff --git a/scripts/fixincludes b/scripts/fixincludes index da8613c..f07965e 100755 --- a/scripts/fixincludes +++ b/scripts/fixincludes | |||
@@ -1,208 +1,153 @@ | |||
1 | #!/usr/bin/perl -w | 1 | #!/usr/bin/perl -w |
2 | # tries to reduce the number of includes in KDE source files | 2 | # tries to reduce the number of includes in KDE source files |
3 | # (c) 2001 Dirk Mueller <mueller@kde.org> | 3 | # (c) 2001 Dirk Mueller <mueller@kde.org> |
4 | 4 | ||
5 | use File::Basename; | 5 | use File::Basename; |
6 | use Cwd; | 6 | use Cwd; |
7 | 7 | ||
8 | # declaration of useful subroutines | 8 | # declaration of useful subroutines |
9 | sub find_fixable_sources ($); | 9 | sub find_fixable_sources ($); |
10 | sub find_fixable_headers($); | 10 | sub find_fixable_headers($); |
11 | sub find_removable_includes ($); | 11 | sub find_removable_includes ($); |
12 | sub warn_before_modifying ($); | 12 | sub warn_before_modifying ($); |
13 | sub remove_include ($$$); | 13 | sub remove_include ($$$); |
14 | sub replace_include ($$$); | 14 | sub replace_include ($$$); |
15 | sub fix_duplicates($); | 15 | sub fix_duplicates($); |
16 | sub fix_compat_includes($); | 16 | sub fix_compat_includes($); |
17 | sub fix_unnecessary($); | 17 | sub fix_unnecessary($); |
18 | sub copy_file($$); | 18 | sub copy_file($$); |
19 | sub process_source_file($); | 19 | sub process_source_file($); |
20 | 20 | ||
21 | # some global variables | 21 | # some global variables |
22 | $verbose = 0; # turns on debugging | 22 | $verbose = 1; # turns on debugging |
23 | $modify = 0; # if 1 it should try to fix the files as well | 23 | $modify = 1; # if 1 it should try to fix the files as well |
24 | $experimental = 0; # try&error if an include is obsolete (slow!!) | 24 | $experimental = 1; # try&error if an include is obsolete (slow!!) |
25 | @explicitfiles = (); # filled in if passing files on the command line | 25 | @explicitfiles = (); # filled in if passing files on the command line |
26 | 26 | ||
27 | # statistic variables | 27 | # statistic variables |
28 | $exp_success = 0; | 28 | $exp_success = 0; |
29 | $exp_failure = 0; | 29 | $exp_failure = 0; |
30 | 30 | ||
31 | while (defined ($ARGV[0])) | 31 | while (defined ($ARGV[0])) |
32 | { | 32 | { |
33 | $_ = shift; | 33 | $_ = shift; |
34 | if (/^--help$|^-h$/) { | 34 | if (/^--help$|^-h$/) { |
35 | print "Usage: fixincludes [--verbose | -v] [--experimental | -e ] [--modify | -m ]\n"; | 35 | print "Usage: fixincludes [--verbose | -v] [--experimental | -e ] [--modify | -m ]\n"; |
36 | exit 0; | 36 | exit 0; |
37 | } | 37 | } |
38 | elsif (/^--verbose$|^-v$/) { | 38 | elsif (/^--verbose$|^-v$/) { |
39 | $verbose = 1; # Oh is there a problem...? | 39 | $verbose = 1; # Oh is there a problem...? |
40 | } | 40 | } |
41 | elsif (/^--modify$|^-m$/) { | 41 | elsif (/^--modify$|^-m$/) { |
42 | $modify = 1; | 42 | $modify = 1; |
43 | } | 43 | } |
44 | elsif (/^--experimental$|^-e$/) { | 44 | elsif (/^--experimental$|^-e$/) { |
45 | $modify = 1; | 45 | $modify = 1; |
46 | $experimental = 1; | 46 | $experimental = 1; |
47 | } | 47 | } |
48 | elsif (!/^-/) { | 48 | elsif (!/^-/) { |
49 | push @explicitfiles, $_; | 49 | push @explicitfiles, $_; |
50 | } | 50 | } |
51 | } | 51 | } |
52 | 52 | ||
53 | $cppExt = "(cpp|cc|cxx|C|c\\+\\+)"; | 53 | $cppExt = "(cpp|cc|cxx|C|c\\+\\+)"; |
54 | $hExt = "(h|H|hh|hxx|hpp|h\\+\\+)"; | 54 | $hExt = "(h|H|hh|hxx|hpp|h\\+\\+)"; |
55 | 55 | ||
56 | # list of compat headers. scroll down ... much of boring stuff here.. | 56 | # list of compat headers. scroll down ... much of boring stuff here.. |
57 | %compatmap = ( | 57 | %compatmap = ( |
58 | 'qapp.h' => "qapplication.h", | ||
59 | #'qarray.h' => "qmemarray.h", | ||
60 | #'qbitarry.h' => "qbitarray.h", | ||
61 | 'qbttngrp.h' => "qbuttongroup.h", | ||
62 | #'qchkbox.h' => "qcheckbox.h", | ||
63 | 'qclipbrd.h' => "qclipboard.h", | ||
64 | #'qcollect.h' => "qptrcollection.h", | ||
65 | #'qcollection.h' => "qptrcollection.h", | ||
66 | 'qcombo.h' => "qcombobox.h", | ||
67 | 'qconnect.h' => "qconnection.h", | ||
68 | 'qdatetm.h' => "qdatetime.h", | ||
69 | 'qdrawutl.h' => "qdrawutil.h", | ||
70 | 'qdstream.h' => "qdatastream.h", | ||
71 | #'qfiledef.h' => "private/qfiledefs_p.h", | ||
72 | 'qfiledlg.h' => "qfiledialog.h", | ||
73 | 'qfileinf.h' => "qfileinfo.h", | ||
74 | 'qfontdta.h' => "qfontdata.h", | ||
75 | 'qfontinf.h' => "qfontinfo.h", | ||
76 | 'qfontmet.h' => "qfontmetrics.h", | ||
77 | 'qgrpbox.h' => "qgroupbox.h", | ||
78 | 'qintcach.h' => "qintcache.h", | ||
79 | 'qiodev.h' => "qiodevice.h", | ||
80 | 'qlcdnum.h' => "qlcdnumber.h", | ||
81 | 'qlined.h' => "qlineedit.h", | ||
82 | #'qlist.h' => "qptrlist.h", | ||
83 | 'qmenudta.h' => "qmenudata.h", | ||
84 | 'qmetaobj.h' => "qmetaobject.h", | ||
85 | 'qmlined.h' => "qtmultilineedit.h", | ||
86 | 'qmsgbox.h' => "qmessagebox.h", | ||
87 | 'qmultilinedit.h' => "qmultilineedit.h", | ||
88 | 'qobjcoll.h' => "qobjectlist.h>\n\#include <qobjectdict.h", | ||
89 | 'qobjdefs.h' => "qobjectdefs.h", | ||
90 | 'qpaintd.h' => "qpaintdevice.h", | ||
91 | 'qpaintdc.h' => "qpaintdevicedefs.h", | ||
92 | 'qpdevmet.h' => "qpaintdevicemetrics.h", | ||
93 | 'qpmcache.h' => "qpixmapcache.h", | ||
94 | 'qpntarry.h' => "qpointarray.h", | ||
95 | 'qpopmenu.h' => "qpopupmenu.h", | ||
96 | 'qprndlg.h' => "qprintdialog.h", | ||
97 | 'qprogbar.h' => "qprogressbar.h", | ||
98 | 'qprogdlg.h' => "qprogressdialog.h", | ||
99 | 'qpsprn.h' => "<private/qpsprinter_p.h>", | ||
100 | 'qpushbt.h' => "qpushbutton.h", | ||
101 | 'qqueue.h' => "qptrqueue.h", | ||
102 | 'qradiobt.h' => "qradiobutton.h", | ||
103 | 'qrangect.h' => "qrangecontrol.h", | ||
104 | 'qscrbar.h' => "qscrollbar.h", | ||
105 | 'qsocknot.h' => "qsocketnotifier.h", | ||
106 | # 'qstack.h' => "qptrstack.h", | ||
107 | 'qtabdlg.h' => "qtabdialog.h", | ||
108 | 'qtstream.h' => "qtextstream.h", | ||
109 | # 'qvector.h' => "qptrvector.h", | ||
110 | 'qwidcoll.h' => "qwidgetlist.h\n\#include <qwidgetintdict.h", | ||
111 | 'qwindefs.h' => "qwindowdefs.h", | ||
112 | |||
113 | # and now the KDE specific compat includes | 58 | # and now the KDE specific compat includes |
114 | # 'kapp.h' => "kapplication.h", | 59 | # 'kapp.h' => "kapplication.h", |
115 | # 'kstddirs.h' => "kstandarddirs.h", | 60 | # 'kstddirs.h' => "kstandarddirs.h", |
116 | # 'kuniqueapp.h' => "kuniqueapplication.h", | 61 | # 'kuniqueapp.h' => "kuniqueapplication.h", |
117 | # 'ktmainwindow.h'=> "kmainwindow.h", | 62 | # 'ktmainwindow.h'=> "kmainwindow.h", |
118 | # 'kcolorbtn.h' => "kcolorbutton.h", | 63 | # 'kcolorbtn.h' => "kcolorbutton.h", |
119 | # 'kcolordlg.h' => "kcolordialog.h", | 64 | # 'kcolordlg.h' => "kcolordialog.h", |
120 | # 'kxmlgui.h' => "kxmlguifactory.h", | 65 | # 'kxmlgui.h' => "kxmlguifactory.h", |
121 | ); | 66 | ); |
122 | 67 | ||
123 | 68 | ||
124 | # now it starts to get interesting again | 69 | # now it starts to get interesting again |
125 | 70 | ||
126 | # Look for source files in the given directory ($dir, first parameter) | 71 | # Look for source files in the given directory ($dir, first parameter) |
127 | sub find_fixable_sources ($) | 72 | sub find_fixable_sources ($) |
128 | { | 73 | { |
129 | # for now I grep the directory (requires srcdir==builddir) | 74 | # for now I grep the directory (requires srcdir==builddir) |
130 | # actually it should read the Makefile and | 75 | # actually it should read the Makefile and |
131 | # find the _SOURCES / _OBJECTS tags that are put there by | 76 | # find the _SOURCES / _OBJECTS tags that are put there by |
132 | # automake and am_edit, but thats an excercise to the reader ;-) | 77 | # automake and am_edit, but thats an excercise to the reader ;-) |
133 | 78 | ||
134 | my ( $dir ) = @_; | 79 | my ( $dir ) = @_; |
135 | 80 | ||
136 | opendir (DIR, "$dir") || die "Couldn't read '$dir'\n"; | 81 | opendir (DIR, "$dir") || die "Couldn't read '$dir'\n"; |
137 | my @sources = grep { /^.*\.$cppExt$/o } readdir(DIR); | 82 | my @sources = grep { /^.*\.$cppExt$/o } readdir(DIR); |
138 | closedir(DIR); | 83 | closedir(DIR); |
139 | 84 | ||
140 | print "found sources: [ " . join(' ', @sources) . " ] in $dir\n" if ($verbose); | 85 | print "found sources: [ " . join(' ', @sources) . " ] in $dir\n" if ($verbose); |
141 | 86 | ||
142 | # prefix them with $dir | 87 | # prefix them with $dir |
143 | my @retsources = (); | 88 | my @retsources = (); |
144 | foreach $source(@sources) { | 89 | foreach $source(@sources) { |
145 | push @retsources, "$dir/$source"; | 90 | push @retsources, "$dir/$source"; |
146 | } | 91 | } |
147 | 92 | ||
148 | return @retsources; | 93 | return @retsources; |
149 | } | 94 | } |
150 | 95 | ||
151 | # Look for header files in the given directory ($dir, first parameter) | 96 | # Look for header files in the given directory ($dir, first parameter) |
152 | sub find_fixable_headers ($) | 97 | sub find_fixable_headers ($) |
153 | { | 98 | { |
154 | # for now I grep the directory (requires srcdir==builddir) | 99 | # for now I grep the directory (requires srcdir==builddir) |
155 | # actually it should read the Makefile and | 100 | # actually it should read the Makefile and |
156 | # find the _HEADERS tags that are put there by | 101 | # find the _HEADERS tags that are put there by |
157 | # automake and am_edit, but thats an excercise to the reader ;-) | 102 | # automake and am_edit, but thats an excercise to the reader ;-) |
158 | 103 | ||
159 | my ( $dir ) = @_; | 104 | my ( $dir ) = @_; |
160 | 105 | ||
161 | opendir (DIR, "$dir") || die "Couldn't read '$dir'\n"; | 106 | opendir (DIR, "$dir") || die "Couldn't read '$dir'\n"; |
162 | my @headers = grep { /^.*\.$hExt$/o } readdir(DIR); | 107 | my @headers = grep { /^.*\.$hExt$/o } readdir(DIR); |
163 | closedir(DIR); | 108 | closedir(DIR); |
164 | 109 | ||
165 | print "found headers: [ " . join(' ', @headers) . " ] in $dir\n" if ($verbose); | 110 | print "found headers: [ " . join(' ', @headers) . " ] in $dir\n" if ($verbose); |
166 | 111 | ||
167 | # prefix them with $dir | 112 | # prefix them with $dir |
168 | my @retheaders = (); | 113 | my @retheaders = (); |
169 | foreach $source(@headers) { | 114 | foreach $source(@headers) { |
170 | push @retheaders, "$dir/$source"; | 115 | push @retheaders, "$dir/$source"; |
171 | } | 116 | } |
172 | 117 | ||
173 | return @retheaders; | 118 | return @retheaders; |
174 | } | 119 | } |
175 | 120 | ||
176 | sub find_removable_includes ($) | 121 | sub find_removable_includes ($) |
177 | { | 122 | { |
178 | my $srcfile = shift @_; | 123 | my $srcfile = shift @_; |
179 | open(SRC, "< $srcfile") || die "find_removable_includes: couldn't open '$srcfile'\n"; | 124 | open(SRC, "< $srcfile") || die "find_removable_includes: couldn't open '$srcfile'\n"; |
180 | 125 | ||
181 | my @includes = (); | 126 | my @includes = (); |
182 | 127 | ||
183 | # we skip all includes that are somehow ifdefed | 128 | # we skip all includes that are somehow ifdefed |
184 | 129 | ||
185 | my $cpplevel = 0; | 130 | my $cpplevel = 0; |
186 | $cpplevel = -1 if ($srcfile=~m/^.*\.$hExt$/); # plan for header-protection #ifndef/#define/#endif | 131 | $cpplevel = -1 if ($srcfile=~m/^.*\.$hExt$/); # plan for header-protection #ifndef/#define/#endif |
187 | while (<SRC>) { | 132 | while (<SRC>) { |
188 | if ($_ =~ m/^\#if/) { | 133 | if ($_ =~ m/^\#if/) { |
189 | $cpplevel = $cpplevel + 1; | 134 | $cpplevel = $cpplevel + 1; |
190 | next; | 135 | next; |
191 | } | 136 | } |
192 | if ($_ =~ m/^\#endif/) { | 137 | if ($_ =~ m/^\#endif/) { |
193 | $cpplevel = $cpplevel - 1; | 138 | $cpplevel = $cpplevel - 1; |
194 | next; | 139 | next; |
195 | } | 140 | } |
196 | #if ($cpplevel == 0 && $_ =~ m/^\#include\s*[\"<]([qk]\S*\.h)[\">]\S*/) { | 141 | #if ($cpplevel == 0 && $_ =~ m/^\#include\s*[\"<]([qk]\S*\.h)[\">]\S*/) { |
197 | if ($cpplevel == 0 && (($_ =~ m/^\#include\s*\"(\S+\.h)\"\S*/) || ($_ =~ m/^\#include\s*\<([qk]\S+.h)\>\S*/))) { | 142 | if ($cpplevel == 0 && (($_ =~ m/^\#include\s*\"(\S+\.h)\"\S*/) || ($_ =~ m/^\#include\s*\<([qk]\S+.h)\>\S*/))) { |
198 | push @includes, $1; | 143 | push @includes, $1; |
199 | next; | 144 | next; |
200 | } | 145 | } |
201 | } | 146 | } |
202 | close SRC; | 147 | close SRC; |
203 | 148 | ||
204 | print "No fixable includes found in $srcfile\n" if ($verbose and not @includes); | 149 | print "No fixable includes found in $srcfile\n" if ($verbose and not @includes); |
205 | print "found includes: [ " . join(' ', @includes) . " ]\n" if ($verbose and @includes); | 150 | print "found includes: [ " . join(' ', @includes) . " ]\n" if ($verbose and @includes); |
206 | 151 | ||
207 | return @includes; | 152 | return @includes; |
208 | } | 153 | } |