1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#!/usr/local/bin/tclsh
# -*- tcl -*-
# this one needs no path.
# fixes the '#!... path' for the given script
#argv = {tclsh_path wish_path appscript}
foreach {tclsh_path wish_path appscript} $argv {break;}
set fail [catch {set fin [open $appscript r]}]
if {$fail} {
# appscript does not exist
exit 1
}
if {[gets $fin ipPath] < 0} {
# appscript is empty
exit 2
}
if {![regexp {^#!} $ipPath]} {
# appscript is no application
close $fin
exit 3
}
if {[regexp {wish} $ipPath]} {
# wish application
if {{} == $wish_path} {
# wish was not found
exit 5
}
set fout [open $appscript.[pid] w]
puts $fout "#!$wish_path"
fcopy $fin $fout
close $fin
close $fout
file rename -force $appscript.[pid] $appscript
exit 0
}
if {[regexp {tclsh} $ipPath]} {
# tclsh application
if {{} == $wish_path} {
# tclsh was not found
exit 6
}
set fout [open $appscript.[pid] w]
puts $fout "#!$tclsh_path"
fcopy $fin $fout
close $fin
close $fout
file rename -force $appscript.[pid] $appscript
exit 0
}
# appscript is no tclsh/wish application
exit 4
|