Warning, /sdk/kde-dev-scripts/fixheaders is written in an unsupported language. File is not indexed.
0001 #! /usr/bin/env perl
0002
0003 # this script is written by Stephan Kulow <coolo@kde.org> with
0004 # much help from Sirtaj Singh Kang <ssk@physics.unimelb.edu.au>
0005
0006 if ($ARGV[0]) {
0007 $topdir = $ARGV[0];
0008 } else {
0009 $topdir=`pwd`;
0010 }
0011 chomp $topdir;
0012
0013 $lastdir = '.';
0014
0015
0016 # this is the important part. Left from the '=>' you find the regular
0017 # expression for the g++ output and right from '=>' the header file to
0018 # include
0019 %messages =
0020 (
0021 'implicit declaration of function `int i18n\(\.\.\.\)\'' => "klocale",
0022 '`i18n\' undeclared \(first use this function\)' => "klocale",
0023 'variable `class QPixmap \S*\' has initializer but incomplete type' => "qpixmap",
0024 '`kapp\' undeclared \(first use this function\)' => "kapplication",
0025 'no matching function for call to `KLocale::' => "klocale",
0026 '`klocale\' undeclared \(first use this function\)' => "klocale",
0027 'no matching function for call to `QPopupMenu::' => "qpopupmenu",
0028 '`QTextStream\' undeclared \(first use this function\)' => "qtextstream",
0029 '`QTextStream\' was not declared in this scope' => "qtextstream",
0030 'incomplete type `QSocketNotifier\'' => "qsocketnotifier",
0031 'no matching function for call to `KConfig' => "kconfig",
0032 'variable `class KConfig \S*\' has initializer but incomplete type' => "kconfig",
0033 'implicit declaration of function `int kDebug' => "kdebug",
0034 'implicit declaration of function `int kWarning' => "kdebug",
0035 '`QFile\' undeclared \(first use this function' => "qfile",
0036 'variable `QFile \S*\' has initializer but incomplete type' => "qfile",
0037 'type `KConfigBase\' is not a base type for type `KConfig' => "kconfig",
0038 'invalid use of undefined type `class QAccel' => "qaccel",
0039 'invalid use of undefined type `class KAboutData' => "kaboutdata",
0040 'incomplete type `KAboutData\'' => "kaboutdata",
0041 'incomplete type `QGrid\'' => "qgrid",
0042 'invalid use of undefined type `class QGrid\'' => "qgrid",
0043 'aggregate `class KConfig \S*\' has incomplete type' => "kconfig",
0044 '`stderr\' undeclared \(first use this function' => "stdio",
0045 'invalid use of undefined type `class KConfig' => "kconfig",
0046 'implicit declaration of function `int f?printf' => "stdio",
0047 'no method `KGlobal::' => "kglobal",
0048 '`KGlobal\' undeclared \(first use this function\)' => "kglobal",
0049 'implicit declaration of function `int locate\(\.\.\.\)' => "kstddirs",
0050 '`locate\' undeclared \(first use this function\)' => "kstddirs",
0051 'no matching function for call to `KStandardDirs' => "kstddirs",
0052 'no method `KStandardDirs::' => "kstddirs",
0053 'variable `class QFile \S*\' has initializer but incomplete type' => "qfile",
0054 'implicit declaration of function `int ICON\(\.\.\.\)' => "kiconloader",
0055 '`QMessageBox\' undeclared \(first use this function\)' => "qmessagebox",
0056 'no matching function for call to `QBoxLayout::QBoxLayout' => "qlayout",
0057 '`QUriDrag\' undeclared \(first use this function\)' => "qdragobject",
0058 '`kDebug\' undeclared \(first use this function\)' => "kdebug",
0059 '`kWarning\' undeclared \(first use this function\)' => "kdebug",
0060 'no matching function for call to `KMenuBar::insertItem\(QString, KPopupMenu' => "kpopupmenu",
0061 'no matching function for call to `KMenuBar::' => "kmenubar",
0062 'invalid use of undefined type `class QPointArray' => "qpointarray",
0063 'variable `QPainter \S*\' has initializer but incomplete type' => "qpainter",
0064 'invalid use of undefined type `class QRegExp' => "qregexp",
0065 'invalid use of undefined type `class QPushButton' => "qpushbutton",
0066 'cannot convert `QPushButton \*\' to `QButton \*' => "qpushbutton",
0067 'invalid use of undefined type `class QButton' => "qbutton",
0068 '`QButton\' undeclared \(first use this function\)' => "qbutton",
0069 'no method `QCursor::pos' => "qcursor",
0070 '`DesktopIcon\' undeclared \(first use this function\)' => "kiconloader",
0071 '`BarIcon\' undeclared \(first use this function\)' => "kiconloader",
0072 '`SmallIcon\' undeclared \(first use this function\)' => "kiconloader",
0073 '`UserIcon\' undeclared \(first use this function\)' => "kiconloader",
0074 'implicit declaration of function `int UserIcon\(...\)\'' => "kiconloader",
0075 '`KIcon\' undeclared \(first use this function\)' => "kiconloader",
0076 'invalid use of undefined type `class KIconLoader' => "kiconloader",
0077 'invalid use of undefined type `class KComponentData' => "kcomponentdata",
0078 'invalid use of undefined type `class KStatusBar\'' => "kstatusbar",
0079 'invalid use of undefined type `class QLabel\'' => "qlabel",
0080 'invalid use of undefined type `class QImage\'' => "qimage",
0081 'invalid use of undefined type `class QImageIO\'' => "qimage",
0082 'invalid use of undefined type `class QLineEdit\'' => "qlineedit",
0083 'invalid use of undefined type `class QComboBox\'' => "qcombobox",
0084 'invalid use of undefined type `class QStyle\'' => "qstyle",
0085 'invalid use of undefined type `class KPopupMenu\'' => "kpopupmenu",
0086 'invalid use of undefined type `class QPopupMenu\'' => "qpopupmenu",
0087 'cannot convert `KPopupMenu \*\' to `QPopupMenu \*' => "kpopupmenu",
0088 'aggregate `QPopupMenu \S*\' has incomplete type' => "qpopupmenu",
0089 'invalid use of undefined type `class KUrl' => "kurl",
0090 'no method `QApplication::' => "qapplication",
0091 'no method `QFile::' => "qfile",
0092 'error: \'Q3CString\' is used as a type' => "q3cstring",
0093 'error: ISO C\+\+ forbids declaration of \`Q3CString\' with' => "q3cstring",
0094 'error: incomplete type \'QPixmap\' cannot be used' => 'qpixmap',
0095 'error: invalid use of undefined type `struct QVector' => 'qvector',
0096 'error: incomplete type `Q3ValueList' => 'q3valuelist',
0097 'error: variable `Q3ValueList<' => 'q3valuelist',
0098 'error: `Q3PointArray\' undeclared' => 'q3pointarray',
0099 'error: invalid use of undefined type \`struct QColor' => 'qcolor',
0100 'error: `QX11Info::' => 'qx11info_x11',
0101 'error: incomplete type \'QX11Info' => 'qx11info_x11',
0102 'error: \'Q3AsciiDi' => 'q3asciidict',
0103 'invalid use of undefined type \'struct KXMLGUIFactory' => 'kxmlguifactory',
0104 'cannot convert \'KXMLGUIFactory*' => 'kxmlguifactory',
0105 'error: \'I18N_NOOP\' was not declared' => 'klocale',
0106 'error: \'i18n\' was not declared' => 'klocale',
0107 'error: incomplete type \'KGlobal' => 'kglobal',
0108 'error: \'KRandom\' has not been declared' => 'krandom',
0109 'error: \‘KStandardAction\’ has not been declared' => 'kstandardaction',
0110 'error: invalid use of undefined type \‘struct KSelectAction' => 'kselectaction',
0111 'invalid use of undefined type \‘struct KToggleAction' => 'ktoggleaction',
0112 'error: invalid use of undefined type \'struct KJobUiDelegate' => 'kjobuidelegate',
0113 'error: invalid use of undefined type \‘struct QLabel' => 'qlabel',
0114 'error: \'KToggleAction\' was not declared in this scope' => 'ktoggleaction',
0115 'invalid use of undefined type ‘struct KActionCollection' => 'kactioncollection',
0116 'forbids declaration of \'KToggleAction\' with no type' => 'ktoggleaction',
0117 'type \'struct KActionMenu' => 'kactionmenu',
0118 'invalid use of undefined type \'struct KAction' => 'kaction',
0119 'invalid use of undefined type ‘struct KAction' => 'kaction',
0120 'invalid use of undefined type ‘struct KSelectAction' => 'kselectaction',
0121 'invalid use of undefined type .struct KFontSizeAction' => 'kfontsizeaction',
0122 'invalid use of undefined type .struct KFontAction' => 'kfontaction',
0123 "invalid use of undefined type .* KIcon" => 'kicon',
0124 );
0125
0126 # Initial values are simply to get into the while
0127 $exitcode=2; # exit-code from last 'make' command
0128 $addedone=1; # 1 when something has been fixed, means we can try again
0129
0130 while ( $exitcode != 0 && $addedone != 0 )
0131 {
0132 $addedone = 0;
0133
0134 %changes = ();
0135 open(INPUT,"makeobj -j10 -k 2>&1 |") || die "Couldn't run makeobj";
0136 while(<INPUT>)
0137 {
0138 if (/make.*Entering directory \`(.+)\'/) {
0139 $lastdir = $1;
0140 $lastdir =~ s/^$topdir\///;
0141 print STDERR "entering $lastdir\n";
0142 next;
0143 }
0144 if (/^([^:]*):\d*: (.*)$/) {
0145 $file = $1;
0146 $line = $2;
0147 if ($file !~ m,^\/,) {
0148 $file = "$lastdir/$file";
0149 }
0150 #print STDERR "file=$file $line\n";
0151 } else {
0152 # This could be a continuation line
0153 if ( defined $line && $line ne "" ) {
0154 $line .= $_;
0155 #print STDERR "file still $file\n";
0156 #print STDERR "line=$line\n";
0157 } else {
0158 # Compilation line, or other unparsable line -> ignore
0159 print STDOUT $_;
0160 next;
0161 }
0162 }
0163
0164 #print STDERR "Already having changes for $file\n" if defined($changes{$file});
0165 next if defined($changes{$file});
0166
0167 #print STDOUT $_;
0168
0169 foreach $message (keys %messages) {
0170 if ($line =~ /.*$message.*/) {
0171 $changes{$file} = $messages{$message};
0172 $addedone = fixFile($file, $messages{$message});
0173 }
0174 }
0175
0176 if (defined($changes{$file})) { $file=""; $line=""; }
0177 } # end of while(<INPUT>)
0178 close(INPUT);
0179 $exitcode=($?>>8);
0180 } # end of main while
0181
0182 sub fixFile
0183 {
0184 my( $file, $adding ) = @_;
0185
0186 my $lastinclude = "";
0187 my $lastkinclude = "";
0188
0189 # read file
0190 open ( FILE, "$file" ) || die "Can't read $file";
0191
0192 my $flines;
0193 my $cpplevel = 0;
0194
0195 while (<FILE>) {
0196 $flines .= $_;
0197 #print "$cpplevel $_";
0198 if ($_ =~ m/^#if/ && $_ !~ m/^#ifn/) {
0199 $cpplevel = $cpplevel + 1;
0200 }
0201 if ($_ =~ m/^#endif/) {
0202 $cpplevel = $cpplevel - 1;
0203 }
0204 if ($cpplevel == 0 && ($_ =~ m/^(#include\s*[\"<]q\S*\.h[\">]\S*)/ || $_ =~ m/^(#include\s*[\"<]Q\S*[\">]\S*)/)) {
0205 $lastinclude = $1;
0206 }
0207 if ($cpplevel == 0 && $_ =~ m/^(#include\s*<k\S*\.h>\S*)/) {
0208 $lastkinclude = $1;
0209 }
0210
0211 }
0212
0213 close FILE;
0214
0215 $lastinclude = $lastkinclude if (!$lastinclude);
0216
0217 if (!$lastinclude) {
0218 print STDERR "ERROR: no include found in $file! (tried to add $adding.h)\n";
0219 return 0;
0220 }
0221
0222 if ($flines =~ m/#include\s*[\"<]$adding\.h[\">]\s*\n/) {
0223 print STDERR "ERROR: $adding.h already included in $file!\n";
0224 return 0;
0225 }
0226 if ($flines =~ /(\n$lastinclude)/) {
0227 $flines =~ s/$lastinclude(.*\n)/$lastinclude$1#include <$adding.h>\n/;
0228 print STDERR "ADDED <$adding.h> after \"$lastinclude\" in $file\n";
0229 } else {
0230 print STDERR "ERROR: can't find $lastinclude in $file\n";
0231 return 0;
0232 }
0233
0234 # write file
0235
0236 open( FILE, ">$file" ) || die "Can't write to $file";
0237 print FILE $flines;
0238 close FILE;
0239 return 1;
0240 }