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-pedantic" => { default => 0, parent => "documentation", description => "be pendantic when checking for documentation inconsistances\n" },
76 "documentation-width" => { default => 0, parent => "documentation", description => "check for documentation width inconsistances\n" },
77 "documentation-arguments" => { default => 1, parent => "documentation", description => "check for arguments documentation inconsistances\n" },
78 "documentation-ordinal" => { default => 0, parent => "documentation", description => "check for ordinal documentation inconsistances\n" },
79 "prototype" => { default => 0, parent => ["local", "headers"], description => "prototype checking" },
81 "global" => { default => 1, description => "global checking" },
82 "declared" => { default => 1, parent => "global", description => "declared checking" },
83 "implemented" => { default => 0, parent => "local", description => "implemented checking" },
84 "implemented-win32" => { default => 0, parent => "implemented", description => "implemented as win32 checking" },
85 "include" => { default => 1, parent => "global", description => "include checking" },
86 "headers" => { default => 0, parent => "global", description => "headers checking" },
87 "headers-duplicated" => { default => 0, parent => "headers", description => "duplicated function declarations checking" },
88 "headers-misplaced" => { default => 0, parent => "headers", description => "misplaced function declarations checking" },
89 "stubs" => { default => 0, parent => "global", description => "stubs checking" }
100 my $class = ref($proto) || $proto;
102 bless ($self, $class);
104 my $output = \${$self->{OUTPUT}};
107 my $refarguments = shift;
108 my $wine_dir = shift;
110 $self->options_set("default");
112 my $c_files = \@{$self->{C_FILES}};
113 my $h_files = \@{$self->{H_FILES}};
114 my $module = \${$self->{MODULE}};
115 my $global = \${$self->{GLOBAL}};
119 if($wine_dir eq ".") {
125 while(defined($_ = shift @$refarguments)) {
126 if(/^--(all|none)$/) {
127 $self->options_set("$1");
129 } elsif(/^-([^=]*)(=(.*))?$/) {
139 if($name =~ /^([^-].*)$/) {
140 $name = $short_options{$1};
142 $name =~ s/^-(.*)$/$1/;
146 if(defined($name) && $name =~ /^no-(.*)$/) {
149 if(defined($value)) {
150 $$output->write("options with prefix 'no' can't take parameters\n");
158 $option = $options{$name};
161 if(defined($option)) {
162 my $key = $$option{key};
163 my $parser = $$option{parser};
164 my $refvalue = \${$self->{$key}};
167 if(defined($$option{parent})) {
168 if(ref($$option{parent}) eq "ARRAY") {
169 @parents = @{$$option{parent}};
171 @parents = $$option{parent};
175 if(defined($parser)) {
176 $$refvalue = &$parser($prefix,$value);
178 if(defined($value)) {
180 } elsif(!defined($prefix)) {
187 if((ref($$refvalue) eq "HASH" && $$refvalue->{active}) || $$refvalue) {
188 while($#parents >= 0) {
189 my @old_parents = @parents;
191 foreach my $parent (@old_parents) {
192 my $parentkey = $options{$parent}{key};
193 my $refparentvalue = \${$self->{$parentkey}};
195 $$refparentvalue = 1;
197 if(defined($options{$parent}{parent})) {
198 if(ref($options{$parent}{parent}) eq "ARRAY") {
199 push @parents, @{$options{$parent}{parent}};
201 push @parents, $options{$parent}{parent};
211 if(/^--module-dlls$/) {
212 my @dirs = `cd dlls && find . -type d ! -name CVS`;
214 for my $dir (@dirs) {
216 $dir =~ s/^\.\/(.*)$/$1/;
220 $$module = { active => 1, filter => 1, hash => \%names };
223 $$output->write("unknown option: $_\n");
228 $$output->write("$_: no such file or directory\n");
244 foreach my $file (@files) {
245 if($file =~ /\.c$/) {
246 push @c_files, $file;
247 } elsif($file =~ /\.h$/) {
248 push @h_files, $file;
254 if($#c_files == -1 && $#h_files == -1 &&
255 ($#paths == -1 || ($#paths == 0 && $paths[0] eq $wine_dir)))
258 push @h_files, "$wine_dir/include";
263 if($#paths != -1 || $#c_files != -1) {
264 my $c_command = "find " . join(" ", @paths, @c_files) . " -name \\*.c";
266 @$c_files = sort(map {
268 if(defined($found{$_}) || /glue\.c|spec\.c$/) {
274 } split(/\n/, `$c_command`));
277 if($#h_files != -1) {
278 my $h_command = "find " . join(" ", @h_files) . " -name \\*.h";
281 @$h_files = sort(map {
283 if(defined($found{$_})) {
289 } split(/\n/, `$h_command`));
301 for my $name (sort(keys(%options))) {
302 my $option = $options{$name};
305 $$option{key} = $key;
306 my $refvalue = \${$self->{$key}};
309 $$refvalue = $$option{default};
311 if($name !~ /^help|debug|verbose|module$/) {
312 if(ref($$refvalue) ne "HASH") {
315 $$refvalue = { active => 1, filter => 0, hash => {} };
319 if($name !~ /^help|debug|verbose|module$/) {
320 if(ref($$refvalue) ne "HASH") {
323 $$refvalue = { active => 0, filter => 0, hash => {} };
334 for my $name (sort(keys(%options))) {
335 if(length($name) > $maxname) {
336 $maxname = length($name);
340 print "usage: winapi-check [--help] [<files>]\n";
342 for my $name (sort(keys(%options))) {
343 my $option = $options{$name};
344 my $description = $$option{description};
345 my $default = $$option{default};
346 my $current = ${$self->{$$option{key}}};
348 my $value = $current;
351 if(ref($value) ne "HASH") {
353 $output = "--no-$name";
358 if($value->{active}) {
359 $output = "--[no-]$name\[=<value>]";
361 $output = "--$name\[=<value>]";
366 for (0..(($maxname - length($name) + 17) - (length($output) - length($name) + 1))) { print " "; }
367 if(ref($value) ne "HASH") {
374 if($value->{active}) {
380 if($default == $current) {
381 print "$description (default)\n";
383 print "$description\n";
391 my $name = $winapi_options::AUTOLOAD;
392 $name =~ s/^.*::(.[^:]*)$/\U$1/;
394 my $refvalue = $self->{$name};
395 if(!defined($refvalue)) {
396 die "<internal>: winapi_options.pm: member $name does not exists\n";
399 if(ref($$refvalue) ne "HASH") {
402 return $$refvalue->{active};
406 sub c_files { my $self = shift; return @{$self->{C_FILES}}; }
408 sub h_files { my $self = shift; return @{$self->{H_FILES}}; }
412 my $refvalue = $self->{MODULE};
417 return $$refvalue->{active} && (!$$refvalue->{filter} || $$refvalue->{hash}->{$name});
423 sub report_argument_forbidden {
425 my $refargument_forbidden = $self->{ARGUMENT_FORBIDDEN};
429 return $$refargument_forbidden->{active} && (!$$refargument_forbidden->{filter} || $$refargument_forbidden->{hash}->{$type});
432 sub report_argument_kind {
434 my $refargument_kind = $self->{ARGUMENT_KIND};
438 return $$refargument_kind->{active} && (!$$refargument_kind->{filter} || $$refargument_kind->{hash}->{$kind});