1 #----- search for specified file
3 proc findfile
:check
{type fname
} {
5 if {$type == "executable" && $tcl_platform(platform
) == "windows"} {
6 foreach ext
{.com .exe .bat
} {
7 if [file exists
$fname$ext] {
12 if [file $type $fname] {
13 if {$type == "executable" && [file isdirectory
$fname]} {
21 proc findfile
:path
{str delim
} {
24 foreach p
[split $str $delim] {
26 foreach d
[split $p /] {
27 if {[string length
$d] > 1 && [string index
$d 0] == {$}} {
28 if [info exists env
([string range
$d 1 end
])] {
29 lappend dir
$env([string range
$d 1 end
])
39 lappend path
[join $dir /]
43 return [join $path $delim]
48 proc find_file
{type fname args
} {
49 global tcl_platform env
54 set dr
[file dirname
$fname]
55 set fn
[file tail
$fname]
65 set filename [pwd]/$fn
67 return [findfile
:check
$type $filename]
70 # check if running under windows
72 if {[info exists tcl_platform
(platform
)] &&
73 $tcl_platform(platform
) == "windows"} {
81 # check current directory
83 set filename [findfile
:check
$type [pwd]/$fn]
84 if {$filename != ""} {
91 # check PATH environment variable
93 if [info exists env
(PATH
)] {
94 foreach dir
[split $env(PATH
) $delim] {
95 set filename [findfile
:check
$type $dir/$fn]
96 if {$filename != ""} {
104 # check supplied list of paths/directories
107 foreach ent
[split $val] {
109 set path
[findfile
:path
$ent $delim]
111 foreach dir
[split $path $delim] {
112 set filename [findfile
:check
$type $dir/$fn]
113 if {$filename != ""} {