michael@0: #!/usr/bin/env perl michael@0: michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: ##----------------------------## michael@0: ##---] CORE/CPAN INCLUDES [---## michael@0: ##----------------------------## michael@0: use strict; michael@0: use warnings; michael@0: use Getopt::Long; michael@0: michael@0: ##-------------------## michael@0: ##---] EXPORTS [---## michael@0: ##-------------------## michael@0: our $VERSION = qw(1.1); michael@0: michael@0: ##-------------------## michael@0: ##---] GLOBALS [---## michael@0: ##-------------------## michael@0: my %argv; michael@0: my $modver = $Getopt::Long::VERSION || 0; michael@0: my $isOldGetopt = ($modver eq '2.25') ? 1 : 0; michael@0: michael@0: ########################################################################### michael@0: ## Intent: Script init function michael@0: ########################################################################### michael@0: sub init michael@0: { michael@0: if ($isOldGetopt) michael@0: { michael@0: # mozilla.build/mingw perl in need of an upgrade michael@0: # emulate Getopt::Long switch|short:init michael@0: foreach (qw(debug regex sort)) michael@0: { michael@0: if (defined($argv{$_})) michael@0: { michael@0: $argv{$_} ||= 1; michael@0: } michael@0: } michael@0: } michael@0: } # init michael@0: michael@0: ##----------------## michael@0: ##---] MAIN [---## michael@0: ##----------------## michael@0: my @args = ($isOldGetopt) michael@0: ? qw(debug|d regex|r sort|s) michael@0: : qw(debug|d:1 regex|r:1 sort|s:1) michael@0: ; michael@0: michael@0: unless(GetOptions(\%argv, @args)) michael@0: { michael@0: print "Usage: $0\n"; michael@0: print " --sort Sort list elements early\n"; michael@0: print " --regex Exclude subdirs by pattern\n"; michael@0: } michael@0: michael@0: init(); michael@0: my $debug = $argv{debug} || 0; michael@0: michael@0: my %seen; michael@0: my @out; michael@0: my @in = ($argv{sort}) ? sort @ARGV : @ARGV; michael@0: michael@0: foreach my $d (@in) michael@0: { michael@0: next if ($seen{$d}++); michael@0: michael@0: print " arg is $d\n" if ($debug); michael@0: michael@0: if ($argv{regex}) michael@0: { michael@0: my $found = 0; michael@0: foreach my $dir (@out) michael@0: { michael@0: my $dirM = quotemeta($dir); michael@0: $found++, last if ($d eq $dir || $d =~ m!^${dirM}\/!); michael@0: } michael@0: print "Adding $d\n" if ($debug && !$found); michael@0: push @out, $d if (!$found); michael@0: } else { michael@0: print "Adding: $d\n" if ($debug); michael@0: push(@out, $d); michael@0: } michael@0: } michael@0: michael@0: print "@out\n" michael@0: michael@0: # EOF