1 package winapi_options;
5 sub parser_comma_list {
8 if(defined($prefix) && $prefix eq "no") {
9 return { active => 0, filter => 0, hash => {} };
10 } elsif(defined($value)) {
12 for my $name (split /,/, $value) {
15 return { active => 1, filter => 1, hash => \%names };
17 return { active => 1, filter => 0, hash => {} };
22 "debug" => { default => 0, description => "debug mode" },
23 "help" => { default => 0, description => "help mode" },
24 "verbose" => { default => 0, description => "verbose mode" },
26 "progress" => { default => 1, description => "show progress" },
28 "win16" => { default => 1, description => "Win16 checking" },
29 "win32" => { default => 1, description => "Win32 checking" },
31 "shared" => { default => 0, description => "show shared functions between Win16 and Win32" },
32 "shared-segmented" => { default => 0, description => "segmented shared functions between Win16 and Win32 checking" },
34 "config" => { default => 1, parent => "local", description => "check configuration include consistancy" },
35 "config-unnessary" => { default => 0, parent => "config", description => "check for unnessary #include \"config.h\"" },
37 "spec-mismatch" => { default => 0, description => "spec file mismatch checking" },
39 "local" => { default => 1, description => "local checking" },
41 default => { active => 1, filter => 0, hash => {} },
43 parser => \&parser_comma_list,
44 description => "module filter"
47 "argument" => { default => 1, parent => "local", description => "argument checking" },
48 "argument-count" => { default => 1, parent => "argument", description => "argument count checking" },
49 "argument-forbidden" => {
50 default => { active => 1, filter => 0, hash => {} },
52 parser => \&parser_comma_list,
53 description => "argument forbidden checking"
56 default => { active => 1, filter => 1, hash => { double => 1 } },
58 parser => \&parser_comma_list,
59 description => "argument kind checking"
61 "calling-convention" => { default => 1, parent => "local", description => "calling convention checking" },
62 "calling-convention-win16" => { default => 0, parent => "calling-convention", description => "calling convention checking (Win16)" },
63 "calling-convention-win32" => { default => 1, parent => "calling-convention", description => "calling convention checking (Win32)" },
64 "misplaced" => { default => 1, parent => "local", description => "check for misplaced functions" },
65 "statements" => { default => 0, parent => "local", description => "check for statements inconsistances" },
66 "cross-call" => { default => 0, parent => "statements", description => "check for cross calling functions" },
67 "cross-call-win32-win16" => {
68 default => 0, parent => "cross-call", description => "check for cross calls between win32 and win16"
70 "cross-call-unicode-ascii" => {
71 default => 0, parent => "cross-call", description => "check for cross calls between Unicode and ASCII"
73 "debug-messages" => { default => 0, parent => "statements", description => "check for debug messages inconsistances" },
74 "documentation" => { default => 1, parent => "local", description => "check for documentation inconsistances\n" },
75 "documentation-width" => { default => 0, parent => "documentation", description => "check for documentation width inconsistances\n" },
76 "prototype" => { default => 0, parent => ["local", "headers"], description => "prototype checking" },
78 "global" => { default => 1, description => "global checking" },
79 "declared" => { default => 1, parent => "global", description => "declared checking" },
80 "implemented" => { default => 1, parent => "local", description => "implemented checking" },
81 "implemented-win32" => { default => 0, parent => "implemented", description => "implemented as win32 checking" },
82 "include" => { default => 1, parent => "global", description => "include checking" },
83 "headers" => { default => 0, parent => "global", description => "headers checking" },
84 "headers-duplicated" => { default => 0, parent => "headers", description => "duplicated function declarations checking" },
85 "headers-misplaced" => { default => 0, parent => "headers", description => "misplaced function declarations checking" },
86 "stubs" => { default => 0, parent => "global", description => "stubs checking" }
97 my $class = ref($proto) || $proto;
99 bless ($self, $class);
101 my $output = \${$self->{OUTPUT}};
104 my $refarguments = shift;
105 my $wine_dir = shift;
107 $self->options_set("default");
109 my $c_files = \@{$self->{C_FILES}};
110 my $h_files = \@{$self->{H_FILES}};
111 my $module = \${$self->{MODULE}};
112 my $global = \${$self->{GLOBAL}};
116 if($wine_dir eq ".") {
122 while(defined($_ = shift @$refarguments)) {
123 if(/^--(all|none)$/) {
124 $self->options_set("$1");
126 } elsif(/^-([^=]*)(=(.*))?$/) {
136 if($name =~ /^([^-].*)$/) {
137 $name = $short_options{$1};
139 $name =~ s/^-(.*)$/$1/;
143 if(defined($name) && $name =~ /^no-(.*)$/) {
146 if(defined($value)) {
147 $$output->write("options with prefix 'no' can't take parameters\n");
155 $option = $options{$name};
158 if(defined($option)) {
159 my $key = $$option{key};
160 my $parser = $$option{parser};
161 my $refvalue = \${$self->{$key}};
164 if(defined($$option{parent})) {
165 if(ref($$option{parent}) eq "ARRAY") {
166 @parents = @{$$option{parent}};
168 @parents = $$option{parent};
172 if(defined($parser)) {
173 $$refvalue = &$parser($prefix,$value);
175 if(defined($value)) {
177 } elsif(!defined($prefix)) {
184 if((ref($$refvalue) eq "HASH" && $$refvalue->{active}) || $$refvalue) {
185 while($#parents >= 0) {
186 my @old_parents = @parents;
188 foreach my $parent (@old_parents) {
189 my $parentkey = $options{$parent}{key};
190 my $refparentvalue = \${$self->{$parentkey}};
192 $$refparentvalue = 1;
194 if(defined($options{$parent}{parent})) {
195 if(ref($options{$parent}{parent}) eq "ARRAY") {
196 push @parents, @{$options{$parent}{parent}};
198 push @parents, $options{$parent}{parent};
208 if(/^--module-dlls$/) {
209 my @dirs = `cd dlls && find . -type d ! -name CVS`;
211 for my $dir (@dirs) {
213 $dir =~ s/^\.\/(.*)$/$1/;
217 $$module = { active => 1, filter => 1, hash => \%names };
220 $$output->write("unknown option: $_\n");
225 $$output->write("$_: no such file or directory\n");
241 foreach my $file (@files) {
242 if($file =~ /\.c$/) {
243 push @c_files, $file;
244 } elsif($file =~ /\.h$/) {
245 push @h_files, $file;
251 if($#c_files == -1 && $#h_files == -1 &&
252 ($#paths == -1 || ($#paths == 0 && $paths[0] eq $wine_dir)))
255 push @h_files, "$wine_dir/include";
260 if($#paths != -1 || $#c_files != -1) {
261 my $c_command = "find " . join(" ", @paths, @c_files) . " -name \\*.c";
263 @$c_files = sort(map {
265 if(defined($found{$_}) || /glue\.c|spec\.c$/) {
271 } split(/\n/, `$c_command`));
274 if($#h_files != -1) {
275 my $h_command = "find " . join(" ", @h_files) . " -name \\*.h";
278 @$h_files = sort(map {
280 if(defined($found{$_})) {
286 } split(/\n/, `$h_command`));
295 for my $name (sort(keys(%options))) {
296 my $option = $options{$name};
299 $$option{key} = $key;
300 my $refvalue = \${$self->{$key}};
303 $$refvalue = $$option{default};
305 if($name !~ /^help|debug|verbose|module$/) {
306 if(ref($$refvalue) ne "HASH") {
309 $$refvalue = { active => 1, filter => 0, hash => {} };
313 if($name !~ /^help|debug|verbose|module$/) {
314 if(ref($$refvalue) ne "HASH") {
317 $$refvalue = { active => 0, filter => 0, hash => {} };
328 for my $name (sort(keys(%options))) {
329 if(length($name) > $maxname) {
330 $maxname = length($name);
334 print "usage: winapi-check [--help] [<files>]\n";
336 for my $name (sort(keys(%options))) {
337 my $option = $options{$name};
338 my $description = $$option{description};
339 my $default = $$option{default};
340 my $current = ${$self->{$$option{key}}};
342 my $value = $current;
345 if(ref($value) ne "HASH") {
347 $output = "--no-$name";
352 if($value->{active}) {
353 $output = "--[no-]$name\[=<value>]";
355 $output = "--$name\[=<value>]";
360 for (0..(($maxname - length($name) + 17) - (length($output) - length($name) + 1))) { print " "; }
361 if(ref($value) ne "HASH") {
368 if($value->{active}) {
374 if($default == $current) {
375 print "$description (default)\n";
377 print "$description\n";
385 my $name = $winapi_options::AUTOLOAD;
386 $name =~ s/^.*::(.[^:]*)$/\U$1/;
388 my $refvalue = $self->{$name};
389 if(!defined($refvalue)) {
390 die "<internal>: winapi_options.pm: member $name does not exists\n";
393 if(ref($$refvalue) ne "HASH") {
396 return $$refvalue->{active};
400 sub c_files { my $self = shift; return @{$self->{C_FILES}}; }
402 sub h_files { my $self = shift; return @{$self->{H_FILES}}; }
406 my $refvalue = $self->{MODULE};
411 return $$refvalue->{active} && (!$$refvalue->{filter} || $$refvalue->{hash}->{$name});
417 sub report_argument_forbidden {
419 my $refargument_forbidden = $self->{ARGUMENT_FORBIDDEN};
423 return $$refargument_forbidden->{active} && (!$$refargument_forbidden->{filter} || $$refargument_forbidden->{hash}->{$type});
426 sub report_argument_kind {
428 my $refargument_kind = $self->{ARGUMENT_KIND};
432 return $$refargument_kind->{active} && (!$$refargument_kind->{filter} || $$refargument_kind->{hash}->{$kind});