Fixed some issues found by winapi_check.
[wine/dcerpc.git] / tools / winapi / winapi_fixup
blobfb338a737eabe81e658cb4c7880d4cb972101d84
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 winapi_c_parser;
44 use c_parser;
45 use type;
47 use winapi_fixup_documentation qw(&fixup_documentation);
48 use winapi_fixup_editor;
49 use winapi_fixup_statements qw(&fixup_statements);
51 my @c_files = $options->c_files;
52 @c_files = files_skip(@c_files);
53 @c_files = files_filter("winelib", @c_files);
55 my $progress_output;
56 my $progress_current = 0;
57 my $progress_max = scalar(@c_files);
59 foreach my $file (@c_files) {
60 my $editor = new winapi_fixup_editor($file);
62 $progress_current++;
63 $output->progress("$file (file $progress_current of $progress_max)");
64 $output->prefix("$file:");
67 open(IN, "< $file");
68 local $/ = undef;
69 $_ = <IN>;
70 close(IN);
73 my $max_line = 0;
75 local $_ = $_;
76 while(s/^.*?\n//) { $max_line++; }
77 if($_) { $max_line++; }
80 my $parser;
81 if (1) {
82 $parser = new c_parser($file);
83 } else {
84 $parser = new winapi_c_parser($file);
87 my $function;
88 my $line;
90 my $update_output = sub {
91 my $progress = "";
92 my $prefix = "";
94 $progress .= "$file (file $progress_current of $progress_max)";
95 $prefix .= "$file:";
97 if(defined($function)) {
98 my $name = $function->name;
99 my $begin_line = $function->begin_line;
100 my $begin_column = $function->begin_column;
102 $progress .= ": function $name";
103 $prefix .= "$begin_line.$begin_column: function $name: ";
106 if(defined($line)) {
107 $progress .= ": line $line of $max_line";
110 $output->progress($progress);
111 $output->prefix($prefix);
114 my $found_preprocessor = sub {
115 my $begin_line = shift;
116 my $begin_column = shift;
117 my $preprocessor = shift;
119 # $output->write("$begin_line.$begin_column: preprocessor: $preprocessor\n");
121 return 1;
124 $parser->set_found_preprocessor_callback($found_preprocessor);
126 my $found_comment = sub {
127 my $begin_line = shift;
128 my $begin_column = shift;
129 my $comment = shift;
131 # $output->write("$begin_line.$begin_column: comment: $comment\n");
133 return 1;
136 $parser->set_found_comment_callback($found_comment);
138 my $found_line = sub {
139 $line = shift;
140 # local $_ = shift;
142 &$update_output;
144 # $output->progress("$file: line $line of ?");
147 $parser->set_found_line_callback($found_line);
149 my $found_declaration = sub {
150 my $begin_line = shift;
151 my $begin_column = shift;
152 my $end_line = shift;
153 my $end_column = shift;
154 my $declaration = shift;
156 # $output->write("$begin_line.$begin_column-$end_line.$end_column: declaration: \\\n$declaration\n");
158 return 1;
161 $parser->set_found_declaration_callback($found_declaration);
163 my $found_function = sub {
164 $function = shift;
166 &$update_output;
168 my $name = $function->name;
169 my $begin_line = $function->begin_line;
170 my $begin_column = $function->begin_column;
171 my $end_line = $function->end_line;
172 my $end_column = $function->end_column;
174 if($options->documentation) {
175 # fixup_documentation($function, $editor);
178 if($options->statements) {
179 fixup_statements($function, $editor);
182 my $statements = $function->statements;
183 if(!defined($statements)) {
184 $function = undef;
185 $output->prefix("$file: ");
186 } else {
187 # $output->write("$begin_line.$begin_column-$end_line.$end_column: function $name\n");
190 return 0;
193 $parser->set_found_function_callback($found_function);
195 my $found_variable = sub {
196 my $begin_line = shift;
197 my $begin_column = shift;
198 my $linkage = shift;
199 my $type = shift;
200 my $name = shift;
202 # $output->write("$begin_line.$begin_column: $linkage $type $name = /* ... */\n");
204 return 1;
207 $parser->set_found_variable_callback($found_variable);
209 my $found_function_call = sub {
210 my $begin_line = shift;
211 my $begin_column = shift;
212 my $end_line = shift;
213 my $end_column = shift;
214 my $name = shift;
215 my $arguments = shift;
217 $output->write("$begin_line.$begin_column-$end_line.$end_column: $name(" . join(", ", @$arguments) . ")\n");
219 return 1;
222 $parser->set_found_function_call_callback($found_function_call);
225 my $line = 1;
226 my $column = 0;
227 if(!$parser->parse_c_file(\$_, \$line, \$column)) {
228 $output->write("can't parse file\n");
232 $output->prefix("");
234 $editor->flush;