1 package winapi_options;
5 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
9 @EXPORT = qw(&parse_comma_list);
10 @EXPORT_OK = qw($options);
12 use vars qw($options);
14 use config qw($current_dir $wine_dir);
15 use output qw($output);
17 sub parser_comma_list {
20 if(defined($prefix) && $prefix eq "no") {
21 return { active => 0, filter => 0, hash => {} };
22 } elsif(defined($value)) {
24 for my $name (split /,/, $value) {
27 return { active => 1, filter => 1, hash => \%names };
29 return { active => 1, filter => 0, hash => {} };
34 "debug" => { default => 0, description => "debug mode" },
35 "help" => { default => 0, description => "help mode" },
36 "verbose" => { default => 0, description => "verbose mode" },
38 "progress" => { default => 1, description => "show progress" },
40 "win16" => { default => 1, description => "Win16 checking" },
41 "win32" => { default => 1, description => "Win32 checking" },
43 "shared" => { default => 0, description => "show shared functions between Win16 and Win32" },
44 "shared-segmented" => { default => 0, description => "segmented shared functions between Win16 and Win32 checking" },
46 "config" => { default => 1, parent => "local", description => "check configuration include consistancy" },
47 "config-unnessary" => { default => 0, parent => "config", description => "check for unnessary #include \"config.h\"" },
49 "spec-mismatch" => { default => 0, description => "spec file mismatch checking" },
51 "local" => { default => 1, description => "local checking" },
53 default => { active => 1, filter => 0, hash => {} },
55 parser => \&parser_comma_list,
56 description => "module filter"
59 "argument" => { default => 1, parent => "local", description => "argument checking" },
60 "argument-count" => { default => 1, parent => "argument", description => "argument count checking" },
61 "argument-forbidden" => {
62 default => { active => 1, filter => 0, hash => {} },
64 parser => \&parser_comma_list,
65 description => "argument forbidden checking"
68 default => { active => 1, filter => 1, hash => { double => 1 } },
70 parser => \&parser_comma_list,
71 description => "argument kind checking"
73 "calling-convention" => { default => 1, parent => "local", description => "calling convention checking" },
74 "calling-convention-win16" => { default => 0, parent => "calling-convention", description => "calling convention checking (Win16)" },
75 "calling-convention-win32" => { default => 1, parent => "calling-convention", description => "calling convention checking (Win32)" },
76 "misplaced" => { default => 1, parent => "local", description => "check for misplaced functions" },
77 "statements" => { default => 0, parent => "local", description => "check for statements inconsistances" },
78 "cross-call" => { default => 0, parent => "statements", description => "check for cross calling functions" },
79 "cross-call-win32-win16" => {
80 default => 0, parent => "cross-call", description => "check for cross calls between win32 and win16"
82 "cross-call-unicode-ascii" => {
83 default => 0, parent => "cross-call", description => "check for cross calls between Unicode and ASCII"
85 "debug-messages" => { default => 0, parent => "statements", description => "check for debug messages inconsistances" },
90 description => "check for documentation inconsistances"
92 "documentation-pedantic" => {
94 parent => "documentation",
95 description => "be pendantic when checking for documentation inconsistances"
98 "documentation-arguments" => {
100 parent => "documentation",
101 description => "check for arguments documentation inconsistances\n"
103 "documentation-comment-indent" => {
105 parent => "documentation", description => "check for documentation comment indent inconsistances"
107 "documentation-comment-width" => {
109 parent => "documentation", description => "check for documentation comment width inconsistances"
111 "documentation-name" => {
113 parent => "documentation",
114 description => "check for documentation name inconsistances\n"
116 "documentation-ordinal" => {
118 parent => "documentation",
119 description => "check for documentation ordinal inconsistances\n"
121 "documentation-wrong" => {
123 parent => "documentation",
124 description => "check for wrong documentation\n"
127 "prototype" => {default => 0, parent => ["local", "headers"], description => "prototype checking" },
128 "global" => { default => 1, description => "global checking" },
129 "declared" => { default => 1, parent => "global", description => "declared checking" },
130 "implemented" => { default => 0, parent => "local", description => "implemented checking" },
131 "implemented-win32" => { default => 0, parent => "implemented", description => "implemented as win32 checking" },
132 "include" => { default => 1, parent => "global", description => "include checking" },
134 "headers" => { default => 0, description => "headers checking" },
135 "headers-duplicated" => { default => 0, parent => "headers", description => "duplicated function declarations checking" },
136 "headers-misplaced" => { default => 0, parent => "headers", description => "misplaced function declarations checking" },
137 "headers-needed" => { default => 1, parent => "headers", description => "headers needed checking" },
138 "headers-unused" => { default => 0, parent => "headers", description => "headers unused checking" },
141 my %short_options = (
149 my $class = ref($proto) || $proto;
151 bless ($self, $class);
153 $self->options_set("default");
155 my $c_files = \@{$self->{C_FILES}};
156 my $h_files = \@{$self->{H_FILES}};
157 my $module = \${$self->{MODULE}};
158 my $global = \${$self->{GLOBAL}};
159 my $headers = \${$self->{HEADERS}};
163 if($wine_dir eq ".") {
169 while(defined($_ = shift @ARGV)) {
170 if(/^--(all|none)$/) {
171 $self->options_set("$1");
173 } elsif(/^-([^=]*)(=(.*))?$/) {
183 if($name =~ /^([^-].*)$/) {
184 $name = $short_options{$1};
186 $name =~ s/^-(.*)$/$1/;
190 if(defined($name) && $name =~ /^no-(.*)$/) {
193 if(defined($value)) {
194 $output->write("options with prefix 'no' can't take parameters\n");
202 $option = $options{$name};
205 if(defined($option)) {
206 my $key = $$option{key};
207 my $parser = $$option{parser};
208 my $refvalue = \${$self->{$key}};
211 if(defined($$option{parent})) {
212 if(ref($$option{parent}) eq "ARRAY") {
213 @parents = @{$$option{parent}};
215 @parents = $$option{parent};
219 if(defined($parser)) {
220 $$refvalue = &$parser($prefix,$value);
222 if(defined($value)) {
224 } elsif(!defined($prefix)) {
231 if((ref($$refvalue) eq "HASH" && $$refvalue->{active}) || $$refvalue) {
232 while($#parents >= 0) {
233 my @old_parents = @parents;
235 foreach my $parent (@old_parents) {
236 my $parentkey = $options{$parent}{key};
237 my $refparentvalue = \${$self->{$parentkey}};
239 $$refparentvalue = 1;
241 if(defined($options{$parent}{parent})) {
242 if(ref($options{$parent}{parent}) eq "ARRAY") {
243 push @parents, @{$options{$parent}{parent}};
245 push @parents, $options{$parent}{parent};
255 if(/^--module-dlls$/) {
256 my @dirs = `cd dlls && find . -type d ! -name CVS`;
258 for my $dir (@dirs) {
260 $dir =~ s/^\.\/(.*)$/$1/;
264 $$module = { active => 1, filter => 1, hash => \%names };
267 $output->write("unknown option: $_\n");
272 $output->write("$_: no such file or directory\n");
288 foreach my $file (@files) {
289 if($file =~ /\.c$/) {
290 push @c_files, $file;
291 } elsif($file =~ /\.h$/) {
292 push @h_files, $file;
302 if($#c_files == -1 && $#h_files == -1 &&
303 ($#paths == -1 || ($#paths == 0 && $paths[0] eq $wine_dir)))
310 if($#paths != -1 || $#c_files != -1) {
311 my $c_command = "find " . join(" ", @paths, @c_files) . " -name \\*.c";
313 @$c_files = sort(map {
315 if(defined($found{$_}) || /glue\.c|spec\.c$/) {
321 } split(/\n/, `$c_command`));
324 if($#paths != -1 || $#h_files != -1) {
325 my $h_command = "find " . join(" ", @paths, @h_files) . " -name \\*.h";
328 @$h_files = sort(map {
330 if(defined($found{$_})) {
336 } split(/\n/, `$h_command`));
351 for my $name (sort(keys(%options))) {
352 my $option = $options{$name};
355 $$option{key} = $key;
356 my $refvalue = \${$self->{$key}};
359 $$refvalue = $$option{default};
361 if($name !~ /^help|debug|verbose|module$/) {
362 if(ref($$refvalue) ne "HASH") {
365 $$refvalue = { active => 1, filter => 0, hash => {} };
369 if($name !~ /^help|debug|verbose|module$/) {
370 if(ref($$refvalue) ne "HASH") {
373 $$refvalue = { active => 0, filter => 0, hash => {} };
384 for my $name (sort(keys(%options))) {
385 if(length($name) > $maxname) {
386 $maxname = length($name);
390 print "usage: winapi-check [--help] [<files>]\n";
392 for my $name (sort(keys(%options))) {
393 my $option = $options{$name};
394 my $description = $$option{description};
395 my $default = $$option{default};
396 my $current = ${$self->{$$option{key}}};
398 my $value = $current;
401 if(ref($value) ne "HASH") {
403 $output = "--no-$name";
408 if($value->{active}) {
409 $output = "--[no-]$name\[=<value>]";
411 $output = "--$name\[=<value>]";
416 for (0..(($maxname - length($name) + 17) - (length($output) - length($name) + 1))) { print " "; }
417 if(ref($value) ne "HASH") {
424 if($value->{active}) {
430 if($default == $current) {
431 print "$description (default)\n";
433 print "$description\n";
441 my $name = $winapi_options::AUTOLOAD;
442 $name =~ s/^.*::(.[^:]*)$/\U$1/;
444 my $refvalue = $self->{$name};
445 if(!defined($refvalue)) {
446 die "<internal>: winapi_options.pm: member $name does not exists\n";
449 if(ref($$refvalue) ne "HASH") {
452 return $$refvalue->{active};
456 sub c_files { my $self = shift; return @{$self->{C_FILES}}; }
458 sub h_files { my $self = shift; return @{$self->{H_FILES}}; }
462 my $refvalue = $self->{MODULE};
467 return $$refvalue->{active} && (!$$refvalue->{filter} || $$refvalue->{hash}->{$name});
473 sub report_argument_forbidden {
475 my $refargument_forbidden = $self->{ARGUMENT_FORBIDDEN};
479 return $$refargument_forbidden->{active} && (!$$refargument_forbidden->{filter} || $$refargument_forbidden->{hash}->{$type});
482 sub report_argument_kind {
484 my $refargument_kind = $self->{ARGUMENT_KIND};
488 return $$refargument_kind->{active} && (!$$refargument_kind->{filter} || $$refargument_kind->{hash}->{$kind});