3 ########################################################################
5 # /u/sonmi/bin/path_uniq
7 # this script makes components of a PATH like string unique cand prints
16 # -d delimiter - default :
17 # -s shortens the path
19 # usefull enhancements: in the usage part, try to guess what was meant as
20 # a path and echo it to stdout to not break for PATHs with blanks
22 ########################################################################
25 print STDERR
"usage $0 [-s] [-d <delimiter>] PATH\n";
26 print STDERR
" this script makes components of the PATH unique, if you\n";
27 print STDERR
" pass in a searchpath A:B:C:A:B:E it will print A:B:C:E to\n";
28 print STDERR
" the stdout\n\n";
29 print STDERR
" -s will mercylessly cut components from the path, \n";
30 print STDERR
" use at your own risk\n\n";
31 print STDERR
" the parameters you gave were: \n";
32 for ( $i = 0; $i <= $#ARGV; $i++ ) {
33 print STDERR
" $ARGV[$i]\n";
48 for ( $i=0; $i <= $#ARGV; $i++) {
49 if ( $ARGV[$i] eq '-d' ) {
50 $delimiter = $ARGV[++$i];
51 } elsif ( $ARGV[$i] eq '-s' ) {
54 $searchpath = $ARGV[$i];
57 if ( $searchpath eq "" ) {
60 #print STDERR "delimiter $delimiter\n";
61 #print STDERR "shorten $shorten\n";
62 #print STDERR "searchpath $searchpath\n";
64 @pathcomponents=split($delimiter, $searchpath);
66 for ( $i = 0; $i <= $#pathcomponents; $i++ ) {
68 if ( $shorten == 1 ) {
69 if ( "\/tools\/ns-arch\/sparc_sun_solaris2\.4\/lib\/sparcworks\/SUNWspro/bin" eq $pathcomponents[$i] ||
70 "\/h\/tortoise\/export\/share\/builds\/tools\/sparc_sun_solaris2\.5\.1\/perl5\.004\/bin" eq $pathcomponents[$i] ||
71 "\/usr\/dist\/local\/exe" eq $pathcomponents[$i] ||
72 "\/opt\/SUNWspro\/bin" eq $pathcomponents[$i] ||
73 "\/opt\/SUNWwabi\/bin" eq $pathcomponents[$i] ||
74 "\/u\/svbld\/bin" eq $pathcomponents[$i] ||
75 "\/usr\/demos" eq $pathcomponents[$i] ||
76 "\/usr\/audio\/bin" eq $pathcomponents[$i] ||
77 "\/usr\/openwin\/demo" eq $pathcomponents[$i] ||
78 "\/tools\/contrib\/bin" eq $pathcomponents[$i] ||
79 "\/usr\/etc\/" eq $pathcomponents[$i] ||
80 "\/usr\/demos\/bin" eq $pathcomponents[$i] ) {
83 #print "dumped: $pathcomponents[$i]\n";
86 #print "keep: $pathcomponents[$i]\n";
88 for ( $j = 0; $j < $i; $j++ ) {
89 if ( $pathcomponents[$j] eq $pathcomponents[$i] ) {
90 #print "$i and $j match - $pathcomponents[$i] - $pathcomponents[$j]\n";
96 #print "$pathcomponents[$i]:";
98 $newpath = $pathcomponents[$i];
100 $newpath=join($delimiter, $newpath,$pathcomponents[$i]);