Bug 790132 - Add a test to make sure media sniffing occurs only when we want. r=bz
[gecko.git] / build / unix / uniq.pl
blob301240e0310aaa93548d3825d4fba550bf20cc6a
1 #!/usr/bin/env perl
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/.
7 ##----------------------------##
8 ##---] CORE/CPAN INCLUDES [---##
9 ##----------------------------##
10 use strict;
11 use warnings;
12 use Getopt::Long;
14 ##-------------------##
15 ##---] EXPORTS [---##
16 ##-------------------##
17 our $VERSION = qw(1.1);
19 ##-------------------##
20 ##---] GLOBALS [---##
21 ##-------------------##
22 my %argv;
23 my $modver = $Getopt::Long::VERSION || 0;
24 my $isOldGetopt = ($modver eq '2.25') ? 1 : 0;
26 ###########################################################################
27 ## Intent: Script init function
28 ###########################################################################
29 sub init
31 if ($isOldGetopt)
33 # mozilla.build/mingw perl in need of an upgrade
34 # emulate Getopt::Long switch|short:init
35 foreach (qw(debug regex sort))
37 if (defined($argv{$_}))
39 $argv{$_} ||= 1;
43 } # init
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)
53 unless(GetOptions(\%argv, @args))
55 print "Usage: $0\n";
56 print " --sort Sort list elements early\n";
57 print " --regex Exclude subdirs by pattern\n";
60 init();
61 my $debug = $argv{debug} || 0;
63 my %seen;
64 my @out;
65 my @in = ($argv{sort}) ? sort @ARGV : @ARGV;
67 foreach my $d (@in)
69 next if ($seen{$d}++);
71 print " arg is $d\n" if ($debug);
73 if ($argv{regex})
75 my $found = 0;
76 foreach my $dir (@out)
78 my $dirM = quotemeta($dir);
79 $found++, last if ($d eq $dir || $d =~ m!^${dirM}\/!);
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);
89 print "@out\n"
91 # EOF