blob: 334aa52a5d90215dc68a7931f58630bb35d922b9 [file] [log] [blame]
Patrik Stridvall6a012e22001-06-13 19:38:29 +00001#!/usr/bin/perl -w
2
3# Copyright 2001 Patrik Stridvall
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00004#
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.
9#
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.
14#
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
Jonathan Ernst360a3f92006-05-18 14:49:52 +020017# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000018#
Patrik Stridvall6a012e22001-06-13 19:38:29 +000019
20use strict;
21
22BEGIN {
23 $0 =~ m%^(.*?/?tools)/winapi/winapi_fixup$%;
24 require "$1/winapi/setup.pm";
25}
26
27use config qw(
Rolf Kalbermatter2db7d112006-01-06 12:17:46 +010028 files_filter files_skip
Alexandre Julliard14920282005-05-04 10:43:00 +000029 $current_dir $wine_dir $winapi_dir
Patrik Stridvall6a012e22001-06-13 19:38:29 +000030);
Patrik Stridvall1c61b3b2001-07-23 23:20:56 +000031use output qw($output);
Patrik Stridvall1c61b3b2001-07-23 23:20:56 +000032use winapi_fixup_options qw($options);
Patrik Stridvall6a012e22001-06-13 19:38:29 +000033
Patrik Stridvallaeb023f2001-08-22 18:09:15 +000034if($options->progress) {
35 $output->enable_progress;
36} else {
37 $output->disable_progress;
38}
39
Patrik Stridvall11f03592002-09-23 20:38:30 +000040use winapi_c_parser;
Patrik Stridvallaeb023f2001-08-22 18:09:15 +000041use c_parser;
Patrik Stridvall67f0a702001-07-26 21:42:12 +000042use type;
Patrik Stridvall6a012e22001-06-13 19:38:29 +000043
Francois Gougeta8b09d12004-10-26 00:12:21 +000044use winapi_fixup_documentation qw(fixup_documentation);
Patrik Stridvall4b33b132001-08-09 21:35:38 +000045use winapi_fixup_editor;
Francois Gougeta8b09d12004-10-26 00:12:21 +000046use winapi_fixup_statements qw(fixup_statements);
Patrik Stridvall4b33b132001-08-09 21:35:38 +000047
Patrik Stridvallc3e8ac32001-07-11 17:27:45 +000048my @c_files = $options->c_files;
Patrik Stridvall35a723b2001-06-20 22:53:21 +000049@c_files = files_skip(@c_files);
50@c_files = files_filter("winelib", @c_files);
Patrik Stridvall6a012e22001-06-13 19:38:29 +000051
52my $progress_output;
53my $progress_current = 0;
54my $progress_max = scalar(@c_files);
55
56foreach my $file (@c_files) {
Patrik Stridvall4b33b132001-08-09 21:35:38 +000057 my $editor = new winapi_fixup_editor($file);
Patrik Stridvall163652b2001-06-19 03:34:39 +000058
Patrik Stridvall6a012e22001-06-13 19:38:29 +000059 $progress_current++;
Patrik Stridvallaeb023f2001-08-22 18:09:15 +000060 $output->progress("$file (file $progress_current of $progress_max)");
61 $output->prefix("$file:");
Patrik Stridvall35a723b2001-06-20 22:53:21 +000062
Patrik Stridvallaeb023f2001-08-22 18:09:15 +000063 {
Colin Pitratab2cdea2006-08-08 12:19:31 +020064 open(IN, "< $file") || die "Error: Can't open $file: $!\n";
Patrik Stridvallaeb023f2001-08-22 18:09:15 +000065 local $/ = undef;
66 $_ = <IN>;
67 close(IN);
68 }
Alexandre Julliard7cae5582002-06-01 02:55:48 +000069
Patrik Stridvalld171a552001-09-10 23:16:05 +000070 my $max_line = 0;
Alexandre Julliard7cae5582002-06-01 02:55:48 +000071 {
Patrik Stridvalld171a552001-09-10 23:16:05 +000072 local $_ = $_;
73 while(s/^.*?\n//) { $max_line++; }
74 if($_) { $max_line++; }
75 }
76
Patrik Stridvall11f03592002-09-23 20:38:30 +000077 my $parser;
78 if (1) {
79 $parser = new c_parser($file);
80 } else {
81 $parser = new winapi_c_parser($file);
82 }
Patrik Stridvallaeb023f2001-08-22 18:09:15 +000083
Patrik Stridvalld171a552001-09-10 23:16:05 +000084 my $function;
85 my $line;
86
87 my $update_output = sub {
88 my $progress = "";
89 my $prefix = "";
90
91 $progress .= "$file (file $progress_current of $progress_max)";
92 $prefix .= "$file:";
93
94 if(defined($function)) {
95 my $name = $function->name;
96 my $begin_line = $function->begin_line;
97 my $begin_column = $function->begin_column;
98
99 $progress .= ": function $name";
100 $prefix .= "$begin_line.$begin_column: function $name: ";
101 }
102
103 if(defined($line)) {
104 $progress .= ": line $line of $max_line";
105 }
106
107 $output->progress($progress);
108 $output->prefix($prefix);
109 };
110
Patrik Stridvallaeb023f2001-08-22 18:09:15 +0000111 my $found_preprocessor = sub {
112 my $begin_line = shift;
113 my $begin_column = shift;
114 my $preprocessor = shift;
115
116 # $output->write("$begin_line.$begin_column: preprocessor: $preprocessor\n");
117
118 return 1;
Patrik Stridvall67f0a702001-07-26 21:42:12 +0000119 };
120
Alexandre Julliard7cae5582002-06-01 02:55:48 +0000121 $parser->set_found_preprocessor_callback($found_preprocessor);
Patrik Stridvallaeb023f2001-08-22 18:09:15 +0000122
123 my $found_comment = sub {
124 my $begin_line = shift;
125 my $begin_column = shift;
126 my $comment = shift;
127
128 # $output->write("$begin_line.$begin_column: comment: $comment\n");
129
130 return 1;
131 };
132
Alexandre Julliard7cae5582002-06-01 02:55:48 +0000133 $parser->set_found_comment_callback($found_comment);
Patrik Stridvallaeb023f2001-08-22 18:09:15 +0000134
Patrik Stridvalld171a552001-09-10 23:16:05 +0000135 my $found_line = sub {
136 $line = shift;
137 # local $_ = shift;
138
139 &$update_output;
140
141 # $output->progress("$file: line $line of ?");
142 };
143
144 $parser->set_found_line_callback($found_line);
145
Patrik Stridvallaeb023f2001-08-22 18:09:15 +0000146 my $found_declaration = sub {
147 my $begin_line = shift;
148 my $begin_column = shift;
149 my $end_line = shift;
150 my $end_column = shift;
151 my $declaration = shift;
152
153 # $output->write("$begin_line.$begin_column-$end_line.$end_column: declaration: \\\n$declaration\n");
154
155 return 1;
156 };
157
Alexandre Julliard7cae5582002-06-01 02:55:48 +0000158 $parser->set_found_declaration_callback($found_declaration);
Patrik Stridvallaeb023f2001-08-22 18:09:15 +0000159
Patrik Stridvall6a012e22001-06-13 19:38:29 +0000160 my $found_function = sub {
Patrik Stridvallaeb023f2001-08-22 18:09:15 +0000161 $function = shift;
Patrik Stridvalld171a552001-09-10 23:16:05 +0000162
163 &$update_output;
164
Patrik Stridvallaeb023f2001-08-22 18:09:15 +0000165 my $name = $function->name;
166 my $begin_line = $function->begin_line;
167 my $begin_column = $function->begin_column;
Patrik Stridvalld171a552001-09-10 23:16:05 +0000168 my $end_line = $function->end_line;
169 my $end_column = $function->end_column;
170
Patrik Stridvall4b33b132001-08-09 21:35:38 +0000171 if($options->documentation) {
Patrik Stridvallaeb023f2001-08-22 18:09:15 +0000172 # fixup_documentation($function, $editor);
Patrik Stridvallb59a9c72001-07-12 22:22:05 +0000173 }
Alexandre Julliard7cae5582002-06-01 02:55:48 +0000174
Patrik Stridvall4b33b132001-08-09 21:35:38 +0000175 if($options->statements) {
176 fixup_statements($function, $editor);
Patrik Stridvall6a012e22001-06-13 19:38:29 +0000177 }
Alexandre Julliard7cae5582002-06-01 02:55:48 +0000178
Patrik Stridvallaeb023f2001-08-22 18:09:15 +0000179 my $statements = $function->statements;
180 if(!defined($statements)) {
181 $function = undef;
182 $output->prefix("$file: ");
Patrik Stridvalld171a552001-09-10 23:16:05 +0000183 } else {
184 # $output->write("$begin_line.$begin_column-$end_line.$end_column: function $name\n");
Patrik Stridvallaeb023f2001-08-22 18:09:15 +0000185 }
Patrik Stridvall163652b2001-06-19 03:34:39 +0000186
Patrik Stridvallaeb023f2001-08-22 18:09:15 +0000187 return 0;
Patrik Stridvall6a012e22001-06-13 19:38:29 +0000188 };
Alexandre Julliard7cae5582002-06-01 02:55:48 +0000189
Patrik Stridvallaeb023f2001-08-22 18:09:15 +0000190 $parser->set_found_function_callback($found_function);
Patrik Stridvall6a012e22001-06-13 19:38:29 +0000191
Patrik Stridvallaeb023f2001-08-22 18:09:15 +0000192 my $found_variable = sub {
193 my $begin_line = shift;
194 my $begin_column = shift;
195 my $linkage = shift;
Patrik Stridvall67f0a702001-07-26 21:42:12 +0000196 my $type = shift;
Patrik Stridvallaeb023f2001-08-22 18:09:15 +0000197 my $name = shift;
198
Patrik Stridvalld171a552001-09-10 23:16:05 +0000199 # $output->write("$begin_line.$begin_column: $linkage $type $name = /* ... */\n");
Alexandre Julliard7cae5582002-06-01 02:55:48 +0000200
Patrik Stridvallaeb023f2001-08-22 18:09:15 +0000201 return 1;
Patrik Stridvall67f0a702001-07-26 21:42:12 +0000202 };
203
Alexandre Julliard7cae5582002-06-01 02:55:48 +0000204 $parser->set_found_variable_callback($found_variable);
Patrik Stridvall6a012e22001-06-13 19:38:29 +0000205
Patrik Stridvalld171a552001-09-10 23:16:05 +0000206 my $found_function_call = sub {
207 my $begin_line = shift;
208 my $begin_column = shift;
209 my $end_line = shift;
210 my $end_column = shift;
211 my $name = shift;
212 my $arguments = shift;
213
214 $output->write("$begin_line.$begin_column-$end_line.$end_column: $name(" . join(", ", @$arguments) . ")\n");
215
216 return 1;
217 };
218
219 $parser->set_found_function_call_callback($found_function_call);
220
221 {
222 my $line = 1;
223 my $column = 0;
224 if(!$parser->parse_c_file(\$_, \$line, \$column)) {
225 $output->write("can't parse file\n");
226 }
Patrik Stridvallaeb023f2001-08-22 18:09:15 +0000227 }
228
229 $output->prefix("");
Patrik Stridvall6a012e22001-06-13 19:38:29 +0000230
Patrik Stridvall4b33b132001-08-09 21:35:38 +0000231 $editor->flush;
Patrik Stridvall6a012e22001-06-13 19:38:29 +0000232}