diff options
| author | fukachan <fukachan> | 2001-01-20 06:28:21 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2001-01-20 06:28:21 +0000 |
| commit | cd647117635bea41f05d63f9efe2ac257c184a8a (patch) | |
| tree | 71d9f15c13836b11b5730c7d1dca8dbce3d5177b /fml/libexec | |
| parent | 8df7b14435b051c7d024d2f429d23b69b153fbff (diff) | |
| download | fml8-cd647117635bea41f05d63f9efe2ac257c184a8a.tar.gz fml8-cd647117635bea41f05d63f9efe2ac257c184a8a.tar.bz2 fml8-cd647117635bea41f05d63f9efe2ac257c184a8a.zip | |
use Getopt::Long, define --params
Diffstat (limited to 'fml/libexec')
| -rw-r--r-- | fml/libexec/Standalone.pm | 25 | ||||
| -rwxr-xr-x | fml/libexec/fmlwrapper | 27 |
2 files changed, 34 insertions, 18 deletions
diff --git a/fml/libexec/Standalone.pm b/fml/libexec/Standalone.pm index efabc7bf..46dae660 100644 --- a/fml/libexec/Standalone.pm +++ b/fml/libexec/Standalone.pm @@ -20,13 +20,14 @@ use Carp; # value3 # XXX This file is non-Object Oriented style but # XXX this is minimum module used in standalone program. -# Arguments: $file -# Side Effects: none -# Return Value: reference to configuration hash +# Arguments: $file $params +# $params is 'key1=value1 key2=value2' syntax. +# Side Effects: $config (hash reference) is allocated on memory here. +# Return Value: hash reference to configuration parameters sub load_cf { - my ($file) = @_; - my $config = {}; + my ($file, $params) = @_; + my $config = $params ? _parse_params($params) : {}; use FileHandle; my $fh = new FileHandle $file; @@ -75,4 +76,18 @@ sub _expand_variables +sub _parse_params +{ + my ($params) = @_; + my %config = (); + + for my $x (split(/\s+/, $params)) { + my ($key, $value) = split(/=/, $x); + $config{ $key } = $value; + } + + \%config; +} + + 1; diff --git a/fml/libexec/fmlwrapper b/fml/libexec/fmlwrapper index a26080ac..82e23dff 100755 --- a/fml/libexec/fmlwrapper +++ b/fml/libexec/fmlwrapper @@ -11,6 +11,7 @@ use vars qw($MainCF); use strict; use Carp; +use Getopt::Long; # main configuration file for directory switch $MainCF = '/etc/fml/main.cf'; @@ -54,17 +55,12 @@ sub Bootstrap my @cf = (); my %options = (); my $my_default_config = ''; + GetOptions(\%options, + qw(ctladdr! debug! params! -c=s) + ); + for (@ARGV) { - if ($_ eq '--ctladdr') { - $options{ ctladdr } = 1; - } - elsif ($_ eq '-c') { - $options{ debug } = 1; - } - elsif ($_ eq '-c') { - $my_default_config = shift @ARGV; - } - elsif (-d $_) { + if (-d $_) { push(@cf, "$_/config.cf") if -f "$_/config.cf"; } elsif (-f $_) { @@ -73,7 +69,9 @@ sub Bootstrap } # 2.1 o.k. try to load main.cf - my $main_cf = Standalone::load_cf($MainCF); + my $main_cf = Standalone::load_cf($options{'c'} || $MainCF, + $options{'params'} + ); my $libexec_dir = $main_cf->{ libexec_dir }; my $default_config = $my_default_config || $main_cf->{ default_config }; unshift(@cf, $default_config); @@ -103,17 +101,20 @@ fmlwrapper -- the wrapper which executes a real fml5 program. =head1 SYNOPSIS -fmlwrapper C<[-c main.cf]> C<[-d]> C<[--ctladdr]> ml_home_dir +fmlwrapper C<[-c main.cf]> C<[--debug]> C<[--ctladdr]> ml_home_dir =head1 DESCRIPTION C<-c main.cf> main.cf alternative -C<-d> +C<--debug> debug on. C<--ctladdr> execute fml/libexec/command. +C<--params> + --params 'key1=value1 key2=value2 ...' + =cut |
