build/unix/uniq.pl

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/build/unix/uniq.pl	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,91 @@
     1.4 +#!/usr/bin/env perl
     1.5 +
     1.6 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.7 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.9 +
    1.10 +##----------------------------##
    1.11 +##---] CORE/CPAN INCLUDES [---##
    1.12 +##----------------------------##
    1.13 +use strict;
    1.14 +use warnings;
    1.15 +use Getopt::Long;
    1.16 +
    1.17 +##-------------------##
    1.18 +##---]  EXPORTS  [---##
    1.19 +##-------------------##
    1.20 +our $VERSION = qw(1.1);
    1.21 +
    1.22 +##-------------------##
    1.23 +##---]  GLOBALS  [---##
    1.24 +##-------------------##
    1.25 +my %argv;
    1.26 +my $modver = $Getopt::Long::VERSION || 0;
    1.27 +my $isOldGetopt = ($modver eq '2.25') ? 1 : 0;
    1.28 +
    1.29 +###########################################################################
    1.30 +## Intent: Script init function
    1.31 +###########################################################################
    1.32 +sub init
    1.33 +{
    1.34 +    if ($isOldGetopt)
    1.35 +    {
    1.36 +	# mozilla.build/mingw perl in need of an upgrade
    1.37 +	# emulate Getopt::Long switch|short:init
    1.38 +	foreach (qw(debug regex sort))
    1.39 +	{
    1.40 +	    if (defined($argv{$_}))
    1.41 +	    {
    1.42 +		$argv{$_} ||= 1;
    1.43 +	    }
    1.44 +	}
    1.45 +    }
    1.46 +} # init
    1.47 +
    1.48 +##----------------##
    1.49 +##---]  MAIN  [---##
    1.50 +##----------------##
    1.51 +my @args = ($isOldGetopt)
    1.52 +    ? qw(debug|d regex|r sort|s)
    1.53 +    : qw(debug|d:1 regex|r:1 sort|s:1)
    1.54 +    ;
    1.55 +
    1.56 +unless(GetOptions(\%argv, @args))
    1.57 +{
    1.58 +    print "Usage: $0\n";
    1.59 +    print "  --sort   Sort list elements early\n";
    1.60 +    print "  --regex  Exclude subdirs by pattern\n";
    1.61 +}
    1.62 +
    1.63 +init();
    1.64 +my $debug = $argv{debug} || 0;
    1.65 +
    1.66 +my %seen;
    1.67 +my @out;
    1.68 +my @in = ($argv{sort}) ? sort @ARGV : @ARGV;
    1.69 +
    1.70 +foreach my $d (@in)
    1.71 +{
    1.72 +    next if ($seen{$d}++);
    1.73 +
    1.74 +    print "   arg is $d\n" if ($debug);
    1.75 +
    1.76 +    if ($argv{regex})
    1.77 +    {
    1.78 +        my $found = 0;
    1.79 +        foreach my $dir (@out)
    1.80 +	{
    1.81 +	    my $dirM = quotemeta($dir);
    1.82 +            $found++, last if ($d eq $dir || $d =~ m!^${dirM}\/!);
    1.83 +        }
    1.84 +	print "Adding $d\n" if ($debug && !$found);
    1.85 +        push @out, $d if (!$found);
    1.86 +    } else {
    1.87 +	print "Adding: $d\n" if ($debug);
    1.88 +        push(@out, $d);
    1.89 +    }
    1.90 +}
    1.91 +
    1.92 +print "@out\n"
    1.93 +
    1.94 +# EOF

mercurial