~ubuntu-branches/ubuntu/saucy/mozjs17/saucy

« back to all changes in this revision

Viewing changes to js/src/build/unix/uniq.pl

  • Committer: Package Import Robot
  • Author(s): Rico Tzschichholz
  • Date: 2013-05-25 12:24:23 UTC
  • Revision ID: package-import@ubuntu.com-20130525122423-zmxucrhtensw90xy
Tags: upstream-17.0.0
ImportĀ upstreamĀ versionĀ 17.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env perl
 
2
 
 
3
# This Source Code Form is subject to the terms of the Mozilla Public
 
4
# License, v. 2.0. If a copy of the MPL was not distributed with this
 
5
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
6
 
 
7
##----------------------------##
 
8
##---] CORE/CPAN INCLUDES [---##
 
9
##----------------------------##
 
10
use strict;
 
11
use warnings;
 
12
use Getopt::Long;
 
13
 
 
14
##-------------------##
 
15
##---]  EXPORTS  [---##
 
16
##-------------------##
 
17
our $VERSION = qw(1.1);
 
18
 
 
19
##-------------------##
 
20
##---]  GLOBALS  [---##
 
21
##-------------------##
 
22
my %argv;
 
23
my $modver = $Getopt::Long::VERSION || 0;
 
24
my $isOldGetopt = ($modver eq '2.25') ? 1 : 0;
 
25
 
 
26
###########################################################################
 
27
## Intent: Script init function
 
28
###########################################################################
 
29
sub init
 
30
{
 
31
    if ($isOldGetopt)
 
32
    {
 
33
        # mozilla.build/mingw perl in need of an upgrade
 
34
        # emulate Getopt::Long switch|short:init
 
35
        foreach (qw(debug regex sort))
 
36
        {
 
37
            if (defined($argv{$_}))
 
38
            {
 
39
                $argv{$_} ||= 1;
 
40
            }
 
41
        }
 
42
    }
 
43
} # init
 
44
 
 
45
##----------------##
 
46
##---]  MAIN  [---##
 
47
##----------------##
 
48
my @args = ($isOldGetopt)
 
49
    ? qw(debug|d regex|r sort|s)
 
50
    : qw(debug|d:1 regex|r:1 sort|s:1)
 
51
    ;
 
52
 
 
53
unless(GetOptions(\%argv, @args))
 
54
{
 
55
    print "Usage: $0\n";
 
56
    print "  --sort   Sort list elements early\n";
 
57
    print "  --regex  Exclude subdirs by pattern\n";
 
58
}
 
59
 
 
60
init();
 
61
my $debug = $argv{debug} || 0;
 
62
 
 
63
my %seen;
 
64
my @out;
 
65
my @in = ($argv{sort}) ? sort @ARGV : @ARGV;
 
66
 
 
67
foreach my $d (@in)
 
68
{
 
69
    next if ($seen{$d}++);
 
70
 
 
71
    print "   arg is $d\n" if ($debug);
 
72
 
 
73
    if ($argv{regex})
 
74
    {
 
75
        my $found = 0;
 
76
        foreach my $dir (@out)
 
77
        {
 
78
            my $dirM = quotemeta($dir);
 
79
            $found++, last if ($d eq $dir || $d =~ m!^${dirM}\/!);
 
80
        }
 
81
        print "Adding $d\n" if ($debug && !$found);
 
82
        push @out, $d if (!$found);
 
83
    } else {
 
84
        print "Adding: $d\n" if ($debug);
 
85
        push(@out, $d);
 
86
    }
 
87
}
 
88
 
 
89
print "@out\n"
 
90
 
 
91
# EOF