path normalisation in "base"

René J.V. Bertin rjvbertin at gmail.com
Tue Oct 11 07:38:34 PDT 2016


On Tuesday October 11 2016 16:04:21 René J.V. Bertin wrote:

>{{{
>proc macports::normalize { filename } {
>    set nprefix [file dirname [file normalize "${macports::prefix}/foo"]]
>    return [string map {${nprefix} ${macports::prefix}} [file normalize $filename]]
>}
>}}}

For some reason [string map] doesn't work when I use the above variables; it did when using the strings relevant for my system??

This does work though:

{{{
proc macports::normalize { filename } {
    # normalise the user-specified prefix. The test file under $prefix need not exist for that:
    set nprefix [file dirname [file normalize "${macports::prefix}/foo"]]
    set file [file normalize $filename]
    # check if the result starts with the "normalised" prefix:
    if {$nprefix ne $macports::prefix && [string first $nprefix $file] eq 0} {
        # obtain the part after the normalised prefix, and prepend the user-specific prefix to it:
        set file [file join $macports::prefix [string range $file [string length $nprefix]+1 end]]
    }
    return $file
}
}}}

R.


More information about the macports-dev mailing list