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" },
78 description => "check for documentation inconsistances"
80 "documentation-pedantic" => {
82 parent => "documentation",
83 description => "be pendantic when checking for documentation inconsistances"
86 "documentation-arguments" => {
88 parent => "documentation",
89 description => "check for arguments documentation inconsistances\n"
91 "documentation-comment-indent" => {
93 parent => "documentation", description => "check for documentation comment indent inconsistances"
95 "documentation-comment-width" => {
97 parent => "documentation", description => "check for documentation comment width inconsistances"
99 "documentation-name" => {
101 parent => "documentation",
102 description => "check for documentation name inconsistances\n"
104 "documentation-ordinal" => {
106 parent => "documentation",
107 description => "check for documentation ordinal inconsistances\n"
110 "prototype" => {default => 0, parent => ["local", "headers"], description => "prototype checking" },
111 "global" => { default => 1, description => "global checking" },
112 "declared" => { default => 1, parent => "global", description => "declared checking" },
113 "implemented" => { default => 0, parent => "local", description => "implemented checking" },
114 "implemented-win32" => { default => 0, parent => "implemented", description => "implemented as win32 checking" },
115 "include" => { default => 1, parent => "global", description => "include checking" },
116 "headers" => { default => 0, parent => "global", description => "headers checking" },
117 "headers-duplicated" => { default => 0, parent => "headers", description => "duplicated function declarations checking" },
118 "headers-misplaced" => { default => 0, parent => "headers", description => "misplaced function declarations checking" },
119 "stubs" => { default => 0, parent => "global", description => "stubs checking" }
122 my %short_options = (
130 my $class = ref($proto) || $proto;
132 bless ($self, $class);
134 my $output = \${$self->{OUTPUT}};
137 my $refarguments = shift;
138 my $wine_dir = shift;
140 $self->options_set("default");
142 my $c_files = \@{$self->{C_FILES}};
143 my $h_files = \@{$self->{H_FILES}};
144 my $module = \${$self->{MODULE}};
145 my $global = \${$self->{GLOBAL}};
149 if($wine_dir eq ".") {
155 while(defined($_ = shift @$refarguments)) {
156 if(/^--(all|none)$/) {
157 $self->options_set("$1");
159 } elsif(/^-([^=]*)(=(.*))?$/) {
169 if($name =~ /^([^-].*)$/) {
170 $name = $short_options{$1};
172 $name =~ s/^-(.*)$/$1/;
176 if(defined($name) && $name =~ /^no-(.*)$/) {
179 if(defined($value)) {
180 $$output->write("options with prefix 'no' can't take parameters\n");
188 $option = $options{$name};
191 if(defined($option)) {
192 my $key = $$option{key};
193 my $parser = $$option{parser};
194 my $refvalue = \${$self->{$key}};
197 if(defined($$option{parent})) {
198 if(ref($$option{parent}) eq "ARRAY") {
199 @parents = @{$$option{parent}};
201 @parents = $$option{parent};
205 if(defined($parser)) {
206 $$refvalue = &$parser($prefix,$value);
208 if(defined($value)) {
210 } elsif(!defined($prefix)) {
217 if((ref($$refvalue) eq "HASH" && $$refvalue->{active}) || $$refvalue) {
218 while($#parents >= 0) {
219 my @old_parents = @parents;
221 foreach my $parent (@old_parents) {
222 my $parentkey = $options{$parent}{key};
223 my $refparentvalue = \${$self->{$parentkey}};
225 $$refparentvalue = 1;
227 if(defined($options{$parent}{parent})) {
228 if(ref($options{$parent}{parent}) eq "ARRAY") {
229 push @parents, @{$options{$parent}{parent}};
231 push @parents, $options{$parent}{parent};
241 if(/^--module-dlls$/) {
242 my @dirs = `cd dlls && find . -type d ! -name CVS`;
244 for my $dir (@dirs) {
246 $dir =~ s/^\.\/(.*)$/$1/;
250 $$module = { active => 1, filter => 1, hash => \%names };
253 $$output->write("unknown option: $_\n");
258 $$output->write("$_: no such file or directory\n");
274 foreach my $file (@files) {
275 if($file =~ /\.c$/) {
276 push @c_files, $file;
277 } elsif($file =~ /\.h$/) {
278 push @h_files, $file;
284 if($#c_files == -1 && $#h_files == -1 &&
285 ($#paths == -1 || ($#paths == 0 && $paths[0] eq $wine_dir)))
288 push @h_files, "$wine_dir/include";
293 if($#paths != -1 || $#c_files != -1) {
294 my $c_command = "find " . join(" ", @paths, @c_files) . " -name \\*.c";
296 @$c_files = sort(map {
298 if(defined($found{$_}) || /glue\.c|spec\.c$/) {
304 } split(/\n/, `$c_command`));
307 if($#h_files != -1) {
308 my $h_command = "find " . join(" ", @h_files) . " -name \\*.h";
311 @$h_files = sort(map {
313 if(defined($found{$_})) {
319 } split(/\n/, `$h_command`));
331 for my $name (sort(keys(%options))) {
332 my $option = $options{$name};
335 $$option{key} = $key;
336 my $refvalue = \${$self->{$key}};
339 $$refvalue = $$option{default};
341 if($name !~ /^help|debug|verbose|module$/) {
342 if(ref($$refvalue) ne "HASH") {
345 $$refvalue = { active => 1, filter => 0, hash => {} };
349 if($name !~ /^help|debug|verbose|module$/) {
350 if(ref($$refvalue) ne "HASH") {
353 $$refvalue = { active => 0, filter => 0, hash => {} };
364 for my $name (sort(keys(%options))) {
365 if(length($name) > $maxname) {
366 $maxname = length($name);
370 print "usage: winapi-check [--help] [<files>]\n";
372 for my $name (sort(keys(%options))) {
373 my $option = $options{$name};
374 my $description = $$option{description};
375 my $default = $$option{default};
376 my $current = ${$self->{$$option{key}}};
378 my $value = $current;
381 if(ref($value) ne "HASH") {
383 $output = "--no-$name";
388 if($value->{active}) {
389 $output = "--[no-]$name\[=<value>]";
391 $output = "--$name\[=<value>]";
396 for (0..(($maxname - length($name) + 17) - (length($output) - length($name) + 1))) { print " "; }
397 if(ref($value) ne "HASH") {
404 if($value->{active}) {
410 if($default == $current) {
411 print "$description (default)\n";
413 print "$description\n";
421 my $name = $winapi_options::AUTOLOAD;
422 $name =~ s/^.*::(.[^:]*)$/\U$1/;
424 my $refvalue = $self->{$name};
425 if(!defined($refvalue)) {
426 die "<internal>: winapi_options.pm: member $name does not exists\n";
429 if(ref($$refvalue) ne "HASH") {
432 return $$refvalue->{active};
436 sub c_files { my $self = shift; return @{$self->{C_FILES}}; }
438 sub h_files { my $self = shift; return @{$self->{H_FILES}}; }
442 my $refvalue = $self->{MODULE};
447 return $$refvalue->{active} && (!$$refvalue->{filter} || $$refvalue->{hash}->{$name});
453 sub report_argument_forbidden {
455 my $refargument_forbidden = $self->{ARGUMENT_FORBIDDEN};
459 return $$refargument_forbidden->{active} && (!$$refargument_forbidden->{filter} || $$refargument_forbidden->{hash}->{$type});
462 sub report_argument_kind {
464 my $refargument_kind = $self->{ARGUMENT_KIND};
468 return $$refargument_kind->{active} && (!$$refargument_kind->{filter} || $$refargument_kind->{hash}->{$kind});