Removed some more trailing whitespace.
[wine/multimedia.git] / tools / winapi / winapi_fixup
blob05a0bafa78e1666eba79b8077d92b9beca2654d2
1 #!/usr/bin/perl -w
3 # Copyright 2001 Patrik Stridvall
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 use strict;
22 BEGIN {
23 $0 =~ m%^(.*?/?tools)/winapi/winapi_fixup$%;
24 require "$1/winapi/setup.pm";
27 use config qw(
28 &file_type &files_filter
29 &file_skip &files_skip
30 &file_normalize
31 &get_spec_files
32 $current_dir $wine_dir $winapi_dir $winapi_check_dir
34 use output qw($output);
35 use winapi_fixup_options qw($options);
37 if($options->progress) {
38 $output->enable_progress;
39 } else {
40 $output->disable_progress;
43 use c_parser;
44 use type;
46 use winapi_fixup_documentation qw(&fixup_documentation);
47 use winapi_fixup_editor;
48 use winapi_fixup_statements qw(&fixup_statements);
50 my @c_files = $options->c_files;
51 @c_files = files_skip(@c_files);
52 @c_files = files_filter("winelib", @c_files);
54 my $progress_output;
55 my $progress_current = 0;
56 my $progress_max = scalar(@c_files);
58 foreach my $file (@c_files) {
59 my $editor = new winapi_fixup_editor($file);
61 $progress_current++;
62 $output->progress("$file (file $progress_current of $progress_max)");
63 $output->prefix("$file:");
66 open(IN, "< $file");
67 local $/ = undef;
68 $_ = <IN>;
69 close(IN);
72 my $max_line = 0;
74 local $_ = $_;
75 while(s/^.*?\n//) { $max_line++; }
76 if($_) { $max_line++; }
79 my $parser = new c_parser($file);
81 my $function;
82 my $line;
84 my $update_output = sub {
85 my $progress = "";
86 my $prefix = "";
88 $progress .= "$file (file $progress_current of $progress_max)";
89 $prefix .= "$file:";
91 if(defined($function)) {
92 my $name = $function->name;
93 my $begin_line = $function->begin_line;
94 my $begin_column = $function->begin_column;
96 $progress .= ": function $name";
97 $prefix .= "$begin_line.$begin_column: function $name: ";
100 if(defined($line)) {
101 $progress .= ": line $line of $max_line";
104 $output->progress($progress);
105 $output->prefix($prefix);
108 my $found_preprocessor = sub {
109 my $begin_line = shift;
110 my $begin_column = shift;
111 my $preprocessor = shift;
113 # $output->write("$begin_line.$begin_column: preprocessor: $preprocessor\n");
115 return 1;
118 $parser->set_found_preprocessor_callback($found_preprocessor);
120 my $found_comment = sub {
121 my $begin_line = shift;
122 my $begin_column = shift;
123 my $comment = shift;
125 # $output->write("$begin_line.$begin_column: comment: $comment\n");
127 return 1;
130 $parser->set_found_comment_callback($found_comment);
132 my $found_line = sub {
133 $line = shift;
134 # local $_ = shift;
136 &$update_output;
138 # $output->progress("$file: line $line of ?");
141 $parser->set_found_line_callback($found_line);
143 my $found_declaration = sub {
144 my $begin_line = shift;
145 my $begin_column = shift;
146 my $end_line = shift;
147 my $end_column = shift;
148 my $declaration = shift;
150 # $output->write("$begin_line.$begin_column-$end_line.$end_column: declaration: \\\n$declaration\n");
152 return 1;
155 $parser->set_found_declaration_callback($found_declaration);
157 my $found_function = sub {
158 $function = shift;
160 &$update_output;
162 my $name = $function->name;
163 my $begin_line = $function->begin_line;
164 my $begin_column = $function->begin_column;
165 my $end_line = $function->end_line;
166 my $end_column = $function->end_column;
168 if($options->documentation) {
169 # fixup_documentation($function, $editor);
172 if($options->statements) {
173 fixup_statements($function, $editor);
176 my $statements = $function->statements;
177 if(!defined($statements)) {
178 $function = undef;
179 $output->prefix("$file: ");
180 } else {
181 # $output->write("$begin_line.$begin_column-$end_line.$end_column: function $name\n");
184 return 0;
187 $parser->set_found_function_callback($found_function);
189 my $found_variable = sub {
190 my $begin_line = shift;
191 my $begin_column = shift;
192 my $linkage = shift;
193 my $type = shift;
194 my $name = shift;
196 # $output->write("$begin_line.$begin_column: $linkage $type $name = /* ... */\n");
198 return 1;
201 $parser->set_found_variable_callback($found_variable);
203 my $found_function_call = sub {
204 my $begin_line = shift;
205 my $begin_column = shift;
206 my $end_line = shift;
207 my $end_column = shift;
208 my $name = shift;
209 my $arguments = shift;
211 $output->write("$begin_line.$begin_column-$end_line.$end_column: $name(" . join(", ", @$arguments) . ")\n");
213 return 1;
216 $parser->set_found_function_call_callback($found_function_call);
219 my $line = 1;
220 my $column = 0;
221 if(!$parser->parse_c_file(\$_, \$line, \$column)) {
222 $output->write("can't parse file\n");
226 $output->prefix("");
228 $editor->flush;