tcl expert needed

Bjarne D Mathiesen macintosh at mathiesen.info
Fri Jun 1 00:44:39 PDT 2012


Gustaf Neumann wrote:
> On 01.06.12 04:20, Bjarne D Mathiesen wrote:
>> Joshua Root wrote:
>>> On 2012-6-1 10:21 , Bjarne D Mathiesen wrote:
>>> The try command is not standard Tcl, it's defined in
>>> base/src/macports1.0/macports_util.tcl.
>> it's in the tcl we've got ... but a little different than the one
>> described on http://tmml.sourceforge.net/doc/tcl/try.html as there's no
>> /on error/
> 
> Be aware, that there are myn versions of "try" around and there
> is a "try" command in Tcl 8.6.
> 
> http://www.tcl.tk/man/tcl8.6/TclCmd/try.htm
> 
> The usual technique to handle multiple implementations of a command
> in tcl is to use multiple namespaces and "namespace path" or
> imports/exports
> into namespaces.

well, in this case it simply turned out that I luckily didn't need to
use /try/ /catch/ at all ;-)

the finished code is this :

+++ script start +++
#
# this proc recurses down through a file system and duplicates the
stucture in dest
# the dirs are created if they don't exist
# the files are having values from the apache dict substituted into them
#
# files are only installed if they don't already exist
#
# dirPath   :   the files are taken from here
# dest      :   where the files are to be installed
# skip      :   length of dirPath - needed because of recursion
# perm      :   permissions for the installed files
#
proc fileInstall { dirPath dest skip perm } {
    global apache
    foreach filePath [glob -nocomplain -directory ${dirPath} *] {
        if { [file isdirectory ${filePath}] } {
            xinstall -d -m 0755 "${dest}[string range ${filePath}
${skip} end]"
            fileInstall ${filePath} ${dest} ${skip} ${perm}
        }
        if {      [file isfile ${filePath}]
             && ! [file exists "${dest}[string range ${filePath} ${skip}
end]"]
           } then {
            set innput [open "${filePath}" r ]
            set output [open "${dest}[string range ${filePath} ${skip}
end]" w ${perm}]
            while { [gets ${innput} line] >= 0 } {
                puts ${output} [subst -novariables "${line}"]
            }
            close ${innput}
            close ${output}
        }
    }
}
+++ script end +++


-- 
Bjarne D Mathiesen
København N ; Danmark ; Europa
----------------------------------------------------------------------
denne besked er skrevet i et totalt M$-frit miljø
MacOS X 10.7.3 Lion ; 2.8GHz Intel Core i7 ; 16GB 1067MHz DDR3


More information about the macports-dev mailing list