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 "local" => { default => 1, description => "local checking" },
39 default => { active => 1, filter => 0, hash => {} },
41 parser => \&parser_comma_list,
42 description => "module filter"
45 "argument" => { default => 1, parent => "local", description => "argument checking" },
46 "argument-count" => { default => 1, parent => "argument", description => "argument count checking" },
47 "argument-forbidden" => {
48 default => { active => 1, filter => 0, hash => {} },
50 parser => \&parser_comma_list,
51 description => "argument forbidden checking"
54 default => { active => 0, filter => 0, hash => {} },
56 parser => \&parser_comma_list,
57 description => "argument kind checking"
59 "calling-convention" => { default => 0, parent => "local", description => "calling convention checking" },
60 "misplaced" => { default => 0, parent => "local", description => "check for misplaced functions" },
61 "cross-call" => { default => 0, parent => "local", description => "check for cross calling functions" },
63 "global" => { default => 1, description => "global checking" },
64 "declared" => { default => 1, parent => "global", description => "declared checking" },
65 "implemented" => { default => 1, parent => "global", description => "implemented checking" },
66 "implemented-win32" => { default => 0, parent => "implemented", description => "implemented as win32 checking" },
67 "include" => { default => 0, parent => "global", description => "include checking" }
78 my $class = ref($proto) || $proto;
80 bless ($self, $class);
82 my $refarguments = shift;
83 my @ARGV = @$refarguments;
85 for my $name (sort(keys(%options))) {
86 my $option = $options{$name};
90 my $refvalue = \${$self->{$key}};
91 $$refvalue = $$option{default};
94 my $files = \@{$self->{FILES}};
95 my $module = \${$self->{MODULE}};
96 my $global = \${$self->{GLOBAL}};
99 while(defined($_ = shift @ARGV)) {
100 if(/^-([^=]*)(=(.*))?$/) {
110 if($name =~ /^([^-].*)$/) {
111 $name = $short_options{$1};
113 $name =~ s/^-(.*)$/$1/;
117 if($name =~ /^no-(.*)$/) {
120 if(defined($value)) {
121 print STDERR "<internal>: options with prefix 'no' can't take parameters\n";
126 my $option = $options{$name};
127 if(defined($option)) {
128 my $key = $$option{key};
129 my $parser = $$option{parser};
130 my $refvalue = \${$self->{$key}};
132 if(defined($parser)) {
133 $$refvalue = &$parser($prefix,$value);
135 if(defined($value)) {
137 } elsif(!defined($prefix)) {
147 if(/^--module-dlls$/) {
148 my @dirs = `cd dlls && find ./ -type d ! -name CVS`;
150 for my $dir (@dirs) {
152 $dir =~ s/^\.\/(.*)$/$1/;
156 $$module = { active => 1, filter => 1, hash => \%names };
159 print STDERR "<internal>: unknown option: $&\n";
160 print STDERR "<internal>: usage: winapi-check [--help] [<files>]\n";
172 $paths = join(" ",@$files);
178 } split(/\n/, `find $paths -name \\*.c`);
187 for my $name (sort(keys(%options))) {
188 if(length($name) > $maxname) {
189 $maxname = length($name);
193 print "usage: winapi-check [--help] [<files>]\n";
195 for my $name (sort(keys(%options))) {
196 my $option = $options{$name};
197 my $description = $$option{description};
198 my $default = $$option{default};
201 if(ref($default) ne "HASH") {
203 $output = "--no-$name";
208 if($default->{active}) {
209 $output = "--[no-]$name\[=<value>]";
211 $output = "--$name\[=<value>]";
216 for (0..(($maxname - length($name) + 14) - (length($output) - length($name) + 1))) { print " "; }
217 if(ref($default) ne "HASH") {
219 print "Disable $description\n";
221 print "Enable $description\n";
224 if($default->{active}) {
225 print "(Disable) $description\n";
227 print "Enable $description\n";
238 my $name = $winapi_options::AUTOLOAD;
239 $name =~ s/^.*::(.[^:]*)$/\U$1/;
241 my $refvalue = $self->{$name};
242 if(!defined($refvalue)) {
243 die "<internal>: winapi_options.pm: member $name does not exists\n";
248 sub files { my $self = shift; return @{$self->{FILES}}; }
252 my $module = $self->module;
257 return $module->{active} && (!$module->{filter} || $module->{hash}->{$name});
263 sub report_argument_forbidden {
265 my $argument_forbidden = $self->argument_forbidden;
269 return $argument_forbidden->{active} && (!$argument_forbidden->{filter} || $argument_forbidden->{hash}->{$type});
272 sub report_argument_kind {
274 my $argument_kind = $self->argument_kind;
278 return $argument_kind->{active} && (!$argument_kind->{filter} || $argument_kind->{hash}->{$kind});