Hello!

When creating a project with multiple files, the problem rises, that
if you want to copy it (install it) do another place you have to
install the whole set of files in the same directory where you created
it, so vtcl-startup routines can find the widget files.  Same goes for
files you include by yourself.

I just elaborated a solution to the problem, which even makes it
posible to install a vtcl made program in one directory and start it
from a symbolic link to the executable.

It's easy and small, and I hope it will make it into the distribution.

Two steps needed:

1- The attached file: info_script.tcl contains two (three) helper
   proc's, chase and info_script.

   These procs have to be included into vtcl startup code (of the
   application).

2- Each occurence of "info script" (used to load the widget files) has
   to be replaced by "info_script"

Notes:

- This is only valid if you do not user this freewrap thing (don't
  know anything about it), because freewrap loads with an absolut
  path.  I suppose that freewrap could also benefit from
  "info_script", but you have to figure out yourself.

- It could be wise to call info_script once at startup and put the
  result (the *real* path to the executing script) in a Vtcl::
  Variable, which can then be reused as many times you like by vtcl
  internal routines *and* by user scripts.  Simpler syntax and faster
  execution.

- Don't know, if "chase" breaks on Guindo's (MS Windows).  It uses
  "file lstat" to check if a path is a symbolic link.  Does this work
  on that platform? and on Mac??  I suppose it should, if not this
  would be a flaw in Tcl, as symlinks don't exist on Windows, so Tcl
  should never report any, but of course report the file type.


Questions to vtcl gurus:

- Why did the code of "source"ed routines in my project suddenly show
  up inside the vtcl program?  It's a bug or a feature?

- Is it possible to redistribute functions into different source
  files?  If not, can it be made possible?

- Is it possible to use another editor to edit the procedures?  If
  not, can this too made possible?

- Is there anybody working on documentation?  What status does it
  have?  Is there some referenc document? (beside the outdated docs)?

Thank you for the fine product,

Best Regards,

     Jorge-Le�n
#
# This file provides two utilities:
#
# info_script: returns the absolute filename of the currently
#              interpreted script.
# chase filename: chases a given path "filename" and follows any
#              symlinks until getting a real file/directory or
#              whatever, or until 8 levels of symlinks are reached,
#              when it aborts with an error message.
#              The nesting level can be changed at the location
#              "{$count ==" below
#

proc {chasehelper} {filename count} {
    file lstat $filename filestat
    if {$filestat(type) == "link"} {
	if {$count == 8} { error "Too many symbolic links" }
	# Recurse into next link-level
	chasehelper [file readlink $filename] [incr count]
    } else {
	return $filename
    }
}

proc {chase} {filename} {return [chasehelper $filename 0]}

proc {info_script} {} {
    
    set scriptinfo [info script]
    if {[string index $scriptinfo 0] == "!"} then {
	set scriptdir $scriptinfo
    } else {
	# For cosmetics we remove ./ in front of the filename
	set scriptpath [file split $scriptinfo]
	if {[lindex $scriptpath 0] == "."} {
	    set scriptpath [lrange $scriptpath 1 [llength $scriptpath]]
	}
        set filename [eval file join [pwd] $scriptpath]
	
	set scriptdir [chase $filename]
    }
    return $scriptdir
}

Reply via email to