[klibc] [PATCH] Add support for --param=name=value

KUMAAN 9maaan at gmail.com
Wed Aug 3 22:06:19 PDT 2011


Excuse me for interrupting.

(2011/08/04 3:32), maximilian attems wrote:
> not beeing a Perl wizzard, I still wonder why that should be 1,
> does perl follow c numbering, quick testing shows not:
> 
> cat /tmp/foo.pl 
> #!/usr/bin/perl
> use strict;
> my @values;
> my $string = "--param bla=bar";
> @values = split('=', $string); 
> if (@values == 2) {
> 	print "2: $values[1]\n";
> } elsif (@values == 1) {
> 	print "1: $values[1]\n";
> }
> 
> perl /tmp/foo.pl
> 2: bar

The $string contains white-space. If you pass it in shell command line,
"--param" is stored in $ARGV[N], and "bla=bar" is stored in $ARGV[N+1].

I wrote another Perl script.

$ cat foo1.pl
#!/usr/bin/perl
use strict;
my $a;
while ( defined($a = shift(@ARGV)) ) {
    #(($a = argv[n++]) =! NULL)

    if ( $a =~ /^--param/ ) {
	# ($a starts with "--param")

	# support --param name=value and --param=name=value
	my @values=split('=', $a);
	if ( @values == 1 ) {
	    # ( $a does not contain '=') 

	    #push(@ccopt, $a);
	    #store $a.
	    #$a starts with "--param".
	    print("--param    : ". $a ."\n");

	    #push(@ccopt, shift(@ARGV));
	    #store argv[n++] as "name=value" part.
	    print("name=value : ". shift(@ARGV) ."\n");

	} elsif ( @values == 3 ) {
	    # ( $a contains 2 '=' ) 

	    #push(@ccopt, $values[0]);
	    #store $values[0].
	    #$values[0] starts with "--param".
	    print("--param    : ". $values[0] ."\n");
	    
	    #push(@ccopt, join('=', $values[1],$values[2]));
	    #store "$values[1]=$values[2]" as "name=value".
	    print("name=value : ", join('=', $values[1],$values[2]) ."\n");

	    #Note:
	    #"value" can not contain '='.
	    #Because if it contain '=', @values != 3.
	} else {
	    print("Ignore     : $a\n");
	}
	print("\n");
    } else {
	print("ERROR:\n".
	      "options which don't start with '--param' are not supported.\n".
	      "\$a = $a\n");
	exit;
    }
}


$ perl foo1.pl --param nametA=valA --param=nameB=valB --param-foo=nameC=valC
--param    : --param
name=value : nametA=valA

--param    : --param
name=value : nameB=valB

--param    : --param-foo
name=value : nameC=valC


If "value" part of "--param=name=value" may contain '=',
this part of 'klcc/klcc.in' may have to like the following.

$ cat foo2.pl
#!/usr/bin/perl
use strict;
my $a;
while ( defined($a = shift(@ARGV)) ) {
    #(($a = argv[n++]) =! NULL)
    if ( $a =~ /^--param/ ) {
	# ($a starts with "--param")

	# support --param name=value and --param=name=value
	if( $a =~ /=/) {
	    # ( $a contains '=' ) 

	    my ($b,$c)=split('=', $a ,2);
	    #split by the first '=' of $a 

	    #push(@ccopt, $b);
	    #store $b.
	    #$b starts with "--param".
	    print("--param    : ". $b ."\n");
	    
	    #push(@ccopt, $c);
	    #store $c as "name=value" part.
	    print("name=value : ". $c ."\n");
	} else {
	    # ( $a does not contain '=')

	    #push(@ccopt, $a);	    
	    #store $a.
	    #$a starts with "--param".
	    print("--param    : ". $a ."\n");

	    #push(@ccopt, shift(@ARGV));
	    #store argv[n++] as "name=value" part.
	    print("name=value : ". shift(@ARGV) ."\n");
	}
	print("\n");
    } else {
	print("ERROR:\n".
	      "options which don't start with '--param' are not supported.\n".
	      "\$a = $a\n");
	exit;
    }
}

$ perl foo2.pl --param nametA=valA --param=nameB=valB --param=nameC=v=a=l=C
--param    : --param
name=value : nametA=valA

--param    : --param
name=value : nameB=valB

--param    : --param
name=value : nameC=v=a=l=C


thank you.

P.S. 
 About 'ipconfig' and DHCP lease-time value problem, I'm trying something.

--
KUMAAN
9maaan at gmail.com



More information about the klibc mailing list