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, 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 => 0, filter => 0, hash => {} },
58 parser => \&parser_comma_list,
59 description => "argument kind checking"
61 "calling-convention" => { default => 0, parent => "local", description => "calling convention checking" },
62 "misplaced" => { default => 1, parent => "local", description => "check for misplaced functions" },
63 "statements" => { default => 0, parent => "local", description => "check for statements inconsistances" },
64 "cross-call" => { default => 0, parent => "statements", description => "check for cross calling functions" },
65 "cross-call-win32-win16" => {
66 default => 0, parent => "cross-call", description => "check for cross calls between win32 and win16"
68 "cross-call-unicode-ascii" => {
69 default => 0, parent => "cross-call", description => "check for cross calls between Unicode and ASCII"
71 "debug-messages" => { default => 0, parent => "statements", description => "check for debug messages inconsistances" },
72 "documentation" => { default => 1, parent => "local", description => "check for documentation inconsistances\n" },
73 "documentation-width" => { default => 0, parent => "documentation", description => "check for documentation width inconsistances\n" },
74 "prototype" => { default => 0, parent => ["local", "headers"], description => "prototype checking" },
76 "global" => { default => 1, description => "global checking" },
77 "declared" => { default => 1, parent => "global", description => "declared checking" },
78 "implemented" => { default => 1, parent => "global", description => "implemented checking" },
79 "implemented-win32" => { default => 0, parent => "implemented", description => "implemented as win32 checking" },
80 "include" => { default => 1, parent => "global", description => "include checking" },
81 "headers" => { default => 0, parent => "global", description => "headers checking" },
82 "headers-duplicated" => { default => 0, parent => "headers", description => "duplicated function declarations checking" },
83 "headers-misplaced" => { default => 0, parent => "headers", description => "misplaced function declarations checking" },
84 "stubs" => { default => 0, parent => "global", description => "stubs checking" }
95 my $class = ref($proto) || $proto;
97 bless ($self, $class);
99 my $output = \${$self->{OUTPUT}};
102 my $refarguments = shift;
103 my $wine_dir = shift;
105 $self->options_set("default");
107 my $c_files = \@{$self->{C_FILES}};
108 my $h_files = \@{$self->{H_FILES}};
109 my $module = \${$self->{MODULE}};
110 my $global = \${$self->{GLOBAL}};
114 if($wine_dir eq ".") {
120 while(defined($_ = shift @$refarguments)) {
121 if(/^--(all|none)$/) {
122 $self->options_set("$1");
124 } elsif(/^-([^=]*)(=(.*))?$/) {
134 if($name =~ /^([^-].*)$/) {
135 $name = $short_options{$1};
137 $name =~ s/^-(.*)$/$1/;
141 if(defined($name) && $name =~ /^no-(.*)$/) {
144 if(defined($value)) {
145 $$output->write("options with prefix 'no' can't take parameters\n");
153 $option = $options{$name};
156 if(defined($option)) {
157 my $key = $$option{key};
158 my $parser = $$option{parser};
159 my $refvalue = \${$self->{$key}};
162 if(defined($$option{parent})) {
163 if(ref($$option{parent}) eq "ARRAY") {
164 @parents = @{$$option{parent}};
166 @parents = $$option{parent};
170 if(defined($parser)) {
171 $$refvalue = &$parser($prefix,$value);
173 if(defined($value)) {
175 } elsif(!defined($prefix)) {
182 if((ref($$refvalue) eq "HASH" && $$refvalue->{active}) || $$refvalue) {
183 while($#parents >= 0) {
184 my @old_parents = @parents;
186 foreach my $parent (@old_parents) {
187 my $parentkey = $options{$parent}{key};
188 my $refparentvalue = \${$self->{$parentkey}};
190 $$refparentvalue = 1;
192 if(defined($options{$parent}{parent})) {
193 if(ref($options{$parent}{parent}) eq "ARRAY") {
194 push @parents, @{$options{$parent}{parent}};
196 push @parents, $options{$parent}{parent};
206 if(/^--module-dlls$/) {
207 my @dirs = `cd dlls && find . -type d ! -name CVS`;
209 for my $dir (@dirs) {
211 $dir =~ s/^\.\/(.*)$/$1/;
215 $$module = { active => 1, filter => 1, hash => \%names };
218 $$output->write("unknown option: $_\n");
223 $$output->write("$_: no such file or directory\n");
239 foreach my $file (@files) {
240 if($file =~ /\.c$/) {
241 push @c_files, $file;
242 } elsif($file =~ /\.h$/) {
243 push @h_files, $file;
249 if($#c_files == -1 && $#h_files == -1 &&
250 ($#paths == -1 || ($#paths == 0 && $paths[0] eq $wine_dir)))
253 push @h_files, "$wine_dir/include";
258 if($#paths != -1 || $#c_files != -1) {
259 my $c_command = "find " . join(" ", @paths, @c_files) . " -name \\*.c";
261 @$c_files = sort(map {
263 if(defined($found{$_}) || /glue\.c|spec\.c$/) {
269 } split(/\n/, `$c_command`));
272 if($#h_files != -1) {
273 my $h_command = "find " . join(" ", @h_files) . " -name \\*.h";
276 @$h_files = sort(map {
278 if(defined($found{$_})) {
284 } split(/\n/, `$h_command`));
293 for my $name (sort(keys(%options))) {
294 my $option = $options{$name};
297 $$option{key} = $key;
298 my $refvalue = \${$self->{$key}};
301 $$refvalue = $$option{default};
303 if($name !~ /^help|debug|verbose|module$/) {
304 if(ref($$refvalue) ne "HASH") {
307 $$refvalue = { active => 1, filter => 0, hash => {} };
311 if($name !~ /^help|debug|verbose|module$/) {
312 if(ref($$refvalue) ne "HASH") {
315 $$refvalue = { active => 0, filter => 0, hash => {} };
326 for my $name (sort(keys(%options))) {
327 if(length($name) > $maxname) {
328 $maxname = length($name);
332 print "usage: winapi-check [--help] [<files>]\n";
334 for my $name (sort(keys(%options))) {
335 my $option = $options{$name};
336 my $description = $$option{description};
337 my $default = $$option{default};
338 my $current = ${$self->{$$option{key}}};
340 my $value = $current;
343 if(ref($value) ne "HASH") {
345 $output = "--no-$name";
350 if($value->{active}) {
351 $output = "--[no-]$name\[=<value>]";
353 $output = "--$name\[=<value>]";
358 for (0..(($maxname - length($name) + 17) - (length($output) - length($name) + 1))) { print " "; }
359 if(ref($value) ne "HASH") {
366 if($value->{active}) {
372 if($default == $current) {
373 print "$description (default)\n";
375 print "$description\n";
383 my $name = $winapi_options::AUTOLOAD;
384 $name =~ s/^.*::(.[^:]*)$/\U$1/;
386 my $refvalue = $self->{$name};
387 if(!defined($refvalue)) {
388 die "<internal>: winapi_options.pm: member $name does not exists\n";
391 if(ref($$refvalue) ne "HASH") {
394 return $$refvalue->{active};
398 sub c_files { my $self = shift; return @{$self->{C_FILES}}; }
400 sub h_files { my $self = shift; return @{$self->{H_FILES}}; }
404 my $refvalue = $self->{MODULE};
409 return $$refvalue->{active} && (!$$refvalue->{filter} || $$refvalue->{hash}->{$name});
415 sub report_argument_forbidden {
417 my $refargument_forbidden = $self->{ARGUMENT_FORBIDDEN};
421 return $$refargument_forbidden->{active} && (!$$refargument_forbidden->{filter} || $$refargument_forbidden->{hash}->{$type});
424 sub report_argument_kind {
426 my $refargument_kind = $self->{ARGUMENT_KIND};
430 return $$refargument_kind->{active} && (!$$refargument_kind->{filter} || $$refargument_kind->{hash}->{$kind});