From: Jeff Hobbs Date: Wed, 23 Jan 2002 02:54:48 +0000 (+0000) Subject: (Expand*): fixed ExpandPathname to better handle spaced pathnames. X-Git-Tag: tkcon-2-4~34 X-Git-Url: https://privyetmir.co.uk/gitweb.cgi?a=commitdiff_plain;h=d2551a0250494d68289ffd47ba671d3be1864001;p=tkcon (Expand*): fixed ExpandPathname to better handle spaced pathnames. [Bug #497079] --- diff --git a/ChangeLog b/ChangeLog index 4b6f2ec..2fa5ed4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ * tkcon.tcl (dir): prevented possible 'divide by zero' error. [Bug #496584] + (Expand*): fixed ExpandPathname to better handle spaced pathnames. + [Bug #497079] 2001-12-14 Jeff Hobbs diff --git a/tkcon.tcl b/tkcon.tcl index 04bfdcb..ab3dff9 100755 --- a/tkcon.tcl +++ b/tkcon.tcl @@ -4653,13 +4653,13 @@ proc ::tkcon::Insert {w s} { # type - type of expansion (path / proc / variable) # Calls: ::tkcon::Expand(Pathname|Procname|Variable) # Outputs: The string to match is expanded to the longest possible match. -# If ::tkcon::OPT(showmultiple) is non-zero and the user longest match -# equaled the string to expand, then all possible matches are -# output to stdout. Triggers bell if no matches are found. +# If ::tkcon::OPT(showmultiple) is non-zero and the user longest +# match equaled the string to expand, then all possible matches +# are output to stdout. Triggers bell if no matches are found. # Returns: number of matches found ## proc ::tkcon::Expand {w {type ""}} { - set exp "\[^\\\\\]\[\[ \t\n\r\\\{\"\\\\\$\]" + set exp "\[^\\\\\]\[\[ \t\n\r\\\{\"$\]" set tmp [$w search -backwards -regexp $exp insert-1c limit-1c] if {[string compare {} $tmp]} {append tmp +2c} else {set tmp limit} if {[$w compare $tmp >= insert]} return @@ -4699,6 +4699,8 @@ proc ::tkcon::Expand {w {type ""}} { ## proc ::tkcon::ExpandPathname str { set pwd [EvalAttached pwd] + # Cause a string like {C:/Program\ Files/} to become "C:/Program Files/" + set str [subst $str] if {[catch {EvalAttached [list cd [file dirname $str]]} err]} { return -code error $err } @@ -4722,23 +4724,19 @@ proc ::tkcon::ExpandPathname str { } else { set tmp [ExpandBestMatch $m $dir] } - if {[string match ?*/* $str]} { - set tmp [file dirname $str]/$tmp - } elseif {[string match /* $str]} { - set tmp /$tmp + if {[string match */* $str]} { + set tmp [string trimright [file dirname $str] /]/$tmp } - regsub -all { } $tmp {\\ } tmp + regsub -all {([^\\]) } $tmp {\1\\ } tmp set match [linsert $m 0 $tmp] } else { ## This may look goofy, but it handles spaces in path names eval append match $m if {[file isdir $match]} {append match /} - if {[string match ?*/* $str]} { - set match [file dirname $str]/$match - } elseif {[string match /* $str]} { - set match /$match + if {[string match */* $str]} { + set match [string trimright [file dirname $str] /]/$match } - regsub -all { } $match {\\ } match + regsub -all {([^\\]) } $match {\1\\ } match ## Why is this one needed and the ones below aren't!! set match [list $match] } @@ -4765,10 +4763,10 @@ proc ::tkcon::ExpandProcname str { } } if {[llength $match] > 1} { - regsub -all { } [ExpandBestMatch $match $str] {\\ } str + regsub -all {([^\\]) } [ExpandBestMatch $match $str] {\1\\ } str set match [linsert $match 0 $str] } else { - regsub -all { } $match {\\ } match + regsub -all {([^\\]) } $match {\1\\ } match } return $match } @@ -4792,10 +4790,10 @@ proc ::tkcon::ExpandVariable str { } else { set match [EvalAttached [list info vars $str*]] if {[llength $match] > 1} { - regsub -all { } [ExpandBestMatch $match $str] {\\ } str + regsub -all {([^\\]) } [ExpandBestMatch $match $str] {\1\\ } str set match [linsert $match 0 $str] } else { - regsub -all { } $match {\\ } match + regsub -all {([^\\]) } $match {\1\\ } match } } return $match