# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # This module contains code that deals with processing URLs. This may # # grow with time ... # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # global D me PROT HOST DIR URL if ![info exists D] {set D 1} if ![info exists me] {set me ?} if ![info exists PROT] {set PROT {}} if ![info exists HOST] {set HOST {}} if ![info exists URL] {set URL {}} # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Given a "short" URL, this routine attempts to convert it to a full # # URL. We use the global URL variable, which should always contain # # the full URL for the current page. 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 D me PROT HOST DIR URL set id "$me/url2URL" if {$D>1} {puts "$id: \"$u\""} if [regexp {^#(.*)$} $u {} mark] { if {$D>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 {$D>1} {puts "$id: \"$u\" is full URL, returning it."} set U $u } elseif [regexp {^([A-Za-z]+)://([-A-Za-z0-9_.:]*)$} $u {} prot host] { if {$D>1} {puts "$id: \"$u\" is URL without final /, fix it up."} set U $u/ } elseif {$PROT == {}} { if {$D>1} {puts "$id: No remote-access protocol known; local URL."} if [regexp {^/} $u] { if {$D>1} {puts "$id: Return absolute local path \"$u\""} set U [Dir $u] } elseif {$DIR != {}} { if {$D>1} {puts "$id: Return relative local path $DIR/$u"} set U [Dir "$DIR/$u"] } else { if {$D>1} {puts "$id: Return u \"$u\" unchanged."} set U $u } } elseif [regexp {^/(.*)$} $u {} rmdr] { if {$D>1} {puts "$id: \"$u\" is full path."} if {$D>1} {puts "$id: \"$URL\" is global URL."} if [regexp {^([A-Za-z]+)://([-A-Za-z0-9_.:]*)/(.*)$} $URL {} prot host rmdr] { if {$D>1} {puts "$id: $prot://\"$host\"/\"$u\"."} set U $prot://[Dir $host$u] } else { if {$D>0} {puts "$id: URL \"$URL\" not in proper form."} if {$D>1} {puts "$id: URL=\"$URL\"/\"$u\"."} set U $URL/$u } } else { if {$D>1} {puts "$id: \"$u\" is relative to URL=\"$URL\""} if {$D>1} {puts "$id: PROT={$PROT} HOST={$HOST} DIR={$DIR}"} if [regexp {^(.*)/(.*)$} $URL {} init rmdr] { if {$D>1} {puts "$id: init=\"$init\"/\"$u\"."} set U $init/$u } else { if {$D>1} {puts "$id: URL=\"$URL\"/\"$u\"."} set U "$URL/$u" } } while [regsub {/([^/])/[^/]/\.\./} $U {/\1/} U] { if {$D>1} {puts "$id: Reduced to \"$U\""} } return $U }