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 "win16" => { default => 1, description => "Win16 checking" },
27 "win32" => { default => 1, description => "Win32 checking" },
29 "shared" => { default => 0, description => "show shared functions between Win16 and Win32" },
30 "shared-segmented" => { default => 0, description => "segmented shared functions between Win16 and Win32 checking" },
32 "local" => { default => 1, description => "local checking" },
34 default => { active => 1, filter => 0, hash => {} },
36 parser => \&parser_comma_list,
37 description => "module filter"
40 "argument" => { default => 1, parent => "local", description => "argument checking" },
41 "argument-count" => { default => 1, parent => "argument", description => "argument count checking" },
42 "argument-forbidden" => {
43 default => { active => 0, filter => 0, hash => {} },
45 parser => \&parser_comma_list,
46 description => "argument forbidden checking"
49 default => { active => 0, filter => 0, hash => {} },
51 parser => \&parser_comma_list,
52 description => "argument kind checking"
54 "calling-convention" => { default => 0, parent => "local", description => "calling convention checking" },
55 "misplaced" => { default => 0, parent => "local", description => "checking for misplaced functions" },
57 "global" => { default => 1, description => "global checking" },
58 "declared" => { default => 1, parent => "global", description => "declared checking" },
59 "implemented" => { default => 0, parent => "global", description => "implemented checking" }
71 my $class = ref($proto) || $proto;
73 bless ($self, $class);
75 my $refarguments = shift;
76 my @ARGV = @$refarguments;
78 for my $name (sort(keys(%options))) {
79 my $option = $options{$name};
83 my $refvalue = \${$self->{$key}};
84 $$refvalue = $$option{default};
87 my $files = \@{$self->{FILES}};
88 my $module = \${$self->{MODULE}};
89 my $global = \${$self->{GLOBAL}};
92 while(defined($_ = shift @ARGV)) {
93 if(/^-([^=]*)(=(.*))?$/) {
103 if($name =~ /^([^-].*)$/) {
104 $name = $short_options{$1};
106 $name =~ s/^-(.*)$/$1/;
110 if($name =~ /^no-(.*)$/) {
113 if(defined($value)) {
114 print STDERR "<internal>: options with prefix 'no' can't take parameters\n";
119 my $option = $options{$name};
120 if(defined($option)) {
121 my $key = $$option{key};
122 my $parser = $$option{parser};
123 my $refvalue = \${$self->{$key}};
125 if(defined($parser)) {
126 $$refvalue = &$parser($prefix,$value);
128 if(defined($value)) {
130 } elsif(!defined($prefix)) {
140 if(/^--module-dlls$/) {
141 my @dirs = `cd dlls && find ./ -type d ! -name CVS`;
143 for my $dir (@dirs) {
145 $dir =~ s/^\.\/(.*)$/$1/;
149 $$module = { active => 1, filter => 1, hash => \%names };
152 print STDERR "<internal>: unknown option: $&\n";
153 print STDERR "<internal>: usage: winapi-check [--help] [<files>]\n";
165 $paths = join(" ",@$files);
171 } split(/\n/, `find $paths -name \\*.c`);
180 for my $name (sort(keys(%options))) {
181 if(length($name) > $maxname) {
182 $maxname = length($name);
186 print "usage: winapi-check [--help] [<files>]\n";
188 for my $name (sort(keys(%options))) {
189 my $option = $options{$name};
190 my $description = $$option{description};
191 my $default = $$option{default};
194 if(ref($default) ne "HASH") {
196 $output = "--no-$name";
201 if($default->{active}) {
202 $output = "--[no-]$name\[=<value>]";
204 $output = "--$name\[=<value>]";
209 for (0..(($maxname - length($name) + 14) - (length($output) - length($name) + 1))) { print " "; }
210 if(ref($default) ne "HASH") {
212 print "Disable $description\n";
214 print "Enable $description\n";
217 if($default->{active}) {
218 print "(Disable) $description\n";
220 print "Enable $description\n";
231 my $name = $winapi_options::AUTOLOAD;
232 $name =~ s/^.*::(.[^:]*)$/\U$1/;
234 my $refvalue = $self->{$name};
235 if(!defined($refvalue)) {
236 die "<internal>: winapi_options.pm: member $name does not exists\n";
241 sub files { my $self = shift; return @{$self->{FILES}}; }
245 my $module = $self->module;
250 return $module->{active} && (!$module->{filter} || $module->{hash}->{$name});
256 sub report_argument_forbidden {
258 my $argument_forbidden = $self->argument_forbidden;
262 return $argument_forbidden->{active} && (!$argument_forbidden->{filter} || $argument_forbidden->{hash}->{$type});
265 sub report_argument_kind {
267 my $argument_kind = $self->argument_kind;
271 return $argument_kind->{active} && (!$argument_kind->{filter} || $argument_kind->{hash}->{$kind});