Drawtext tidying up ready for the next big change:
[wine/wine-kai.git] / tools / winapi / winapi_fixup
blob4ac4b3946ed89772a42b2868d5f6f3d0b8cdc6b5
1 #!/usr/bin/perl -w
3 # Copyright 2001 Patrik Stridvall
5 use strict;
7 BEGIN {
8 $0 =~ m%^(.*?/?tools)/winapi/winapi_fixup$%;
9 require "$1/winapi/setup.pm";
12 use config qw(
13 &file_type &files_filter
14 &file_skip &files_skip
15 &file_normalize
16 &get_spec_files
17 $current_dir $wine_dir $winapi_dir $winapi_check_dir
19 use output qw($output);
20 use winapi_fixup_options qw($options);
22 if($options->progress) {
23 $output->enable_progress;
24 } else {
25 $output->disable_progress;
28 use c_parser;
29 use type;
31 use winapi_fixup_documentation qw(&fixup_documentation);
32 use winapi_fixup_editor;
33 use winapi_fixup_statements qw(&fixup_statements);
35 my @c_files = $options->c_files;
36 @c_files = files_skip(@c_files);
37 @c_files = files_filter("winelib", @c_files);
39 my $progress_output;
40 my $progress_current = 0;
41 my $progress_max = scalar(@c_files);
43 foreach my $file (@c_files) {
44 my $editor = new winapi_fixup_editor($file);
46 $progress_current++;
47 $output->progress("$file (file $progress_current of $progress_max)");
48 $output->prefix("$file:");
51 open(IN, "< $file");
52 local $/ = undef;
53 $_ = <IN>;
54 close(IN);
57 my $max_line = 0;
59 local $_ = $_;
60 while(s/^.*?\n//) { $max_line++; }
61 if($_) { $max_line++; }
64 my $parser = new c_parser($file);
66 my $function;
67 my $line;
69 my $update_output = sub {
70 my $progress = "";
71 my $prefix = "";
73 $progress .= "$file (file $progress_current of $progress_max)";
74 $prefix .= "$file:";
76 if(defined($function)) {
77 my $name = $function->name;
78 my $begin_line = $function->begin_line;
79 my $begin_column = $function->begin_column;
81 $progress .= ": function $name";
82 $prefix .= "$begin_line.$begin_column: function $name: ";
85 if(defined($line)) {
86 $progress .= ": line $line of $max_line";
89 $output->progress($progress);
90 $output->prefix($prefix);
93 my $found_preprocessor = sub {
94 my $begin_line = shift;
95 my $begin_column = shift;
96 my $preprocessor = shift;
98 # $output->write("$begin_line.$begin_column: preprocessor: $preprocessor\n");
100 return 1;
103 $parser->set_found_preprocessor_callback($found_preprocessor);
105 my $found_comment = sub {
106 my $begin_line = shift;
107 my $begin_column = shift;
108 my $comment = shift;
110 # $output->write("$begin_line.$begin_column: comment: $comment\n");
112 return 1;
115 $parser->set_found_comment_callback($found_comment);
117 my $found_line = sub {
118 $line = shift;
119 # local $_ = shift;
121 &$update_output;
123 # $output->progress("$file: line $line of ?");
126 $parser->set_found_line_callback($found_line);
128 my $found_declaration = sub {
129 my $begin_line = shift;
130 my $begin_column = shift;
131 my $end_line = shift;
132 my $end_column = shift;
133 my $declaration = shift;
135 # $output->write("$begin_line.$begin_column-$end_line.$end_column: declaration: \\\n$declaration\n");
137 return 1;
140 $parser->set_found_declaration_callback($found_declaration);
142 my $found_function = sub {
143 $function = shift;
145 &$update_output;
147 my $name = $function->name;
148 my $begin_line = $function->begin_line;
149 my $begin_column = $function->begin_column;
150 my $end_line = $function->end_line;
151 my $end_column = $function->end_column;
153 if($options->documentation) {
154 # fixup_documentation($function, $editor);
157 if($options->statements) {
158 fixup_statements($function, $editor);
161 my $statements = $function->statements;
162 if(!defined($statements)) {
163 $function = undef;
164 $output->prefix("$file: ");
165 } else {
166 # $output->write("$begin_line.$begin_column-$end_line.$end_column: function $name\n");
169 return 0;
172 $parser->set_found_function_callback($found_function);
174 my $found_variable = sub {
175 my $begin_line = shift;
176 my $begin_column = shift;
177 my $linkage = shift;
178 my $type = shift;
179 my $name = shift;
181 # $output->write("$begin_line.$begin_column: $linkage $type $name = /* ... */\n");
183 return 1;
186 $parser->set_found_variable_callback($found_variable);
188 my $found_function_call = sub {
189 my $begin_line = shift;
190 my $begin_column = shift;
191 my $end_line = shift;
192 my $end_column = shift;
193 my $name = shift;
194 my $arguments = shift;
196 $output->write("$begin_line.$begin_column-$end_line.$end_column: $name(" . join(", ", @$arguments) . ")\n");
198 return 1;
201 $parser->set_found_function_call_callback($found_function_call);
204 my $line = 1;
205 my $column = 0;
206 if(!$parser->parse_c_file(\$_, \$line, \$column)) {
207 $output->write("can't parse file\n");
211 $output->prefix("");
213 $editor->flush;