sbsv1_os/e32toolp/genutil/listzip.pl
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 # Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 # All rights reserved.
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of "Eclipse Public License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Nokia Corporation - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description:
       
    14 # e32toolp/genutil/listzip.pl
       
    15 # Utility for listing the contents of a zip file.
       
    16 # Syntax:
       
    17 # perl listzip.pl <prefix> <zipfile>
       
    18 # This command will print all files in the <zipfile>. Each file name is prefixed by
       
    19 # <prefix> and is printed on a separate line.
       
    20 # 
       
    21 #
       
    22 
       
    23 sub _print_usage_and_die();
       
    24 sub _print_err_and_die(@);
       
    25 
       
    26 sub main(@)
       
    27 {
       
    28     my ($prefix, $zipf, @junk) = @_;
       
    29 
       
    30     _print_usage_and_die() if (!$prefix || !$zipf || @junk);
       
    31 
       
    32     _print_err_and_die("$prefix is not a directory.") unless -d $prefix;
       
    33     _print_err_and_die("$zipf doesn't exist.") unless -f $zipf;
       
    34 
       
    35     my @raw_data = qx/unzip -l $zipf/;
       
    36 
       
    37     for (@raw_data)
       
    38     {
       
    39         if ($_ =~ /^\s*\d+\s+\d\d[-|\/]\d\d[-|\/]\d\d\s+\d\d:\d\d\s+(.*)/)
       
    40         {
       
    41             my $line = "${prefix}/$1";
       
    42             $line =~ s/\//\\/g;
       
    43 	    # don't print directories under the <build> tags
       
    44 	    if (!($line =~ /\\$/)) {
       
    45 		    print "$line\n";
       
    46 		    }
       
    47         }
       
    48     }
       
    49 }
       
    50 
       
    51 sub _print_usage_and_die()
       
    52 {
       
    53     print "usage: listzip.pl <prefix> <zipfile>\n";
       
    54     exit 2;
       
    55 }
       
    56 
       
    57 sub _print_err_and_die(@)
       
    58 {
       
    59     print "listzip.pl: error: @_\n";
       
    60     exit 1;
       
    61 }
       
    62 
       
    63 main(@ARGV);
       
    64 
       
    65