5 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
9 @EXPORT = qw(&parse_comma_list);
12 sub parse_comma_list {
15 if(defined($prefix) && $prefix eq "no") {
16 return { active => 0, filter => 0, hash => {} };
17 } elsif(defined($value)) {
19 for my $name (split /,/, $value) {
22 return { active => 1, filter => 1, hash => \%names };
24 return { active => 1, filter => 0, hash => {} };
32 $_options = _options->new(@_);
39 my $name = $options::AUTOLOAD;
40 $name =~ s/^.*::(.[^:]*)$/$1/;
42 return $_options->$name(@_);
51 my $class = ref($proto) || $proto;
53 bless ($self, $class);
55 my $options_long = \%{$self->{OPTIONS_LONG}};
56 my $options_short = \%{$self->{OPTIONS_SHORT}};
57 my $options_usage = \${$self->{OPTIONS_USAGE}};
59 my $refoptions_long = shift;
60 my $refoptions_short = shift;
61 $$options_usage = shift;
63 %$options_long = %{$refoptions_long};
64 %$options_short = %{$refoptions_short};
66 $self->options_set("default");
68 my $c_files = \@{$self->{C_FILES}};
69 my $h_files = \@{$self->{H_FILES}};
72 while(defined($_ = shift @ARGV)) {
73 if(/^--(all|none)$/) {
74 $self->options_set("$1");
76 } elsif(/^-([^=]*)(=(.*))?$/) {
86 if($name =~ /^([^-].*)$/) {
87 $name = $$options_short{$1};
89 $name =~ s/^-(.*)$/$1/;
93 if(defined($name) && $name =~ /^no-(.*)$/) {
97 output->write("options with prefix 'no' can't take parameters\n");
105 $option = $$options_long{$name};
108 if(defined($option)) {
109 my $key = $$option{key};
110 my $parser = $$option{parser};
111 my $refvalue = \${$self->{$key}};
114 if(defined($$option{parent})) {
115 if(ref($$option{parent}) eq "ARRAY") {
116 @parents = @{$$option{parent}};
118 @parents = $$option{parent};
122 if(defined($parser)) {
123 $$refvalue = &$parser($prefix,$value);
125 if(defined($value)) {
127 } elsif(!defined($prefix)) {
134 if((ref($$refvalue) eq "HASH" && $$refvalue->{active}) || $$refvalue) {
135 while($#parents >= 0) {
136 my @old_parents = @parents;
138 foreach my $parent (@old_parents) {
139 my $parentkey = $$options_long{$parent}{key};
140 my $refparentvalue = \${$self->{$parentkey}};
142 $$refparentvalue = 1;
144 if(defined($$options_long{$parent}{parent})) {
145 if(ref($$options_long{$parent}{parent}) eq "ARRAY") {
146 push @parents, @{$$options_long{$parent}{parent}};
148 push @parents, $$options_long{$parent}{parent};
159 output->write("unknown option: $_\n");
160 output->write($$options_usage);
164 output->write("$_: no such file or directory\n");
173 output->write($$options_usage);
181 foreach my $file (@files) {
182 if($file =~ /\.c$/) {
183 push @c_files, $file;
184 } elsif($file =~ /\.h$/) {
185 push @h_files, $file;
191 if($#c_files == -1 && $#h_files == -1 && $#paths == -1)
196 if($#paths != -1 || $#c_files != -1) {
197 my $c_command = "find " . join(" ", @paths, @c_files) . " -name \\*.c";
199 @$c_files = sort(map {
201 if(defined($found{$_}) || /glue\.c|spec\.c$/) {
207 } split(/\n/, `$c_command`));
210 if($#h_files != -1) {
211 my $h_command = "find " . join(" ", @h_files) . " -name \\*.h";
214 @$h_files = sort(map {
216 if(defined($found{$_})) {
222 } split(/\n/, `$h_command`));
234 my $options_long = \%{$self->{OPTIONS_LONG}};
235 my $options_short = \%{$self->{OPTIONS_SHORT}};
238 for my $name (sort(keys(%$options_long))) {
239 my $option = $$options_long{$name};
242 $$option{key} = $key;
243 my $refvalue = \${$self->{$key}};
246 $$refvalue = $$option{default};
248 if($name !~ /^help|debug|verbose|module$/) {
249 if(ref($$refvalue) ne "HASH") {
252 $$refvalue = { active => 1, filter => 0, hash => {} };
256 if($name !~ /^help|debug|verbose|module$/) {
257 if(ref($$refvalue) ne "HASH") {
260 $$refvalue = { active => 0, filter => 0, hash => {} };
270 my $options_long = \%{$self->{OPTIONS_LONG}};
271 my $options_short = \%{$self->{OPTIONS_SHORT}};
274 for my $name (sort(keys(%$options_long))) {
275 if(length($name) > $maxname) {
276 $maxname = length($name);
280 for my $name (sort(keys(%$options_long))) {
281 my $option = $$options_long{$name};
282 my $description = $$option{description};
283 my $default = $$option{default};
284 my $current = ${$self->{$$option{key}}};
286 my $value = $current;
289 if(ref($value) ne "HASH") {
291 $command = "--no-$name";
293 $command = "--$name";
296 if($value->{active}) {
297 $command = "--[no-]$name\[=<value>]";
299 $command = "--$name\[=<value>]";
303 output->write($command);
304 for (0..(($maxname - length($name) + 17) - (length($command) - length($name) + 1))) { output->write(" "); }
305 if(ref($value) ne "HASH") {
307 output->write("Disable ");
309 output->write("Enable ");
312 if($value->{active}) {
313 output->write("(Disable) ");
315 output->write("Enable ");
318 if($default == $current) {
319 output->write("$description (default)\n");
321 output->write("$description\n");
329 my $name = $_options::AUTOLOAD;
330 $name =~ s/^.*::(.[^:]*)$/\U$1/;
332 my $refvalue = $self->{$name};
333 if(!defined($refvalue)) {
334 die "<internal>: options.pm: member $name does not exists\n";
337 if(ref($$refvalue) ne "HASH") {
340 return $$refvalue->{active};
344 sub c_files { my $self = shift; return @{$self->{C_FILES}}; }
346 sub h_files { my $self = shift; return @{$self->{H_FILES}}; }