security/nss/tests/path_uniq

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rwxr-xr-x

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 #! /bin/perl
michael@0 2
michael@0 3 ########################################################################
michael@0 4 #
michael@0 5 # /u/sonmi/bin/path_uniq
michael@0 6 #
michael@0 7 # this script makes components of a PATH like string unique cand prints
michael@0 8 # it to stdout
michael@0 9 #
michael@0 10 # parameters
michael@0 11 # ----------
michael@0 12 # PATH
michael@0 13 #
michael@0 14 # options
michael@0 15 # -------
michael@0 16 # -d delimiter - default :
michael@0 17 # -s shortens the path
michael@0 18 #
michael@0 19 # usefull enhancements: in the usage part, try to guess what was meant as
michael@0 20 # a path and echo it to stdout to not break for PATHs with blanks
michael@0 21 #
michael@0 22 ########################################################################
michael@0 23
michael@0 24 sub usage {
michael@0 25 print STDERR "usage $0 [-s] [-d <delimiter>] PATH\n";
michael@0 26 print STDERR " this script makes components of the PATH unique, if you\n";
michael@0 27 print STDERR " pass in a searchpath A:B:C:A:B:E it will print A:B:C:E to\n";
michael@0 28 print STDERR " the stdout\n\n";
michael@0 29 print STDERR " -s will mercylessly cut components from the path, \n";
michael@0 30 print STDERR " use at your own risk\n\n";
michael@0 31 print STDERR " the parameters you gave were: \n";
michael@0 32 for ( $i = 0; $i <= $#ARGV; $i++ ) {
michael@0 33 print STDERR " $ARGV[$i]\n";
michael@0 34 }
michael@0 35 exit ;
michael@0 36 }
michael@0 37
michael@0 38
michael@0 39 $i = 0;
michael@0 40 $j = 0;
michael@0 41 $delimiter = ":";
michael@0 42 $searchpath = "";
michael@0 43 @pathcomponents;
michael@0 44 $found=0;
michael@0 45 $newpath="";
michael@0 46 $shorten=0;
michael@0 47
michael@0 48 for ( $i=0; $i <= $#ARGV; $i++) {
michael@0 49 if ( $ARGV[$i] eq '-d' ) {
michael@0 50 $delimiter = $ARGV[++$i];
michael@0 51 } elsif ( $ARGV[$i] eq '-s' ) {
michael@0 52 $shorten=1;
michael@0 53 } else {
michael@0 54 $searchpath = $ARGV[$i];
michael@0 55 }
michael@0 56 }
michael@0 57 if ( $searchpath eq "" ) {
michael@0 58 usage;
michael@0 59 }
michael@0 60 #print STDERR "delimiter $delimiter\n";
michael@0 61 #print STDERR "shorten $shorten\n";
michael@0 62 #print STDERR "searchpath $searchpath\n";
michael@0 63
michael@0 64 @pathcomponents=split($delimiter, $searchpath);
michael@0 65
michael@0 66 for ( $i = 0; $i <= $#pathcomponents; $i++ ) {
michael@0 67 $found=0;
michael@0 68 if ( $shorten == 1 ) {
michael@0 69 if ( "\/tools\/ns-arch\/sparc_sun_solaris2\.4\/lib\/sparcworks\/SUNWspro/bin" eq $pathcomponents[$i] ||
michael@0 70 "\/h\/tortoise\/export\/share\/builds\/tools\/sparc_sun_solaris2\.5\.1\/perl5\.004\/bin" eq $pathcomponents[$i] ||
michael@0 71 "\/usr\/dist\/local\/exe" eq $pathcomponents[$i] ||
michael@0 72 "\/opt\/SUNWspro\/bin" eq $pathcomponents[$i] ||
michael@0 73 "\/opt\/SUNWwabi\/bin" eq $pathcomponents[$i] ||
michael@0 74 "\/u\/svbld\/bin" eq $pathcomponents[$i] ||
michael@0 75 "\/usr\/demos" eq $pathcomponents[$i] ||
michael@0 76 "\/usr\/audio\/bin" eq $pathcomponents[$i] ||
michael@0 77 "\/usr\/openwin\/demo" eq $pathcomponents[$i] ||
michael@0 78 "\/tools\/contrib\/bin" eq $pathcomponents[$i] ||
michael@0 79 "\/usr\/etc\/" eq $pathcomponents[$i] ||
michael@0 80 "\/usr\/demos\/bin" eq $pathcomponents[$i] ) {
michael@0 81
michael@0 82
michael@0 83 #print "dumped: $pathcomponents[$i]\n";
michael@0 84 next;
michael@0 85 }
michael@0 86 #print "keep: $pathcomponents[$i]\n";
michael@0 87 }
michael@0 88 for ( $j = 0; $j < $i; $j++ ) {
michael@0 89 if ( $pathcomponents[$j] eq $pathcomponents[$i] ) {
michael@0 90 #print "$i and $j match - $pathcomponents[$i] - $pathcomponents[$j]\n";
michael@0 91 $found=1;
michael@0 92 last;
michael@0 93 }
michael@0 94 }
michael@0 95 if ( $found == 0 ) {
michael@0 96 #print "$pathcomponents[$i]:";
michael@0 97 if ($i == 0) {
michael@0 98 $newpath = $pathcomponents[$i];
michael@0 99 } else {
michael@0 100 $newpath=join($delimiter, $newpath,$pathcomponents[$i]);
michael@0 101 }
michael@0 102 }
michael@0 103 }
michael@0 104 print "$newpath\n";
michael@0 105 exit;
michael@0 106
michael@0 107

mercurial