2 # Copyright 1999, 2000, 2001 Patrik Stridvall
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 package winapi_fixup_editor
;
23 use options
qw($options);
24 use output qw($output);
25 use winapi qw($win16api $win32api @winapis);
31 my $class = ref($proto) || $proto;
33 bless ($self, $class);
35 my $file = \${$self->{FILE}};
42 sub add_trigger($$$) {
45 my $triggers = \%{$self->{TRIGGERS}};
50 if(!defined($$triggers{$line})) {
51 $$triggers{$line} = [];
54 push @{$$triggers{$line}}, $action;
60 my $begin_line = shift;
61 my $begin_column = shift;
63 my $end_column = shift;
66 my $file = \${$self->{FILE}};
68 my $line = $begin_line;
71 $self->add_trigger($begin_line, {
73 begin_line => $begin_line,
74 begin_column => $begin_column,
75 end_line => $end_line,
76 end_column => $end_column,
84 my $file = \${$self->{FILE}};
85 my $triggers = \%{$self->{TRIGGERS}};
95 my $lookahead_count = 0;
96 LINE: while($again || defined(my $current = <IN>)) {
102 $_ .= "\n" . $current;
106 $lookahead_count = 0;
109 $lookahead_count = 0;
113 my $line = $. - $lookahead_count;
114 foreach my $action (@{$$triggers{$line}}) {
115 if($. < $action->{end_line}) {
120 my $type = $action->{type};
121 my $begin_line = $action->{begin_line};
122 my $begin_column = $action->{begin_column};
123 my $end_line = $action->{end_line};
124 my $end_column = $action->{end_column};
126 if($type eq "replace") {
127 my $replace = $action->{replace};
129 my @lines = split(/\n/, $_);
137 while($column < $begin_column - 1 && s/^.//) {
140 $column = $column + 8 - $column % 8;
147 $_ = $lines[$#lines];
148 while($column2 < $end_column && s/^.//) {
150 $column2 = $column2 + 8 - $column2 % 8;
157 $_ = "$begin$replace$end";
158 if($options->modify) {
161 $output->write("$$file:$begin_line.$begin_column-$end_line.$end_column: $replace\n");
174 $modified = edit_file($$file, $editor);
182 ########################################################################
183 # Hack for backward compabillity
195 my $file = ${$self->{FILE}};
207 $line = $insert_line{$.};
209 if($options->modify) {
213 my $line2 = $line; chomp($line2);
214 my @line2 = split(/\n/, $line2);
216 $output->write("$file: $.: insert: \\\n");
217 foreach my $line2 (@line2) {
218 $output->write("'$line2'\n");
221 $output->write("$file: $.: insert: '$line2'\n");
226 my $search = $substitute_line{$.}{search};
227 my $replace = $substitute_line{$.}{replace};
229 if(defined($search) && defined($replace)) {
231 if(s/$search/$replace/) {
232 if($options->modify) {
238 if(!$options->modify || !$modified2) {
242 $search2 = "unmatched search";
243 $replace2 = "unmatched replace";
246 $replace2 = "replace";
248 $output->write("$file: $.: $search2 : '$search'\n");
250 my @replace2 = split(/\n/, $replace);
252 $output->write("$file: $.: $replace2: \\\n");
253 foreach my $replace2 (@replace2) {
254 $output->write("'$replace2'\n");
257 $output->write("$file: $.: $replace2: '$replace'\n");
262 $line = $delete_line{$.};
265 if($options->modify) {
269 $output->write("$file: $.: delete: '$line'\n");
272 $output->write("$file: $.: unmatched delete: '$line'\n");
283 while(defined(each %insert_line)) { $n++; }
284 while(defined(each %substitute_line)) { $n++; }
285 while(defined(each %delete_line)) { $n++; }
287 edit_file($file, $editor);
290 foreach my $module (sort(keys(%spec_file))) {
292 foreach my $winapi (@winapis) {
293 $file = ($winapi->module_file($module) || $file);
297 $file = file_normalize($file);
300 my @substitutes = @{$spec_file{$module}};
310 my @substitutes2 = ();
311 foreach my $substitute (@substitutes) {
312 my $search = $substitute->{search};
313 my $replace = $substitute->{replace};
315 if(s/$search/$replace/) {
316 if($options->modify) {
319 $output->write("$file: search : '$search'\n");
320 $output->write("$file: replace: '$replace'\n");
324 push @substitutes2, $substitute;
327 @substitutes = @substitutes2;
336 edit_file($file, $editor);
338 $output->write("$module: doesn't have any spec file\n");
341 if($#substitutes >= 0) {
342 foreach my $substitute (@substitutes) {
343 my $search = $substitute->{search};
344 my $replace = $substitute->{replace};
346 $output->write("$file: unmatched search : '$search'\n");
347 $output->write("$file: unmatched replace: '$replace'\n");
354 %substitute_line = ();
360 sub delete_line($$$) {
366 $delete_line{$line} = $pattern;
369 sub insert_line($$$) {
375 $insert_line{$line} = $insert;
378 sub substitute_line($$$$) {
385 $substitute_line{$line}{search} = $search;
386 $substitute_line{$line}{replace} = $replace;
389 sub replace_spec_file($$$$) {
397 $substitute->{search} = $search;
398 $substitute->{replace} = $replace;
400 if(!defined($spec_file{$module})) {
401 $spec_file{$module} = [];
404 push @{$spec_file{$module}}, $substitute;