1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/nss/tests/path_uniq Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,107 @@ 1.4 +#! /bin/perl 1.5 + 1.6 +######################################################################## 1.7 +# 1.8 +# /u/sonmi/bin/path_uniq 1.9 +# 1.10 +# this script makes components of a PATH like string unique cand prints 1.11 +# it to stdout 1.12 +# 1.13 +# parameters 1.14 +# ---------- 1.15 +# PATH 1.16 +# 1.17 +# options 1.18 +# ------- 1.19 +# -d delimiter - default : 1.20 +# -s shortens the path 1.21 +# 1.22 +# usefull enhancements: in the usage part, try to guess what was meant as 1.23 +# a path and echo it to stdout to not break for PATHs with blanks 1.24 +# 1.25 +######################################################################## 1.26 + 1.27 +sub usage { 1.28 + print STDERR "usage $0 [-s] [-d <delimiter>] PATH\n"; 1.29 + print STDERR " this script makes components of the PATH unique, if you\n"; 1.30 + print STDERR " pass in a searchpath A:B:C:A:B:E it will print A:B:C:E to\n"; 1.31 + print STDERR " the stdout\n\n"; 1.32 + print STDERR " -s will mercylessly cut components from the path, \n"; 1.33 + print STDERR " use at your own risk\n\n"; 1.34 + print STDERR " the parameters you gave were: \n"; 1.35 + for ( $i = 0; $i <= $#ARGV; $i++ ) { 1.36 + print STDERR " $ARGV[$i]\n"; 1.37 + } 1.38 + exit ; 1.39 +} 1.40 + 1.41 + 1.42 +$i = 0; 1.43 +$j = 0; 1.44 +$delimiter = ":"; 1.45 +$searchpath = ""; 1.46 +@pathcomponents; 1.47 +$found=0; 1.48 +$newpath=""; 1.49 +$shorten=0; 1.50 + 1.51 +for ( $i=0; $i <= $#ARGV; $i++) { 1.52 + if ( $ARGV[$i] eq '-d' ) { 1.53 + $delimiter = $ARGV[++$i]; 1.54 + } elsif ( $ARGV[$i] eq '-s' ) { 1.55 + $shorten=1; 1.56 + } else { 1.57 + $searchpath = $ARGV[$i]; 1.58 + } 1.59 +} 1.60 +if ( $searchpath eq "" ) { 1.61 + usage; 1.62 +} 1.63 +#print STDERR "delimiter $delimiter\n"; 1.64 +#print STDERR "shorten $shorten\n"; 1.65 +#print STDERR "searchpath $searchpath\n"; 1.66 + 1.67 +@pathcomponents=split($delimiter, $searchpath); 1.68 + 1.69 +for ( $i = 0; $i <= $#pathcomponents; $i++ ) { 1.70 + $found=0; 1.71 + if ( $shorten == 1 ) { 1.72 + if ( "\/tools\/ns-arch\/sparc_sun_solaris2\.4\/lib\/sparcworks\/SUNWspro/bin" eq $pathcomponents[$i] || 1.73 + "\/h\/tortoise\/export\/share\/builds\/tools\/sparc_sun_solaris2\.5\.1\/perl5\.004\/bin" eq $pathcomponents[$i] || 1.74 + "\/usr\/dist\/local\/exe" eq $pathcomponents[$i] || 1.75 + "\/opt\/SUNWspro\/bin" eq $pathcomponents[$i] || 1.76 + "\/opt\/SUNWwabi\/bin" eq $pathcomponents[$i] || 1.77 + "\/u\/svbld\/bin" eq $pathcomponents[$i] || 1.78 + "\/usr\/demos" eq $pathcomponents[$i] || 1.79 + "\/usr\/audio\/bin" eq $pathcomponents[$i] || 1.80 + "\/usr\/openwin\/demo" eq $pathcomponents[$i] || 1.81 + "\/tools\/contrib\/bin" eq $pathcomponents[$i] || 1.82 + "\/usr\/etc\/" eq $pathcomponents[$i] || 1.83 + "\/usr\/demos\/bin" eq $pathcomponents[$i] ) { 1.84 + 1.85 + 1.86 + #print "dumped: $pathcomponents[$i]\n"; 1.87 + next; 1.88 + } 1.89 + #print "keep: $pathcomponents[$i]\n"; 1.90 + } 1.91 + for ( $j = 0; $j < $i; $j++ ) { 1.92 + if ( $pathcomponents[$j] eq $pathcomponents[$i] ) { 1.93 + #print "$i and $j match - $pathcomponents[$i] - $pathcomponents[$j]\n"; 1.94 + $found=1; 1.95 + last; 1.96 + } 1.97 + } 1.98 + if ( $found == 0 ) { 1.99 + #print "$pathcomponents[$i]:"; 1.100 + if ($i == 0) { 1.101 + $newpath = $pathcomponents[$i]; 1.102 + } else { 1.103 + $newpath=join($delimiter, $newpath,$pathcomponents[$i]); 1.104 + } 1.105 + } 1.106 +} 1.107 +print "$newpath\n"; 1.108 +exit; 1.109 + 1.110 +