commsinfrastructureapitest/commsinfrastructuresvs/suite/group/InsertIpAddr.pl
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 #
       
     2 # Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description:
       
    15 #
       
    16 
       
    17 use Getopt::Long;
       
    18 
       
    19 sub Usage()
       
    20 	{
       
    21 	print <<USAGE_EOF;
       
    22 Usage
       
    23 perl InsertIpAddr.pl --in=FileNameIn --out=FileNameOut [--connection=Connection] --tag=Tag --help
       
    24 
       
    25     --in=FileNameIn             : Input file name
       
    26 
       
    27     --out=FileNameOut           : Output file name
       
    28 
       
    29     --connection=Connection     : Name of connection to get IP address of
       
    30                                   defaults to "Local Area Connection"
       
    31 
       
    32     --tag=Tag                   : Tag in input file to replace with the IP address
       
    33 
       
    34     --help                      : This help
       
    35 USAGE_EOF
       
    36 	exit( 0 )
       
    37 	}
       
    38 
       
    39 sub trim($)
       
    40 {
       
    41     my $string = shift;
       
    42     $string =~ s/^\s+//;
       
    43     $string =~ s/\s+$//;
       
    44     return $string;
       
    45 }
       
    46 
       
    47 sub main($$$$)
       
    48 {
       
    49 	my	($fileNameIn, $fileNameOut, $connectionName, $tagName) = @_;
       
    50 
       
    51 	my	$help='';
       
    52 	my	$input="";
       
    53 	my	$output="";
       
    54 	my	$connection="Local Area Connection";
       
    55 	my	$tag="";
       
    56 
       
    57 	GetOptions(
       
    58 		'in=s'			=> \$input,
       
    59 		'out=s'			=> \$output,
       
    60 		'connection=s'	=> \$connection,
       
    61 		'tag=s'			=> \$tag,
       
    62 		'help' 			=> \$help
       
    63 	);
       
    64 
       
    65 	if($help or ($input eq "") or ($output eq "") or ($connection eq "") or ($tag eq ""))
       
    66 		{
       
    67 		Usage();
       
    68 		exit(0);
       
    69 		}
       
    70 
       
    71 	my	$ipAddr=trim(`perl -S getipaddr.pl -connection=\"$connection\"`);
       
    72 	print $ipAddr, "\n";
       
    73 	if ($ipAddr == "")
       
    74 	{
       
    75 		print "ERROR: No IP Address\n";
       
    76 		exit(-1);
       
    77 	}
       
    78 
       
    79 	my	@newLines = ();
       
    80 	open(FIN, $input);
       
    81 	open(FOUT, ">$output");
       
    82 
       
    83 	foreach (<FIN>)
       
    84 	{
       
    85 		if (/$tag/)
       
    86 		{
       
    87 			s/$tag/$ipAddr/;
       
    88 		}
       
    89 		print FOUT $_;
       
    90 	}
       
    91 	close(FIN);
       
    92 	close(FOUT);
       
    93 }
       
    94 
       
    95 main($ARGV[0], $ARGV[1], $ARGV[2], $ARGV[3]);