summaryrefslogtreecommitdiffstats
path: root/bin/tqt20fix
blob: cee2eb1e420c9d88a4336d5ad40d52b73645ce6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/usr/bin/perl -w
#
# in sh/bash/zsh:
#    make 2>&1 | .../qt/bin/tqt20fix
# in csh/tcsh
#    make |& .../qt/bin/tqt20fix
#
# repeat as long as tqt20fix says to.  if your make supports the -k
# flag, that speeds up the process a bit.
#
# tqt20fix tends to fix a bit over half of the remaining problems in
# each run.
#
# if you don't use gcc, you will need to change parseline.
#


# this function must accept one line, which is presumed to be an error
# message, and return an array of three strings: the file name, the
# line number and the variable that is undefined.
#
# it may also return an empty list, if the line isn't an error message.
#
# the function is called on each line in turn and only once on each
# line, so it's possible to save state.
#

sub parseline{
    my( $line ) = @_;

    chomp $line;

    if ( $line =~ m%^([-a-zA-Z0-9_\./]+\.[a-zA-Z]+):(\d+):\s*\`(.+)\' undeclared% ) {
	@r = ($1,$2,$3);
	$r[0] = $currentdir . $r[0] if ( defined($currentdir) &&
					 $r[0] =~ m%^[^/]% );
	return @r;
    } elsif ( $line =~ m%^([-a-zA-Z0-9_\./]+\.[a-zA-Z]+):(\d+):\s*\`(.+)\' was not declared% ) {
	@r = ($1,$2,$3);
	$r[0] = $currentdir . $r[0] if ( defined($currentdir) &&
					 $r[0] =~ m%^[^/]% );
	return @r;
    } elsif ( $line =~ m%^g?make\[(\d+)\]: Entering directory \`(.*)\'% ) {
	# make[1]: Entering directory `/home/agulbra/2x/src/ui'
	my( $l, $c ) = ( $1, $2 );
	$c =~ s-/?$-/-;
	$dirs[$l] = $c;
	$currentdir = $c;
	print "$line\n";
    } elsif ( $line =~ m%make\[(\d+)\]: Leaving directory \`.*\'$% ) {
	# make[1]: Leaving directory `/home/agulbra/2x/src/ui'
	$currentdir = defined( $dirs[$1 - 1] ) ? $dirs[$1 - 1] : "";
	print "$line\n";
    } elsif ( $line =~ m%^\S+:(?:\d+:)?\s+\S% ) {
	# other compiler message - skip it
    } else {
	print "$line\n";
    }

    return ();
}


#
# this is the big array of globals and their replacements.  add stuff
# at will.
#

%globals =
(
 "Event_None" => "QEvent::None",
 "Event_Timer" => "QEvent::Timer",
 "Event_MouseButtonPress" => "QEvent::MouseButtonPress",
 "Event_MouseButtonRelease" => "QEvent::MouseButtonRelease",
 "Event_MouseButtonDblClick" => "QEvent::MouseButtonDblClick",
 "Event_MouseMove" => "QEvent::MouseMove",
 "Event_KeyPress" => "QEvent::KeyPress",
 "Event_KeyRelease" => "QEvent::KeyRelease",
 "Event_FocusIn" => "QEvent::FocusIn",
 "Event_FocusOut" => "QEvent::FocusOut",
 "Event_Enter" => "QEvent::Enter",
 "Event_Leave" => "QEvent::Leave",
 "Event_Paint" => "QEvent::Paint",
 "Event_Move" => "QEvent::Move",
 "Event_Resize" => "QEvent::Resize",
 "Event_Create" => "QEvent::Create",
 "Event_Destroy" => "QEvent::Destroy",
 "Event_Show" => "QEvent::Show",
 "Event_Hide" => "QEvent::Hide",
 "Event_Close" => "QEvent::Close",
 "Event_Quit" => "QEvent::Quit",
 "Event_Accel" => "QEvent::Accel",
 "Event_Clipboard" => "QEvent::Clipboard",
 "Event_SockAct" => "QEvent::SockAct",
 "Event_DragEnter" => "QEvent::DragEnter",
 "Event_DragMove" => "QEvent::DragMove",
 "Event_DragLeave" => "QEvent::DragLeave",
 "Event_Drop" => "QEvent::Drop",
 "Event_DragResponse" => "QEvent::DragResponse",
 "Event_ChildInserted" => "QEvent::ChildInserted",
 "Event_ChildRemoved" => "QEvent::ChildRemoved",
 "Event_LayoutHint" => "QEvent::LayoutHint",
 "Event_User" => "QEvent::User",

 "color0" => "Qt::color0",
 "color1" => "Qt::color1",
 "black" => "Qt::black",
 "white" => "Qt::white",
 "darkGray" => "Qt::darkGray",
 "gray" => "Qt::gray",
 "lightGray" => "Qt::lightGray",
 "red" => "Qt::red",
 "green" => "Qt::green",
 "blue" => "Qt::blue",
 "cyan" => "Qt::cyan",
 "magenta" => "Qt::magenta",
 "yellow" => "Qt::yellow",
 "darkRed" => "Qt::darkRed",
 "darkGreen" => "Qt::darkGreen",
 "darkBlue" => "Qt::darkBlue",
 "darkCyan" => "Qt::darkCyan",
 "darkMagenta" => "Qt::darkMagenta",
 "darkYellow" => "Qt::darkYellow",

 "AlignLeft" => "Qt::AlignLeft",
 "AlignRight" => "Qt::AlignRight",
 "AlignHCenter" => "Qt::AlignHCenter",
 "AlignTop" => "Qt::AlignTop",
 "AlignBottom" => "Qt::AlignBottom",
 "AlignVCenter" => "Qt::AlignVCenter",
 "AlignCenter" => "Qt::AlignCenter",
 "SingleLine" => "Qt::SingleLine",
 "DontClip" => "Qt::DontClip",
 "ExpandTabs" => "Qt::ExpandTabs",
 "ShowPrefix" => "Qt::ShowPrefix",
 "WordBreak" => "Qt::WordBreak",
 "DontPrint" => "Qt::DontPrint",

 "TransparentMode" => "Qt::TransparentMode",
 "OpaqueMode" => "Qt::OpaqueMode",

 "PixelUnit" => "Qt::PixelUnit",
 "LoMetricUnit" => "Qt::LoMetricUnit",
 "HiMetricUnit" => "Qt::HiMetricUnit",
 "LoEnglishUnit" => "Qt::LoEnglishUnit",
 "HiEnglishUnit" => "Qt::HiEnglishUnit",
 "TwipsUnit" => "Qt::TwipsUnit",

 "WindowsStyle" => "Qt::WindowsStyle",
 "MotifStyle" => "Qt::MotifStyle",

 "Horizontal" => "Qt::Horizontal",
 "Vertical" => "Qt::Vertical",

 "PenStyle" => "Qt::PenStyle",
 "NoPen" => "Qt::NoPen",
 "SolidLine" => "Qt::SolidLine",
 "DashLine" => "Qt::DashLine",
 "DotLine" => "Qt::DotLine",
 "DashDotLine" => "Qt::DashDotLine",
 "DashDotDotLine" => "Qt::DashDotDotLine",

 "BrushStyle" => "Qt::BrushStyle",
 "NoBrush" => "Qt::NoBrush",
 "SolidPattern" => "Qt::SolidPattern",
 "Dense1Pattern" => "Qt::Dense1Pattern",
 "Dense2Pattern" => "Qt::Dense2Pattern",
 "Dense3Pattern" => "Qt::Dense3Pattern",
 "Dense4Pattern" => "Qt::Dense4Pattern",
 "Dense5Pattern" => "Qt::Dense5Pattern",
 "Dense6Pattern" => "Qt::Dense6Pattern",
 "Dense7Pattern" => "Qt::Dense7Pattern",
 "HorPattern" => "Qt::HorPattern",
 "VerPattern" => "Qt::VerPattern",
 "CrossPattern" => "Qt::CrossPattern",
 "BDiagPattern" => "Qt::BDiagPattern",
 "FDiagPattern" => "Qt::FDiagPattern",
 "DiagCrossPattern" => "Qt::DiagCrossPattern",
 "CustomPattern" => "Qt::CustomPattern",

 "arrowCursor" => "Qt::arrowCursor",
 "upArrowCursor" => "Qt::upArrowCursor",
 "crossCursor" => "Qt::crossCursor",
 "waitCursor" => "Qt::waitCursor",
 "ibeamCursor" => "Qt::ibeamCursor",
 "sizeVerCursor" => "Qt::sizeVerCursor",
 "sizeHorCursor" => "Qt::sizeHorCursor",
 "sizeBDiagCursor" => "Qt::sizeBDiagCursor",
 "sizeFDiagCursor" => "Qt::sizeFDiagCursor",
 "sizeAllCursor" => "Qt::sizeAllCursor",
 "blankCursor" => "Qt::blankCursor",
 "splitVCursor" => "Qt::splitVCursor",
 "splitHCursor" => "Qt::splitHCursor",
 "pointingHandCursor" => "Qt::pointingHandCursor"
);

if ( defined( $ENV{"TQTDIR"} ) &&
     open( I, "< ". $ENV{"TQTDIR"} . "/src/kernel/ntq1xcompatibility.h" ) ) {
    while( <I> ) {
	if ( /\#define\s+([a-zA-Z0-9_]+)\s+(\S+)/ ) {
	    if ( !defined( $globals{$1} ) ) {
		$globals{$1} = $2;
	    } elsif ( $globals{$1} ne $2 ) {
		#print "conflict: $1 is mapped to $2 and $globals{$1}\n";
	    }
	}
    }
    close I;
}

#
# do the do
#

while( <STDIN> ) {
    @r = parseline($_);
    next unless @r;
    ($file, $line, $variable) = @r;
    if ( defined( $variable ) && defined($globals{$variable}) ) {
	if ( !defined($lastfile) || ($file ne $lastfile) ) {
	    $lastfile = undef if ( !$changes );
	    if ( defined( $lastfile ) ) {
		open( O, "> $lastfile" ) ||
		  die "cannot write to $lastfile, stopped";
		print "tqt20fix: writing $lastfile (changes: $changes)\n";
		print O @currentfile;
		close O;
	    }
	    open( I, "< $file" ) || die "cannot read $file, stopped";
	    @currentfile = <I>;
	    close I;
	    $lastfile = $file;
	    $changes = 0;
	}
	next unless ( defined( $currentfile[$line-1] ) );
	next unless ( $currentfile[$line-1] =~ /\b$variable\b/ );
	if ( $currentfile[$line-1] =~ s/([^a-zA-Z0-9])::$variable\b/$1$globals{$variable}/ ||
	     $currentfile[$line-1] =~ s/([^a-zA-Z0-9:])$variable\b/$1$globals{$variable}/ ) {
	    print "$file:$line:replaced \`$variable\' with \`$globals{$variable}\'\n";
	    $changes++;
	    $totalchanges++
	}
    } elsif ( defined( $variable ) ) {
	print "$file:$line: unknown undefined variable $variable\n";
    }
}

if ( defined( $changes) && $changes > 0 && defined( $lastfile ) ) {
    open( O, "> $lastfile" ) ||
      die "cannot write to $lastfile, stopped";
    print "tqt20fix: writing $lastfile (changes: $changes)\n";
    print O @currentfile;
    close O;
}


if ( defined( $totalchanges) && $totalchanges > 0 ) {
    print "tqt20fix: total changes: $totalchanges\ntqt20fix: rerun recommended\n";
}