# <20220201.1341.04>
#
# This routine examins the env PATH variable and reports any masking found
# Masking is when the same program appears in more than one path element.
#
#
proc checkForPathMasking {} {
  global resultAr
  array unset resultAr
  if {$::MSW} {
    set path [split [expandEnvRefs $::env(PATH)]]
  } else {
    set path [split $::env(PATH) ":"]
  }
  set progs {}
  set dirs  {}
  foreach dir $path {
    set dir [file dir [file norm $dir/x]]
    if {$dir in $dirs} {continue}
    lappend dirs $dir
    foreach file [glob -directory $dir -nocomplain -tails -types {x} -- *] {
      if {[info exists resultAr($file)]} {
	if {$dir ni $resultAr($file) && \
		[file dir [file norm $resultAr($file)/$file/X]] != \
		[file dir [file norm $dir/$file/X]]} {
	  lappend resultAr($file) $dir
	}
      } else {
	set resultAr($file) $dir
	lappend progs $file
      }
    }
  }

  # now we sort the programs
  set progs [lsort $progs]
  puts "Path is: $::env(PATH)\n"
  puts "[llength $progs] found\n"

  foreach prog $progs {
    if {[llength $resultAr($prog)] > 1 } {
      set masked [lassign $resultAr($prog) firstEnt]
      puts "Program $prog in $firstEnt is masking $prog in $masked"
      puts "([file dir [file norm $firstEnt/$prog/X]] vs:"
      foreach dir $masked {
	puts "   [file dir [file norm $dir/$prog/X]]"
      }
      puts ")\n"
      incr co
    }
  }
  if {![info exists co]} {
    puts "No masking found"
  }
}

  
	  
    
