5 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
10 @EXPORT_OK = qw($options &parse_comma_list);
12 use vars qw($options);
14 sub parse_comma_list {
17 if(defined($prefix) && $prefix eq "no") {
18 return { active => 0, filter => 0, hash => {} };
19 } elsif(defined($value)) {
21 for my $name (split /,/, $value) {
24 return { active => 1, filter => 1, hash => \%names };
26 return { active => 1, filter => 0, hash => {} };
34 use config qw($current_dir $wine_dir);
35 use output qw($output);
39 my $class = ref($proto) || $proto;
41 bless ($self, $class);
43 my $options_long = \%{$self->{_OPTIONS_LONG}};
44 my $options_short = \%{$self->{_OPTIONS_SHORT}};
45 my $options_usage = \${$self->{_OPTIONS_USAGE}};
47 my $refoptions_long = shift;
48 my $refoptions_short = shift;
49 $$options_usage = shift;
51 %$options_long = %{$refoptions_long};
52 %$options_short = %{$refoptions_short};
54 $self->options_set("default");
56 my $arguments = \@{$self->{_ARGUMENTS}};
58 my $end_of_options = 0;
59 while(defined($_ = shift @ARGV)) {
63 } elsif($end_of_options) {
65 } elsif(/^--(all|none)$/) {
66 $self->options_set("$1");
68 } elsif(/^-([^=]*)(=(.*))?$/) {
78 if($name =~ /^([^-].*)$/) {
79 $name = $$options_short{$1};
81 $name =~ s/^-(.*)$/$1/;
85 if(defined($name) && $name =~ /^no-(.*)$/) {
89 $output->write("options with prefix 'no' can't take parameters\n");
97 $option = $$options_long{$name};
100 if(defined($option)) {
101 my $key = $$option{key};
102 my $parser = $$option{parser};
103 my $refvalue = \${$self->{$key}};
106 if(defined($$option{parent})) {
107 if(ref($$option{parent}) eq "ARRAY") {
108 @parents = @{$$option{parent}};
110 @parents = $$option{parent};
114 if(defined($parser)) {
115 $$refvalue = &$parser($prefix,$value);
117 if(defined($value)) {
119 } elsif(!defined($prefix)) {
126 if((ref($$refvalue) eq "HASH" && $$refvalue->{active}) || $$refvalue) {
127 while($#parents >= 0) {
128 my @old_parents = @parents;
130 foreach my $parent (@old_parents) {
131 my $parentkey = $$options_long{$parent}{key};
132 my $refparentvalue = \${$self->{$parentkey}};
134 $$refparentvalue = 1;
136 if(defined($$options_long{$parent}{parent})) {
137 if(ref($$options_long{$parent}{parent}) eq "ARRAY") {
138 push @parents, @{$$options_long{$parent}{parent}};
140 push @parents, $$options_long{$parent}{parent};
150 if(!$end_of_options && /^-(.*)$/) {
151 $output->write("unknown option: $_\n");
152 $output->write($$options_usage);
155 push @$arguments, $_;
160 $output->write($$options_usage);
174 my $arguments = \@{$self->{_ARGUMENTS}};
175 my $c_files = \@{$self->{_C_FILES}};
176 my $h_files = \@{$self->{_H_FILES}};
180 foreach (@$arguments) {
182 $output->write("$_: no such file or directory\n");
195 foreach my $file (@files) {
196 if($file =~ /\.c$/) {
197 push @c_files, $file;
198 } elsif($file =~ /\.h$/) {
199 push @h_files, $file;
205 if($#c_files == -1 && $#h_files == -1 && $#paths == -1)
210 if($#paths != -1 || $#c_files != -1) {
211 my $c_command = "find " . join(" ", @paths, @c_files) . " -name \\*.c";
213 @$c_files = sort(map {
215 if(defined($found{$_})) {
221 } split(/\n/, `$c_command`));
224 if($#paths != -1 || $#h_files != -1) {
225 my $h_command = "find " . join(" ", @paths, @h_files) . " -name \\*.h";
228 @$h_files = sort(map {
230 if(defined($found{$_})) {
236 } split(/\n/, `$h_command`));
243 my $options_long = \%{$self->{_OPTIONS_LONG}};
244 my $options_short = \%{$self->{_OPTIONS_SHORT}};
247 for my $name (sort(keys(%$options_long))) {
248 my $option = $$options_long{$name};
251 $$option{key} = $key;
252 my $refvalue = \${$self->{$key}};
255 $$refvalue = $$option{default};
257 if($name !~ /^help|debug|verbose|module$/) {
258 if(ref($$refvalue) ne "HASH") {
261 $$refvalue = { active => 1, filter => 0, hash => {} };
265 if($name !~ /^help|debug|verbose|module$/) {
266 if(ref($$refvalue) ne "HASH") {
269 $$refvalue = { active => 0, filter => 0, hash => {} };
279 my $options_long = \%{$self->{_OPTIONS_LONG}};
280 my $options_short = \%{$self->{_OPTIONS_SHORT}};
283 for my $name (sort(keys(%$options_long))) {
284 if(length($name) > $maxname) {
285 $maxname = length($name);
289 for my $name (sort(keys(%$options_long))) {
290 my $option = $$options_long{$name};
291 my $description = $$option{description};
292 my $default = $$option{default};
293 my $current = ${$self->{$$option{key}}};
295 my $value = $current;
298 if(ref($value) ne "HASH") {
300 $command = "--no-$name";
302 $command = "--$name";
305 if($value->{active}) {
306 $command = "--[no-]$name\[=<value>]";
308 $command = "--$name\[=<value>]";
312 $output->write($command);
313 for (0..(($maxname - length($name) + 17) - (length($command) - length($name) + 1))) { $output->write(" "); }
314 if(ref($value) ne "HASH") {
316 $output->write("Disable ");
318 $output->write("Enable ");
321 if($value->{active}) {
322 $output->write("(Disable) ");
324 $output->write("Enable ");
327 if($default == $current) {
328 $output->write("$description (default)\n");
330 $output->write("$description\n");
338 my $name = $_options::AUTOLOAD;
339 $name =~ s/^.*::(.[^:]*)$/\U$1/;
341 my $refvalue = $self->{$name};
342 if(!defined($refvalue)) {
343 die "<internal>: options.pm: member $name does not exists\n";
346 if(ref($$refvalue) ne "HASH") {
349 return $$refvalue->{active};
356 my $arguments = \@{$self->{_ARGUMENTS}};
364 my $c_files = \@{$self->{_C_FILES}};
366 if(!defined(@$c_files)) {
376 my $h_files = \@{$self->{_H_FILES}};
378 if(!defined(@$h_files)) {