# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # This module contains code that deals with processing URLs. This may # # grow with time ... # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # global V me PROT HOST DIR if ![info exists V] {set V 1} if ![info exists me] {set me ?} if ![info exists PROT] {set PROT {}} if ![info exists HOST] {set HOST {}} # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Given a "short" URL, this routine attempts to convert it to a full # # URL. We use the global URLt() array, which should always contain # # the full URL for the current window. We look at the various forms # # of short URL, and combine them with the global URL. This routine # # may not be quite complete yet, due to complexities in URL parsing. # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # proc url2URL u { global V me PROT HOST DIR URLt curD set id "$me/url2URL" set wdt $curD if {$V>2} {puts "$id: \"$u\""} if [regexp {^#(.*)$} $u {} mark] { if {$V>1} {puts "$id: \"$u\" is marked name within current URL."} set U $u } elseif [regexp {^([A-Za-z]+)://([-A-Za-z0-9_.:]*)/(.*)$} $u {} prot host rmdr] { if {$V>1} {puts "$id: \"$u\" is full URL"} set U $u } elseif [regexp {^([A-Za-z]+)://([-A-Za-z0-9_.:]*)$} $u {} prot host] { if {$V>1} {puts "$id: \"$u\" is URL without final /"} set U $u/ } elseif [regexp {^([A-Za-z]+):/([^/].*)$} $u {} prot rmdr] { if {$V>1} {puts "$id: \"$u\" is $prot:/ URL"} set U $prot://$HOST/$rmdr } elseif [regexp {^([A-Za-z]+):([^/].*)$} $u {} prot rmdr] { if {$V>1} {puts "$id: \"$u\" is $prot: URL"} switch $prot { mailto {set U $u} default {set U $prot://$HOST/$DIR$rmdr} } } elseif {$PROT == {}} { if {$V>1} {puts "$id: No remote-access protocol known; local URL."} if [regexp {^/} $u] { if {$V>1} {puts "$id: Return absolute local path \"$u\""} set U [Dir $u] } elseif {$DIR != {}} { if {$V>1} {puts "$id: Return relative local path $u"} set U [Dir "$u"] } else { if {$V>1} {puts "$id: Return u \"$u\" unchanged."} set U $u } } elseif [regexp {^/(.*)$} $u {} rmdr] { if {$V>1} {puts "$id: \"$u\" is full path."} if {$V>1} {puts "$id: \"$URLt($wdt)\" is global URLt($wdt)."} if [regexp {^([A-Za-z]+)://([-A-Za-z0-9_.:]*)/(.*)$} $URLt($wdt) {} prot host rmdr] { if {$V>1} {puts "$id: $prot://\"$host\"/\"$u\"."} set U $prot://[Dir $host$u] } else { if {$V>0} {puts "$id: URLt($wdt) \"$URLt($wdt)\" not in proper form."} if {$V>1} {puts "$id: URLt($wdt)=\"$URLt($wdt)\"/\"$u\"."} set U $URLt($wdt)/$u } } else { if {$V>1} {puts "$id: \"$u\" is relative to URLt($wdt)=\"$URLt($wdt)\""} if {$V>1} {puts "$id: PROT={$PROT} HOST={$HOST} DIR={$DIR}"} if [regexp {^(.*)/(.*)$} $URLt($wdt) {} init rmdr] { if {$V>1} {puts "$id: init=\"$init\"/\"$u\"."} set U $init/$u } else { if {$V>1} {puts "$id: URLt($wdt)=\"$URLt($wdt)\"/\"$u\"."} set U "$URLt($wdt)/$u" } } while {[regsub {/[^/]+/\.\./} $U {/} U]} { if {$V>1} {puts "$id: Reduced to \"$U\""} } return [nosp $U] }