#
# <20180717.1631.52>
#
# The replaceMsEnv command takes a string and returns a string with
# %env-var% instances replaced with the current value of the given
# environment variable.
#
proc replaceMsEnv {str} {
  global env
  set result {}
  while {[regexp {([^%]*)%([^%]+)%(.*)} $str m pre it post]} {
    append result $pre
    # The issue is that windows envs are not case sensitive, so....
    if {[info exists env($it)]} {
      append result $env($it)
    } else {
      append result "%$it%"
    }
    set str $post
  }
  return [append result $str]
}
