##
## NOTE: The purpose of this procedure is to take the base URL of the
## Fossil project and return the root of the entire web site using
## the same URI scheme as the base URL (e.g. http or https).
##
proc getLogoUrl { baseurl } {
set idx(first) [string first // $baseurl]
if {$idx(first) != -1} {
##
## NOTE: Skip second slash.
##
set idx(first+1) [expr {$idx(first) + 2}]
##
## NOTE: (part 1) The [string first] command does NOT actually
## support the optional startIndex argument as specified
## in the TH1 support manual; therefore, we fake it by
## using the [string range] command and then adding the
## necessary offset to the resulting index manually
## (below). In Tcl, we could use the following instead:
##
## set idx(next) [string first / $baseurl $idx(first+1)]
##
set idx(nextRange) [string range $baseurl $idx(first+1) end]
set idx(next) [string first / $idx(nextRange)]
if {$idx(next) != -1} {
##
## NOTE: (part 2) Add the necessary offset to the result of
## the search for the next slash (i.e. the one after
## the initial search for the two slashes).
##
set idx(next) [expr {$idx(next) + $idx(first+1)}]
##
## NOTE: Back up one character from the next slash.
##
set idx(next-1) [expr {$idx(next) - 1}]
##
## NOTE: Extract the URI scheme and host from the base URL.
##
set scheme [string range $baseurl 0 $idx(first)]
set host [string range $baseurl $idx(first+1) $idx(next-1)]
##
## NOTE: Try to stay in SSL mode if we are there now.
##
if {[string compare $scheme http:/] == 0} {
set scheme http://
} else {
set scheme https://
}
set logourl $scheme$host/
} else {
set logourl $baseurl
}
} else {
set logourl $baseurl
}
return $logourl
}
set logourl [getLogoUrl $baseurl]
$
if {[info exists login]} {
puts "Logged in as $login"
} else {
puts "Not logged in"
}