modern Tcl and correct quoting

Poor Yorick org.macosforge.lists.macports-dev at pooryorick.com
Tue Jun 11 23:05:22 PDT 2013


Hi,

macport.tcl appears to have originally been written prior to Tcl 8.5, which was
released in 2007, and uses idioms that are now considered obsolete.  There are
also instances where curly brackets are used in combination with variable
interpolation to attempt to create a well-formed list value, but this is not
robust.

The attached diff contains various changes, some of which, admittedly, are a
question of style, but many others have a real impact on correctness and
performance.  Changes which are not fluff include:

	eliminate redundant calls to [expr] in [if] tests.

	use "eq" instead of "==" where appropriate

	brace arguments to [expr]

	replace [eval] with {*} expansion where appropriate

	use [list] to correctly quote arguments to [eval]

	use [string map] to correcty interpolate variable arguments into
	dynamically-generated scripts.

Changes which are somewhat fluff:

	remove quotes around single variables

Changes which are fluff:

	replace "" with {}

	remove quotes around values when they are not needed

	remove extra spaces between things like parenthesis and curly brackets and their contents

	replace double quotes with curly brackets where appropriate


So far, I haven't succesfully set up a macports development environment where I
could test the changes in this diff, but I did use a static syntax analyzer to
catch as many typos as possible.

I hope the macports team will see fit to modernize its Tcl code.  If these
changes are accepted, I would be happy to make the same effort with other .tcl
files in the project.

A couple of other issues I'm interested in working on:

	The implementation of [system] curently passes its commands through a
	shell, but this makes it necessary to add an extra layer of shell quoting
	to the arguments to [system].  Macports currently includes no [shquote]
	command, so extra layer of quoting has been manually hard-coded into the
	values that are passed, which is not correct and only works if one steers
	clear of the edge cases.  [system] could be implemented so that it bypasses
	the shell, which would be more simple and robust.

	macports_util.tcl implements [try], which, as of Tcl 8.6, is included as a
	built-in command.  In my development environment, this leads to an error
	when [package require] is invoked.  I propose to rename the macports [try]
	so that it can coexist with the builtin.


-- 
Poor Yorick
-------------- next part --------------
--- macports.tcl	2013-06-11 11:14:01.000000000 -0400
+++ macports.tcl.new	2013-06-11 19:48:23.000000000 -0400
@@ -39,41 +39,41 @@
 package require macports_util 1.0
 
 namespace eval macports {
-    namespace export bootstrap_options user_options portinterp_options open_mports ui_priorities port_phases 
-    variable bootstrap_options "\
-        portdbpath libpath binpath auto_path extra_env sources_conf prefix portdbformat \
-        portarchivetype portautoclean \
-        porttrace portverbose keeplogs destroot_umask variants_conf rsync_server rsync_options \
-        rsync_dir startupitem_type startupitem_install place_worksymlink xcodeversion xcodebuildcmd \
-        configureccache ccache_dir ccache_size configuredistcc configurepipe buildnicevalue buildmakejobs \
-        applications_dir frameworks_dir developer_dir universal_archs build_arch macosx_deployment_target \
-        macportsuser proxy_override_env proxy_http proxy_https proxy_ftp proxy_rsync proxy_skip \
-        master_site_local patch_site_local archive_site_local buildfromsource \
-        revupgrade_autorun revupgrade_mode revupgrade_check_id_loadcmds \
-        host_blacklist preferred_hosts sandbox_enable \
+    namespace export bootstrap_options user_options portinterp_options open_mports ui_priorities port_phases
+    variable bootstrap_options "
+        portdbpath libpath binpath auto_path extra_env sources_conf prefix portdbformat
+        portarchivetype portautoclean
+        porttrace portverbose keeplogs destroot_umask variants_conf rsync_server rsync_options
+        rsync_dir startupitem_type startupitem_install place_worksymlink xcodeversion xcodebuildcmd
+        configureccache ccache_dir ccache_size configuredistcc configurepipe buildnicevalue buildmakejobs
+        applications_dir frameworks_dir developer_dir universal_archs build_arch macosx_deployment_target
+        macportsuser proxy_override_env proxy_http proxy_https proxy_ftp proxy_rsync proxy_skip
+        master_site_local patch_site_local archive_site_local buildfromsource
+        revupgrade_autorun revupgrade_mode revupgrade_check_id_loadcmds
+        host_blacklist preferred_hosts sandbox_enable
         packagemaker_path default_compilers pkg_post_unarchive_deletions"
-    variable user_options ""
-    variable portinterp_options "\
-        portdbpath porturl portpath portbuildpath auto_path prefix prefix_frozen portsharepath \
-        registry.path registry.format user_home \
-        portarchivetype archivefetch_pubkeys portautoclean porttrace keeplogs portverbose destroot_umask \
-        rsync_server rsync_options rsync_dir startupitem_type startupitem_install place_worksymlink macportsuser \
-        configureccache ccache_dir ccache_size configuredistcc configurepipe buildnicevalue buildmakejobs \
-        applications_dir current_phase frameworks_dir developer_dir universal_archs build_arch \
-        os_arch os_endian os_version os_major os_platform macosx_version macosx_deployment_target \
-        packagemaker_path default_compilers sandbox_enable \
+    variable user_options {}
+    variable portinterp_options "
+        portdbpath porturl portpath portbuildpath auto_path prefix prefix_frozen portsharepath
+        registry.path registry.format user_home
+        portarchivetype archivefetch_pubkeys portautoclean porttrace keeplogs portverbose destroot_umask
+        rsync_server rsync_options rsync_dir startupitem_type startupitem_install place_worksymlink macportsuser
+        configureccache ccache_dir ccache_size configuredistcc configurepipe buildnicevalue buildmakejobs
+        applications_dir current_phase frameworks_dir developer_dir universal_archs build_arch
+        os_arch os_endian os_version os_major os_platform macosx_version macosx_deployment_target
+        packagemaker_path default_compilers sandbox_enable
         pkg_post_unarchive_deletions $user_options"
 
     # deferred options are only computed when needed.
     # they are not exported to the trace thread.
     # they are not exported to the interpreter in system_options array.
-    variable portinterp_deferred_options "xcodeversion xcodebuildcmd developer_dir"
+    variable portinterp_deferred_options [list xcodeversion xcodebuildcmd developer_dir]
 
     variable open_mports {}
 
     variable ui_priorities "error warn msg notice info debug any"
     variable port_phases "any fetch checksum"
-    variable current_phase "main"
+    variable current_phase main
 
     variable ui_prefix "---> "
 }
@@ -100,7 +100,7 @@
 # ui_options accessor
 proc macports::ui_isset {val} {
     if {[info exists macports::ui_options($val)]} {
-        if {$macports::ui_options($val) == "yes"} {
+        if {$macports::ui_options($val) eq "yes"} {
             return 1
         }
     }
@@ -111,7 +111,7 @@
 # global_options accessor
 proc macports::global_option_isset {val} {
     if {[info exists macports::global_options($val)]} {
-        if {$macports::global_options($val) == "yes"} {
+        if {$macports::global_options($val) eq "yes"} {
             return 1
         }
     }
@@ -130,7 +130,7 @@
     }
     # Add our log-channel to all already initialized channels
     foreach key [array names channels] {
-        set macports::channels($key) [concat $macports::channels($key) "debuglog"]
+        set macports::channels($key) [concat $macports::channels($key) debuglog]
     }
     return 0
 }
@@ -144,13 +144,13 @@
 
     set logname [macports::getportlogpath $portpath $portname]
     file mkdir $logname
-    set logname [file join $logname "main.log"]
+    set logname [file join $logname main.log]
 
     set ::debuglogname $logname
 
     # Truncate the file if already exists
     set ::debuglog [open $::debuglogname w]
-    puts $::debuglog "version:1"
+    puts $::debuglog version:1
 }
 proc macports::push_log {mport} {
     global ::logstack ::logenabled ::debuglog ::debuglogname
@@ -196,7 +196,7 @@
 proc set_phase {phase} {
     global macports::current_phase
     set macports::current_phase $phase
-    if {$phase != "main"} {
+    if {$phase ne "main"} {
         set cur_time [clock format [clock seconds] -format  {%+}]
         ui_debug "$phase phase started at $cur_time"
     }
@@ -205,23 +205,23 @@
 proc ui_message {priority prefix phase args} {
     global macports::channels ::debuglog macports::current_phase
     foreach chan $macports::channels($priority) {
-        if {[info exists ::debuglog] && ($chan == "debuglog")} {
+        if {[info exists ::debuglog] && ($chan eq "debuglog")} {
             set chan $::debuglog
             if {[info exists macports::current_phase]} {
                 set phase $macports::current_phase
             }
             set strprefix ":$priority:$phase "
-            if {[lindex $args 0] == "-nonewline"} {
-                puts -nonewline $chan "$strprefix[lindex $args 1]"
+            if {[lindex $args 0] eq "-nonewline"} {
+                puts -nonewline $chan $strprefix[lindex $args 1]
             } else {
-                puts $chan "$strprefix[lindex $args 0]"
+                puts $chan $strprefix[lindex $args 0]
             }
- 
+
         } else {
-            if {[lindex $args 0] == "-nonewline"} {
-                puts -nonewline $chan "$prefix[lindex $args 1]"
+            if {[lindex $args 0] eq "-nonewline"} {
+                puts -nonewline $chan $prefix[lindex $args 1]
             } else {
-                puts $chan "$prefix[lindex $args 0]"
+                puts $chan $prefix[lindex $args 0]
             }
         }
     }
@@ -235,10 +235,10 @@
     } else {
         set channels($priority) $default_channel
     }
-    
+
     # if some priority initialized after log file is being created
     if {[info exists ::debuglog]} {
-        set channels($priority) [concat $channels($priority) "debuglog"]
+        set channels($priority) [concat $channels($priority) debuglog]
     }
     # Simplify ui_$priority.
     try {
@@ -248,11 +248,11 @@
     }
     set phases {fetch checksum}
     try {
-        eval ::ui_init $priority $prefix $channels($priority) $args
+        ::ui_init $priority $prefix $channels($priority) {*}$args
     } catch * {
-        interp alias {} ui_$priority {} ui_message $priority $prefix ""
+        interp alias {} ui_$priority {} ui_message $priority $prefix {}
         foreach phase $phases {
-            interp alias {} ui_${priority}_${phase} {} ui_message $priority $prefix $phase
+            interp alias {} ui_${priority}_$phase {} ui_message $priority $prefix $phase
         }
     }
 }
@@ -270,7 +270,7 @@
             return "Warning: "
         }
         default {
-            return ""
+            return {}
         }
     }
 }
@@ -326,19 +326,19 @@
 # Replace puts to catch errors (typically broken pipes when being piped to head)
 rename puts tcl::puts
 proc puts {args} {
-    catch "tcl::puts $args"
+    catch {tcl::puts $args}
 }
 
 # find a binary either in a path defined at MacPorts' configuration time
 # or in the PATH environment variable through macports::binaryInPath (fallback)
-proc macports::findBinary {prog {autoconf_hint ""}} {
-    if {${autoconf_hint} != "" && [file executable ${autoconf_hint}]} {
-        return ${autoconf_hint}
+proc macports::findBinary {prog {autoconf_hint {}}} {
+    if {$autoconf_hint ne {} && [file executable $autoconf_hint]} {
+        return $autoconf_hint
     } else {
-        if {[catch {set cmd_path [macports::binaryInPath ${prog}]} result] == 0} {
-            return ${cmd_path}
+        if {[catch {set cmd_path [macports::binaryInPath $prog]} result] == 0} {
+            return $cmd_path
         } else {
-            return -code error "${result} or at its MacPorts configuration time location, did you move it?"
+            return -code error "$result or at its MacPorts configuration time location, did you move it?"
         }
     }
 }
@@ -358,7 +358,7 @@
 # deferred option processing
 proc macports::getoption {name} {
     global macports::$name
-    return [expr $$name]
+    return [set $name]
 }
 
 # deferred and on-need extraction of xcodeversion and xcodebuildcmd.
@@ -371,51 +371,51 @@
     if {![catch {findBinary xcodebuild $macports::autoconf::xcodebuild_path} xcodebuild]} {
         if {![info exists xcodeversion]} {
             # Determine xcode version
-            set macports::xcodeversion "2.0orlower"
+            set macports::xcodeversion 2.0orlower
             if {[catch {set xcodebuildversion [exec -- $xcodebuild -version 2> /dev/null]}] == 0} {
                 if {[regexp {Xcode ([0-9.]+)} $xcodebuildversion - xcode_v] == 1} {
                     set macports::xcodeversion $xcode_v
-                } elseif {[regexp "DevToolsCore-(.*);" $xcodebuildversion - devtoolscore_v] == 1} {
+                } elseif {[regexp {DevToolsCore-(.*);} $xcodebuildversion - devtoolscore_v] == 1} {
                     if {$devtoolscore_v >= 1809.0} {
-                        set macports::xcodeversion "3.2.6"
+                        set macports::xcodeversion 3.2.6
                     } elseif {$devtoolscore_v >= 1204.0} {
-                        set macports::xcodeversion "3.1.4"
+                        set macports::xcodeversion 3.1.4
                     } elseif {$devtoolscore_v >= 1100.0} {
-                        set macports::xcodeversion "3.1"
+                        set macports::xcodeversion 3.1
                     } elseif {$devtoolscore_v >= 921.0} {
-                        set macports::xcodeversion "3.0"
+                        set macports::xcodeversion 3.0
                     } elseif {$devtoolscore_v >= 798.0} {
-                        set macports::xcodeversion "2.5"
+                        set macports::xcodeversion 2.5
                     } elseif {$devtoolscore_v >= 762.0} {
-                        set macports::xcodeversion "2.4.1"
+                        set macports::xcodeversion 2.4.1
                     } elseif {$devtoolscore_v >= 757.0} {
-                        set macports::xcodeversion "2.4"
+                        set macports::xcodeversion 2.4
                     } elseif {$devtoolscore_v > 650.0} {
                         # XXX find actual version corresponding to 2.3
-                        set macports::xcodeversion "2.3"
+                        set macports::xcodeversion 2.3
                     } elseif {$devtoolscore_v >= 650.0} {
-                        set macports::xcodeversion "2.2.1"
+                        set macports::xcodeversion 2.2.1
                     } elseif {$devtoolscore_v > 620.0} {
                         # XXX find actual version corresponding to 2.2
-                        set macports::xcodeversion "2.2"
+                        set macports::xcodeversion 2.2
                     } elseif {$devtoolscore_v >= 620.0} {
-                        set macports::xcodeversion "2.1"
+                        set macports::xcodeversion 2.1
                     }
                 }
             } else {
                 ui_warn "xcodebuild exists but failed to execute"
-                set macports::xcodeversion "none"
+                set macports::xcodeversion none
             }
         }
         if {![info exists xcodebuildcmd]} {
-            set macports::xcodebuildcmd "$xcodebuild"
+            set macports::xcodebuildcmd $xcodebuild
         }
     } else {
         if {![info exists xcodeversion]} {
-            set macports::xcodeversion "none"
+            set macports::xcodeversion none
         }
         if {![info exists xcodebuildcmd]} {
-            set macports::xcodebuildcmd "none"
+            set macports::xcodebuildcmd none
         }
     }
 }
@@ -425,7 +425,7 @@
     global macports::developer_dir macports::os_major macports::xcodeversion
 
     trace remove variable macports::developer_dir read macports::set_developer_dir
-    
+
     # Look for xcodeselect, and make sure it has a valid value
     if {![catch {findBinary xcode-select $macports::autoconf::xcode_select_path} xcodeselect]} {
 
@@ -438,21 +438,21 @@
         }
 
         # The directory from xcode-select isn't correct.
-        
+
         # Ask mdfind where Xcode is and make some suggestions for the user,
         # searching by bundle identifier for various Xcode versions (3.x and 4.x)
         set installed_xcodes {}
         if {![catch {findBinary mdfind $macports::autoconf::mdfind_path} mdfind]} {
-            set installed_xcodes [exec $mdfind "kMDItemCFBundleIdentifier == 'com.apple.Xcode' || kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'"]
+            set installed_xcodes [exec $mdfind {kMDItemCFBundleIdentifier == 'com.apple.Xcode' || kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'}]
         }
-        
+
         # In case mdfind metadata wasn't complete, also look in two well-known locations for Xcode.app
         foreach app {/Applications/Xcode.app /Developer/Applications/Xcode.app} {
             if {[file isdirectory $app]} {
                 lappend installed_xcodes $app
             }
         }
-        
+
         # Form a list of unique xcode installations
         set installed_xcodes [lsort -unique $installed_xcodes]
 
@@ -460,24 +460,24 @@
         ui_error
         if {[llength $installed_xcodes] > 0 && ![catch {findBinary mdls $macports::autoconf::mdls_path} mdls]} {
             # One, or more than one, Xcode installations found
-            ui_error "No valid Xcode installation is properly selected."
-            ui_error "Please use xcode-select to select an Xcode installation:"
+            ui_error {No valid Xcode installation is properly selected.}
+            ui_error {Please use xcode-select to select an Xcode installation:}
             foreach xcode $installed_xcodes {
                 set vers [exec $mdls -raw -name kMDItemVersion $xcode]
-                if {$vers == "(null)"} { set vers "unknown" }
-                if {[_is_valid_developer_dir "${xcode}/Contents/Developer"]} {
+                if {$vers eq {(null)}} {set vers unknown}
+                if {[_is_valid_developer_dir $xcode/Contents/Developer]} {
                     # Though xcode-select shipped with xcode 4.3 supports and encourages
                     # direct use of the app path, older xcode-select does not.
                     # Specify the Contents/Developer directory if it exists
-                    ui_error "    sudo xcode-select -switch ${xcode}/Contents/Developer # version ${vers}"
+                    ui_error "    sudo xcode-select -switch $xcode/Contents/Developer # version $vers"
                 } elseif {[vercmp $vers 4.3] >= 0} {
                     # Future proofing: fall back to the app-path only for xcode >= 4.3, since Contents/Developer doesn't exist
-                    ui_error "    sudo xcode-select -switch ${xcode} # version ${vers}"
-                } elseif {[_is_valid_developer_dir "${xcode}/../.."]} {
+                    ui_error "    sudo xcode-select -switch $xcode # version $vers"
+                } elseif {[_is_valid_developer_dir $xcode/../..]} {
                     # Older xcode (< 4.3) is below the developer directory
-                    ui_error "    sudo xcode-select -switch [file normalize ${xcode}/../..] # version ${vers}"
+                    ui_error "    sudo xcode-select -switch [file normalize $xcode/../..] # version $vers"
                 } else {
-                    ui_error "    # malformed Xcode at ${xcode}, version ${vers}"
+                    ui_error "    # malformed Xcode at $xcode, version $vers"
                 }
             }
         } else {
@@ -489,9 +489,9 @@
 
     # Try the default
     if {$os_major >= 11 && [vercmp $xcodeversion 4.3] >= 0} {
-        set devdir "/Applications/Xcode.app/Contents/Developer"
+        set devdir /Applications/Xcode.app/Contents/Developer
     } else {
-        set devdir "/Developer"
+        set devdir /Developer
     }
 
     set macports::developer_dir $devdir
@@ -507,7 +507,7 @@
 
     # Verify that the directory has some key subdirectories
     foreach subdir {Library usr} {
-        if {![file isdirectory "${dir}/${subdir}"]} {
+        if {![file isdirectory $dir/$subdir]} {
             return 0
         }
     }
@@ -518,29 +518,30 @@
 
 
 proc mportinit {{up_ui_options {}} {up_options {}} {up_variations {}}} {
-    if {$up_ui_options eq ""} {
+    if {$up_ui_options eq {}} {
         array set macports::ui_options {}
     } else {
         upvar $up_ui_options temp_ui_options
         array set macports::ui_options [array get temp_ui_options]
     }
-    if {$up_options eq ""} {
+    if {$up_options eq {}} {
         array set macports::global_options {}
     } else {
         upvar $up_options temp_options
         array set macports::global_options [array get temp_options]
     }
-    if {$up_variations eq ""} {
+    if {$up_variations eq {}} {
         array set variations {}
     } else {
         upvar $up_variations variations
     }
 
     # Initialize ui_*
-    foreach priority ${macports::ui_priorities} {
+    foreach priority $macports::ui_priorities {
         macports::ui_init $priority
     }
 
+
     global auto_path env tcl_platform \
         macports::autoconf::macports_conf_path \
         macports::macports_user_dir \
@@ -585,17 +586,17 @@
 
     # set up platform info variables
     set os_arch $tcl_platform(machine)
-    if {$os_arch == "Power Macintosh"} { set os_arch "powerpc" }
-    if {$os_arch == "i586" || $os_arch == "i686" || $os_arch == "x86_64"} { set os_arch "i386" }
+    if {$os_arch eq "Power Macintosh"} {set os_arch "powerpc"}
+    if {$os_arch eq "i586" || $os_arch eq "i686" || $os_arch eq "x86_64"} {set os_arch "i386"}
     set os_version $tcl_platform(osVersion)
     set os_major [lindex [split $os_version .] 0]
     set os_platform [string tolower $tcl_platform(os)]
     # Remove trailing "Endian"
     set os_endian [string range $tcl_platform(byteOrder) 0 end-6]
     set macosx_version {}
-    if {$os_platform == "darwin"} {
+    if {$os_platform eq "darwin"} {
         # This will probably break when Apple changes versioning
-        set macosx_version [expr 10.0 + ($os_major - 4) / 10.0]
+        set macosx_version [expr {10.0 + ($os_major - 4) / 10.0}]
     }
 
     # Ensure that the macports user directory (i.e. ~/.macports) exists if HOME is defined.
@@ -603,32 +604,32 @@
     if {[info exists env(HOME)]} {
         set macports::user_home $env(HOME)
         set macports::macports_user_dir [file normalize $macports::autoconf::macports_user_dir]
-    } elseif {[info exists env(SUDO_USER)] && $os_platform == "darwin"} {
+    } elseif {[info exists env(SUDO_USER)] && $os_platform eq "darwin"} {
         set macports::user_home [exec dscl -q . -read /Users/$env(SUDO_USER) NFSHomeDirectory | cut -d ' ' -f 2]
-        set macports::macports_user_dir [file join ${macports::user_home} [string range $macports::autoconf::macports_user_dir 2 end]]
-    } elseif {[exec id -u] != 0 && $os_platform == "darwin"} {
+        set macports::macports_user_dir [file join $macports::user_home [string range $macports::autoconf::macports_user_dir 2 end]]
+    } elseif {[exec id -u] ne 0 && $os_platform eq "darwin"} {
         set macports::user_home [exec dscl -q . -read /Users/[exec id -un] NFSHomeDirectory | cut -d ' ' -f 2]
-        set macports::macports_user_dir [file join ${macports::user_home} [string range $macports::autoconf::macports_user_dir 2 end]]
+        set macports::macports_user_dir [file join $macports::user_home [string range $macports::autoconf::macports_user_dir 2 end]]
     } else {
         # Otherwise define the user directory as a directory that will never exist
-        set macports::macports_user_dir "/dev/null/NO_HOME_DIR"
-        set macports::user_home "/dev/null/NO_HOME_DIR"
+        set macports::macports_user_dir /dev/null/NO_HOME_DIR
+        set macports::user_home /dev/null/NO_HOME_DIR
     }
 
     # Configure the search path for configuration files
-    set conf_files ""
-    lappend conf_files "${macports_conf_path}/macports.conf"
-    if { [file isdirectory $macports_user_dir] } {
-        lappend conf_files "${macports_user_dir}/macports.conf"
+    set conf_files {}
+    lappend conf_files $macports_conf_path/macports.conf
+    if {[file isdirectory $macports_user_dir]} {
+        lappend conf_files $macports_user_dir/macports.conf
     }
     if {[info exists env(PORTSRC)]} {
         set PORTSRC $env(PORTSRC)
-        lappend conf_files ${PORTSRC}
+        lappend conf_files $PORTSRC
     }
 
     # Process all configuration files we find on conf_files list
     foreach file $conf_files {
-        if [file exists $file] {
+        if {[file exists $file]} {
             set portconf $file
             set fd [open $file r]
             while {[gets $fd line] >= 0} {
@@ -644,8 +645,8 @@
     }
 
     # Process per-user only settings
-    set per_user "${macports_user_dir}/user.conf"
-    if [file exists $per_user] {
+    set per_user $macports_user_dir/user.conf
+    if {[file exists $per_user]} {
         set fd [open $per_user r]
         while {[gets $fd line] >= 0} {
             if {[regexp {^(\w+)([ \t]+(.*))?$} $line match option ignore val] == 1} {
@@ -659,7 +660,7 @@
     }
 
     if {![info exists sources_conf]} {
-        return -code error "sources_conf must be set in ${macports_conf_path}/macports.conf or in your ${macports_user_dir}/macports.conf file"
+        return -code error "sources_conf must be set in $macports_conf_path/macports.conf or in your $macports_user_dir/macports.conf file"
     }
     set fd [open $sources_conf r]
     while {[gets $fd line] >= 0} {
@@ -671,7 +672,7 @@
                     if {[lsearch -exact [list nosync default] $flag] == -1} {
                         ui_warn "$sources_conf source '$line' specifies invalid flag '$flag'"
                     }
-                    if {$flag == "default"} {
+                    if {$flag eq "default"} {
                         if {[info exists sources_default]} {
                             ui_warn "More than one default port source is defined."
                         }
@@ -695,14 +696,14 @@
 
     if {![info exists sources]} {
         if {[file isdirectory ports]} {
-            set sources "file://[pwd]/ports"
+            set sources file://[pwd]/ports
         } else {
             return -code error "No sources defined in $sources_conf"
         }
     }
 
     if {[info exists variants_conf]} {
-        if {[file exist $variants_conf]} {
+        if {[file exists $variants_conf]} {
             set fd [open $variants_conf r]
             while {[gets $fd line] >= 0} {
                 set line [string trimright $line]
@@ -728,8 +729,8 @@
 
     # pubkeys.conf
     set macports::archivefetch_pubkeys {}
-    if {[file isfile [file join ${macports_conf_path} pubkeys.conf]]} {
-        set fd [open [file join ${macports_conf_path} pubkeys.conf] r]
+    if {[file isfile [file join $macports_conf_path pubkeys.conf]]} {
+        set fd [open [file join $macports_conf_path pubkeys.conf] r]
         while {[gets $fd line] >= 0} {
             set line [string trim $line]
             if {![regexp {^[\ \t]*#.*$|^$} $line]} {
@@ -742,7 +743,7 @@
     }
 
     if {![info exists portdbpath]} {
-        return -code error "portdbpath must be set in ${macports_conf_path}/macports.conf or in your ${macports_user_dir}/macports.conf"
+        return -code error "portdbpath must be set in $macports_conf_path/macports.conf or in your $macports_user_dir/macports.conf"
     }
     if {![file isdirectory $portdbpath]} {
         if {![file exists $portdbpath]} {
@@ -759,7 +760,7 @@
 
     # Format for receipts; currently only "sqlite" is allowed
     # could previously be "flat", so we switch that to sqlite
-    if {![info exists portdbformat] || $portdbformat == "flat" || $portdbformat == "sqlite"} {
+    if {![info exists portdbformat] || $portdbformat eq "flat" || $portdbformat eq "sqlite"} {
         set registry.format receipt_sqlite
     } else {
         return -code error "unknown registry format '$portdbformat' set in macports.conf"
@@ -767,15 +768,15 @@
 
     # Autoclean mode, whether to automatically call clean after "install"
     if {![info exists portautoclean]} {
-        set macports::portautoclean "yes"
+        set macports::portautoclean yes
         global macports::portautoclean
     }
     # whether to keep logs after successful builds
     if {![info exists keeplogs]} {
-        set macports::keeplogs "no"
+        set macports::keeplogs no
         global macports::keeplogs
     }
-   
+
     # Check command line override for autoclean
     if {[info exists macports::global_options(ports_autoclean)]} {
         if {![string equal $macports::global_options(ports_autoclean) $portautoclean]} {
@@ -784,7 +785,7 @@
     }
     # Trace mode, whether to use darwintrace to debug ports.
     if {![info exists porttrace]} {
-        set macports::porttrace "no"
+        set macports::porttrace no
         global macports::porttrace
     }
     # Check command line override for trace
@@ -797,14 +798,14 @@
     if {![info exists macports::global_options(ports_binary_only)]
         && ![info exists macports::global_options(ports_source_only)]
         && [info exists macports::buildfromsource]} {
-        if {${macports::buildfromsource} == "never"} {
+        if {$macports::buildfromsource eq "never"} {
             set macports::global_options(ports_binary_only) yes
             set temp_options(ports_binary_only) yes
-        } elseif {${macports::buildfromsource} == "always"} {
+        } elseif {$macports::buildfromsource eq "always"} {
             set macports::global_options(ports_source_only) yes
             set temp_options(ports_source_only) yes
-        } elseif {${macports::buildfromsource} != "ifneeded"} {
-            ui_warn "'buildfromsource' set to unknown value '${macports::buildfromsource}', using 'ifneeded' instead"
+        } elseif {$macports::buildfromsource ne "ifneeded"} {
+            ui_warn "'buildfromsource' set to unknown value '$macports::buildfromsource', using 'ifneeded' instead"
         }
     }
 
@@ -818,7 +819,7 @@
 
     # Export verbosity.
     if {![info exists portverbose]} {
-        set macports::portverbose "no"
+        set macports::portverbose no
         global macports::portverbose
     }
     if {[info exists macports::ui_options(ports_verbose)]} {
@@ -831,7 +832,7 @@
     # CPIO, XAR, etc.)
     global macports::portarchivetype
     if {![info exists portarchivetype]} {
-        set macports::portarchivetype "tbz2"
+        set macports::portarchivetype tbz2
     } else {
         set macports::portarchivetype [lindex $portarchivetype 0]
     }
@@ -850,24 +851,24 @@
         set rsync_options "-rtzv --delete-after"
     }
 
-    set portsharepath ${prefix}/share/macports
+    set portsharepath $prefix/share/macports
     if {![file isdirectory $portsharepath]} {
         return -code error "Data files directory '$portsharepath' must exist"
     }
 
     if {![info exists libpath]} {
-        set libpath "${prefix}/share/macports/Tcl"
+        set libpath $prefix/share/macports/Tcl
     }
 
     if {![info exists binpath]} {
-        set env(PATH) "${prefix}/bin:${prefix}/sbin:/bin:/sbin:/usr/bin:/usr/sbin"
+        set env(PATH) $prefix/bin:$prefix/sbin:/bin:/sbin:/usr/bin:/usr/sbin
     } else {
-        set env(PATH) "$binpath"
+        set env(PATH) $binpath
     }
 
     # Set startupitem default type (can be overridden by portfile)
     if {![info exists macports::startupitem_type]} {
-        set macports::startupitem_type "default"
+        set macports::startupitem_type default
     }
 
     # Set whether startupitems are symlinked into system directories
@@ -888,7 +889,7 @@
         set macports::ccache_dir [file join $portdbpath build .ccache]
     }
     if {![info exists macports::ccache_size]} {
-        set macports::ccache_size "2G"
+        set macports::ccache_size 2G
     }
     if {![info exists macports::configuredistcc]} {
         set macports::configuredistcc no
@@ -920,10 +921,10 @@
     } elseif {[llength $macports::universal_archs] < 2} {
         ui_warn "invalid universal_archs configured (should contain at least 2 archs)"
     }
-    
+
     # Default arch to build for
     if {![info exists macports::build_arch]} {
-        if {$os_platform == "darwin"} {
+        if {$os_platform eq "darwin"} {
             if {$os_major >= 10} {
                 if {[sysctl hw.cpu64bit_capable] == 1} {
                     set macports::build_arch x86_64
@@ -931,14 +932,14 @@
                     set macports::build_arch i386
                 }
             } else {
-                if {$os_arch == "powerpc"} {
+                if {$os_arch eq "powerpc"} {
                     set macports::build_arch ppc
                 } else {
                     set macports::build_arch i386
                 }
             }
         } else {
-            set macports::build_arch ""
+            set macports::build_arch {}
         }
     } else {
         set macports::build_arch [lindex $macports::build_arch 0]
@@ -952,12 +953,12 @@
         set macports::revupgrade_autorun yes
     }
     if {![info exists macports::revupgrade_mode]} {
-        set macports::revupgrade_mode "rebuild"
+        set macports::revupgrade_mode rebuild
     }
     if {![info exists macports::global_options(ports_rev-upgrade_id-loadcmd-check)]
          && [info exists macports::revupgrade_check_id_loadcmds]} {
-        set macports::global_options(ports_rev-upgrade_id-loadcmd-check) ${macports::revupgrade_check_id_loadcmds}
-        set temp_options(ports_rev-upgrade_id-loadcmd-check) ${macports::revupgrade_check_id_loadcmds}
+        set macports::global_options(ports_rev-upgrade_id-loadcmd-check) $macports::revupgrade_check_id_loadcmds
+        set temp_options(ports_rev-upgrade_id-loadcmd-check) $macports::revupgrade_check_id_loadcmds
     }
 
     if {![info exists macports::sandbox_enable]} {
@@ -979,7 +980,7 @@
         COLUMNS LINES
     }
     if {[info exists extra_env]} {
-        set keepenvkeys [concat ${keepenvkeys} ${extra_env}]
+        set keepenvkeys [concat $keepenvkeys $extra_env]
     }
 
     if {[file isdirectory $libpath]} {
@@ -999,9 +1000,9 @@
 
     # don't keep unusable TMPDIR/TMP values
     foreach var {TMP TMPDIR} {
-        if {[info exists env($var)] && [file writable $env($var)] && 
-            ([getuid] != 0 || $macportsuser == "root" ||
-             [file attributes $env($var) -owner] == $macportsuser)} {
+        if {[info exists env($var)] && [file writable $env($var)] &&
+            ([getuid] != 0 || $macportsuser eq "root" ||
+             [file attributes $env($var) -owner] eq $macportsuser)} {
             lappend keepenvkeys $var
         }
     }
@@ -1014,7 +1015,7 @@
     }
 
     # unset environment an extra time, to work around bugs in Leopard Tcl
-    if {$macosx_version == "10.5"} {
+    if {$macosx_version eq "10.5"} {
         foreach envkey $env_names {
             if {[lsearch -exact $keepenvkeys $envkey] == -1} {
                 unsetenv $envkey
@@ -1029,21 +1030,21 @@
     }
 
     if {![info exists developer_dir]} {
-        if {$os_platform == "darwin"} {
+        if {$os_platform eq "darwin"} {
             trace add variable macports::developer_dir read macports::set_developer_dir
         } else {
-            set macports::developer_dir ""
+            set macports::developer_dir {}
         }
     } else {
-        if {$os_platform == "darwin" && ![file isdirectory $developer_dir]} {
+        if {$os_platform eq "darwin" && ![file isdirectory $developer_dir]} {
             ui_warn "Your developer_dir setting in macports.conf points to a non-existing directory.\
                 Since this is known to cause problems, please correct the setting or comment it and let\
                 macports auto-discover the correct path."
         }
     }
 
-    if {[getuid] == 0 && $os_major >= 11 && $os_platform == "darwin" && 
-            [file isfile "${macports::user_home}/Library/Preferences/com.apple.dt.Xcode.plist"]} {
+    if {[getuid] == 0 && $os_major >= 11 && $os_platform eq "darwin" &&
+            [file isfile "$macports::user_home/Library/Preferences/com.apple.dt.Xcode.plist"]} {
         macports::copy_xcode_plist $env(HOME)
     }
 
@@ -1053,49 +1054,49 @@
     }
 
     if {[info exists master_site_local] && ![info exists env(MASTER_SITE_LOCAL)]} {
-        set env(MASTER_SITE_LOCAL) "$master_site_local"
+        set env(MASTER_SITE_LOCAL) $master_site_local
     }
     if {[info exists patch_site_local] && ![info exists env(PATCH_SITE_LOCAL)]} {
-        set env(PATCH_SITE_LOCAL) "$patch_site_local"
+        set env(PATCH_SITE_LOCAL) $patch_site_local
     }
     if {[info exists archive_site_local] && ![info exists env(ARCHIVE_SITE_LOCAL)]} {
-        set env(ARCHIVE_SITE_LOCAL) "$archive_site_local"
+        set env(ARCHIVE_SITE_LOCAL) $archive_site_local
     }
 
     # Proxy handling (done this late since Pextlib is needed)
-    if {![info exists proxy_override_env] } {
-        set proxy_override_env "no"
+    if {![info exists proxy_override_env]} {
+        set proxy_override_env no
     }
     if {[catch {array set sysConfProxies [get_systemconfiguration_proxies]} result]} {
         return -code error "Unable to get proxy configuration from system: $result"
     }
-    if {![info exists env(http_proxy)] || $proxy_override_env == "yes" } {
+    if {![info exists env(http_proxy)] || $proxy_override_env eq "yes"} {
         if {[info exists proxy_http]} {
             set env(http_proxy) $proxy_http
         } elseif {[info exists sysConfProxies(proxy_http)]} {
             set env(http_proxy) $sysConfProxies(proxy_http)
         }
     }
-    if {![info exists env(HTTPS_PROXY)] || $proxy_override_env == "yes" } {
+    if {![info exists env(HTTPS_PROXY)] || $proxy_override_env eq "yes"} {
         if {[info exists proxy_https]} {
             set env(HTTPS_PROXY) $proxy_https
         } elseif {[info exists sysConfProxies(proxy_https)]} {
             set env(HTTPS_PROXY) $sysConfProxies(proxy_https)
         }
     }
-    if {![info exists env(FTP_PROXY)] || $proxy_override_env == "yes" } {
+    if {![info exists env(FTP_PROXY)] || $proxy_override_env eq "yes"} {
         if {[info exists proxy_ftp]} {
             set env(FTP_PROXY) $proxy_ftp
         } elseif {[info exists sysConfProxies(proxy_ftp)]} {
             set env(FTP_PROXY) $sysConfProxies(proxy_ftp)
         }
     }
-    if {![info exists env(RSYNC_PROXY)] || $proxy_override_env == "yes" } {
+    if {![info exists env(RSYNC_PROXY)] || $proxy_override_env eq "yes"} {
         if {[info exists proxy_rsync]} {
             set env(RSYNC_PROXY) $proxy_rsync
         }
     }
-    if {![info exists env(NO_PROXY)] || $proxy_override_env == "yes" } {
+    if {![info exists env(NO_PROXY)] || $proxy_override_env eq "yes"} {
         if {[info exists proxy_skip]} {
             set env(NO_PROXY) $proxy_skip
         } elseif {[info exists sysConfProxies(proxy_skip)]} {
@@ -1104,22 +1105,22 @@
     }
 
     # add ccache to environment
-    set env(CCACHE_DIR) ${macports::ccache_dir}
+    set env(CCACHE_DIR) $macports::ccache_dir
 
     # load cached ping times
     if {[catch {
-        set pingfile [open ${macports::portdbpath}/pingtimes r]
+        set pingfile [open $macports::portdbpath/pingtimes r]
         array set macports::ping_cache [gets $pingfile]
         close $pingfile
-    }]} { array set macports::ping_cache {} }
+    }]} {array set macports::ping_cache {}}
     # set up arrays of blacklisted and preferred hosts
     if {[info exists macports::host_blacklist]} {
-        foreach host ${macports::host_blacklist} {
+        foreach host $macports::host_blacklist {
             set macports::host_blacklisted($host) 1
         }
     }
     if {[info exists macports::preferred_hosts]} {
-        foreach host ${macports::preferred_hosts} {
+        foreach host $macports::preferred_hosts {
             set macports::host_preferred($host) 1
         }
     }
@@ -1128,10 +1129,11 @@
     _mports_load_quickindex
 
     if {![info exists macports::ui_options(ports_no_old_index_warning)]} {
-        set default_source_url [lindex ${sources_default} 0]
-        if {[macports::getprotocol $default_source_url] == "file" || [macports::getprotocol $default_source_url] == "rsync"} {
+        set default_source_url [lindex $sources_default 0]
+        if {[macports::getprotocol $default_source_url] eq "file"
+            || [macports::getprotocol $default_source_url] eq "rsync"} {
             set default_portindex [macports::getindex $default_source_url]
-            if {[file exists $default_portindex] && [expr [clock seconds] - [file mtime $default_portindex]] > 1209600} {
+            if {[file exists $default_portindex] && [clock seconds] - [file mtime $default_portindex] > 1209600} {
                 ui_warn "port definitions are more than two weeks old, consider updating them by running 'port selfupdate'."
             }
         }
@@ -1148,7 +1150,7 @@
     if {$db_exists == 0 && [file exists ${registry.path}/receipts] && [file writable $db_path]} {
         ui_warn "Converting your registry to sqlite format, this might take a while..."
         if {[catch {registry::convert_to_sqlite}]} {
-            ui_debug "$::errorInfo"
+            ui_debug $::errorInfo
             file delete -force $db_path
             error "Failed to convert your registry to sqlite!"
         } else {
@@ -1161,15 +1163,15 @@
 proc mportshutdown {} {
     # save ping times
     global macports::ping_cache macports::portdbpath
-    if {[file writable ${macports::portdbpath}]} {
+    if {[file writable $macports::portdbpath]} {
         catch {
             foreach host [array names ping_cache] {
                 # don't save expired entries
-                if {[expr [clock seconds] - [lindex $ping_cache($host) 1]] < 86400} {
+                if {[clock seconds] - [lindex $ping_cache($host) 1] < 86400} {
                     lappend pinglist_fresh $host $ping_cache($host)
                 }
             }
-            set pingfile [open ${macports::portdbpath}/pingtimes w]
+            set pingfile [open $macports::portdbpath/pingtimes w]
             puts $pingfile $pinglist_fresh
             close $pingfile
         }
@@ -1181,22 +1183,22 @@
 # link plist for xcode 4.3's benefit
 proc macports::copy_xcode_plist {target_homedir} {
     global macports::user_home macports::macportsuser
-    set user_plist "${user_home}/Library/Preferences/com.apple.dt.Xcode.plist"
-    set target_dir "${target_homedir}/Library/Preferences"
-    file delete -force "${target_dir}/com.apple.dt.Xcode.plist"
+    set user_plist "$user_home/Library/Preferences/com.apple.dt.Xcode.plist"
+    set target_dir "$target_homedir/Library/Preferences"
+    file delete -force "$target_dir/com.apple.dt.Xcode.plist"
     if {[file isfile $user_plist]} {
-        if {![file isdirectory "${target_dir}"]} {
-            if {[catch {file mkdir "${target_dir}"} result]} {
-                ui_warn "Failed to create Library/Preferences in ${target_homedir}: $result"
+        if {![file isdirectory $target_dir]} {
+            if {[catch {file mkdir $target_dir} result]} {
+                ui_warn "Failed to create Library/Preferences in $target_homedir: $result"
                 return
             }
         }
-        if {[file writable ${target_dir}] && [catch {
-            ui_debug "Copying $user_plist to ${target_dir}"
+        if {[file writable $target_dir] && [catch {
+            ui_debug "Copying $user_plist to $target_dir"
             file copy -force $user_plist $target_dir
-            file attributes "${target_dir}/com.apple.dt.Xcode.plist" -owner $macportsuser -permissions 0644
+            file attributes $target_dir/com.apple.dt.Xcode.plist -owner $macportsuser -permissions 0644
         } result]} {
-            ui_warn "Failed to copy com.apple.dt.Xcode.plist to ${target_dir}: $result"
+            ui_warn "Failed to copy com.apple.dt.Xcode.plist to $target_dir: $result"
         }
     }
 }
@@ -1209,20 +1211,25 @@
     interp hide $workername exit
 
     # cd: This is necessary for some code in port1.0, but should be hidden
-    interp eval $workername "rename cd _cd"
+    interp eval $workername [list rename cd _cd]
 
     # Tell the sub interpreter about all the Tcl packages we already
     # know about so it won't glob for packages.
     foreach pkgName [package names] {
         foreach pkgVers [package versions $pkgName] {
             set pkgLoadScript [package ifneeded $pkgName $pkgVers]
-            $workername eval "package ifneeded $pkgName $pkgVers {$pkgLoadScript}"
+            $workername eval [list package ifneeded $pkgName $pkgVers $pkgLoadScript]
         }
     }
 
     # Create package require abstraction procedure
-    $workername eval "proc PortSystem \{version\} \{ \n\
-            package require port \$version \}"
+	set script {
+		proc PortSystem {version} {
+            package require port ${version}
+		}
+	}
+	set script [string map  [list \${version} [list $version]] $script]
+    $workername eval $script
 
     # Clearly separate slave interpreters and the master interpreter.
     $workername alias mport_exec mportexec
@@ -1233,17 +1240,17 @@
     $workername alias set_phase set_phase
 
     # instantiate the UI call-backs
-    foreach priority ${macports::ui_priorities} {
+    foreach priority $macports::ui_priorities {
         $workername alias ui_$priority ui_$priority
-        foreach phase ${macports::port_phases} {
-            $workername alias ui_${priority}_${phase} ui_${priority}_${phase}
+        foreach phase $macports::port_phases {
+            $workername alias ui_$priority_$phase ui_${priority}_$phase
         }
- 
+
     }
 
     $workername alias ui_prefix ui_prefix
     $workername alias ui_channels ui_channels
-    
+
     $workername alias ui_warn_once ui_warn_once
 
     # Export some utility functions defined here.
@@ -1297,33 +1304,37 @@
             global macports::$opt
         }
         if {[info exists $opt]} {
-            $workername eval set system_options($opt) \{[set $opt]\}
-            $workername eval set $opt \{[set $opt]\}
+            $workername eval [list set system_options($opt) [set $opt]]
+            $workername eval [list set system_options($opt) [set $opt]]
+            $workername eval [list set $opt [set $opt]]
         }
     }
 
     foreach opt $portinterp_deferred_options {
         global macports::$opt
         # define the trace hook.
-        $workername eval \
-            "proc trace_$opt {name1 name2 op} { \n\
-                trace remove variable ::$opt read ::trace_$opt \n\
-                global $opt \n\
-                set $opt \[getoption $opt\] \n\
-            }"
+        set script {
+            proc trace_${opt} {name1 name2 op} {
+                trace remove variable ::${opt} read ::trace_${opt}
+                global ${opt}
+                set ${opt} [getoption ${opt}]
+            }
+        }
+        set script [string map [list \${opt} $opt] $script]
+        $workername eval $script
         # next access will actually define the variable.
-        $workername eval "trace add variable ::$opt read ::trace_$opt"
+        $workername eval [list trace add variable ::$opt read ::trace_$opt]
         # define some value now
-        $workername eval set $opt "?"
+        $workername eval [list set $opt ?]
     }
 
     foreach {opt val} $options {
-        $workername eval set user_options($opt) $val
-        $workername eval set $opt $val
+        $workername eval [list set user_options($opt) $val]
+        $workername eval [list set $opt $val]
     }
 
     foreach {var val} $variations {
-        $workername eval set variations($var) $val
+        $workername eval [list set variations($var) $val]
     }
 }
 
@@ -1343,20 +1354,20 @@
     foreach pkgName [package names] {
         foreach pkgVers [package versions $pkgName] {
             set pkgLoadScript [package ifneeded $pkgName $pkgVers]
-            thread::send -async $result "package ifneeded $pkgName $pkgVers {$pkgLoadScript}"
+            thread::send -async $result [list package ifneeded $pkgName $pkgVers $pkgLoadScript]
         }
     }
 
     # inherit configuration variables.
-    thread::send -async $result "namespace eval macports {}"
+    thread::send -async $result [list namespace eval macports {}]
     foreach opt $portinterp_options {
         if {![info exists $opt]} {
             global macports::$opt
         }
         if {[info exists $opt]} {
-            thread::send -async $result "global macports::$opt"
+            thread::send -async $result [list global macports::$opt]
             set val [set macports::$opt]
-            thread::send -async $result "set macports::$opt \"$val\""
+            thread::send -async $result [list set macports::$opt $val]
         }
     }
 
@@ -1367,10 +1378,10 @@
     switch -- $suffix {
         .tbz -
         .tbz2 {
-            return "-j"
+            return -j
         }
         .tgz {
-            return "-z"
+            return -z
         }
         .txz {
             return "--use-compress-program [findBinary xz {}] -"
@@ -1379,7 +1390,7 @@
             return "--use-compress-program [findBinary lzma {}] -"
         }
         default {
-            return "-"
+            return -
         }
     }
 }
@@ -1404,16 +1415,16 @@
     # check if this is a binary archive or just the port dir
     set tarcmd [findBinary tar $macports::autoconf::tar_path]
     set tarflags [get_tar_flags [file extension $fetchfile]]
-    set qflag ${macports::autoconf::tar_q}
-    set cmdline "$tarcmd ${tarflags}${qflag}xOf \"$fetchfile\" +CONTENTS"
-    ui_debug "$cmdline"
-    if {![catch {set contents [eval exec $cmdline]}]} {
+    set qflag $macports::autoconf::tar_q
+    set cmdline "$tarcmd $tarflags${qflag}xOf \"$fetchfile\" +CONTENTS"
+    ui_debug $cmdline
+    if {![catch {set contents [exec {*}$cmdline]}]} {
         set binary 1
         ui_debug "getting port name from binary archive"
         # get the portname from the contents file
-        foreach line [split $contents "\n"] {
-            if {[lindex $line 0] == "@name"} {
-                # actually ${name}-${version}_${revision}
+        foreach line [split $contents \n] {
+            if {[lindex $line 0] eq "@name"} {
+                # actually $name-$version_$revision
                 set portname [lindex $line 1]
             }
         }
@@ -1428,12 +1439,12 @@
     # extract the portfile (and possibly files dir if not a binary archive)
     ui_debug "extracting port archive to [pwd]"
     if {$binary} {
-        set cmdline "$tarcmd ${tarflags}${qflag}xOf \"$fetchfile\" +PORTFILE > Portfile"
+        set cmdline [list $tarcmd $tarflags${qflag}xOf $fetchfile +PORTFILE > Portfile]
     } else {
-        set cmdline "$tarcmd ${tarflags}xf \"$fetchfile\""
+        set cmdline [list $tarcmd $tarflagsxf $fetchfile]
     }
-    ui_debug "$cmdline"
-    if {[catch {eval exec $cmdline} result]} {
+    ui_debug $cmdline
+    if {[catch {exec {*}$cmdline} result]} {
         return -code error "Port extract failed: $result"
     }
 
@@ -1443,7 +1454,7 @@
 
 proc macports::getprotocol {url} {
     if {[regexp {(?x)([^:]+)://.+} $url match protocol] == 1} {
-        return ${protocol}
+        return $protocol
     } else {
         return -code error "Can't parse url $url"
     }
@@ -1453,12 +1464,12 @@
 # I've added the destdir parameter.  This is the location a remotely
 # fetched port will be downloaded to (currently only applies to
 # mports:// sources).
-proc macports::getportdir {url {destdir "."}} {
+proc macports::getportdir {url {destdir .}} {
     global macports::extracted_portdirs
     set protocol [macports::getprotocol $url]
-    switch ${protocol} {
+    switch -- $protocol {
         file {
-            set path [file normalize [string range $url [expr [string length $protocol] + 3] end]]
+            set path [file normalize [string range $url [expr {[string length $protocol] + 3}] end]]
             if {![file isfile $path]} {
                 return $path
             } else {
@@ -1496,12 +1507,12 @@
 # @param path path in _resources we are interested in
 # @param fallback fall back to the default source tree
 # @return path to the _resources directory or the path to the fallback
-proc macports::getportresourcepath {url {path ""} {fallback yes}} {
+proc macports::getportresourcepath {url {path {}} {fallback yes}} {
     global macports::sources_default
 
     set protocol [getprotocol $url]
 
-    switch -- ${protocol} {
+    switch -- $protocol {
         file {
             set proposedpath [file normalize [file join [getportdir $url] .. ..]]
         }
@@ -1513,7 +1524,7 @@
     # append requested path
     set proposedpath [file join $proposedpath _resources $path]
 
-    if {$fallback == "yes" && ![file exists $proposedpath]} {
+    if {$fallback eq "yes" && ![file exists $proposedpath]} {
         return [getdefaultportresourcepath $path]
     }
 
@@ -1525,11 +1536,11 @@
 #
 # @param path path in _resources we are interested in
 # @return path to the _resources directory of the default source
-proc macports::getdefaultportresourcepath {{path ""}} {
+proc macports::getdefaultportresourcepath {{path {}}} {
     global macports::sources_default
 
-    set default_source_url [lindex ${sources_default} 0]
-    if {[getprotocol $default_source_url] == "file"} {
+    set default_source_url [lindex $sources_default 0]
+    if {[getprotocol $default_source_url] eq "file"} {
         set proposedpath [getportdir $default_source_url]
     } else {
         set proposedpath [getsourcepath $default_source_url]
@@ -1548,17 +1559,17 @@
 # of this function should be treated as an opaque handle to a
 # MacPorts Portfile.
 
-proc mportopen {porturl {options ""} {variations ""} {nocache ""}} {
+proc mportopen {porturl {options {}} {variations {}} {nocache {}}} {
     global macports::portdbpath macports::portconf macports::open_mports auto_path
 
     # Look for an already-open MPort with the same URL.
     # if found, return the existing reference and bump the refcount.
-    if {$nocache != ""} {
+    if {$nocache ne {}} {
         set mport {}
     } else {
         set mport [dlist_match_multi $macports::open_mports [list porturl $porturl variations $variations options $options]]
     }
-    if {$mport != {}} {
+    if {$mport ne {}} {
         # just in case more than one somehow matches
         set mport [lindex $mport 0]
         set refcnt [ditem_key $mport refcnt]
@@ -1571,7 +1582,7 @@
     if {[info exists options_array(portdir)]} {
         set portdir $options_array(portdir)
     } else {
-        set portdir ""
+        set portdir {}
     }
 
     set portpath [macports::getportdir $porturl $portdir]
@@ -1608,7 +1619,7 @@
 
     $workername eval port::run_callbacks
 
-    ditem_key $mport provides [$workername eval return \$subport]
+    ditem_key $mport provides [$workername eval {return $subport}]
 
     return $mport
 }
@@ -1618,24 +1629,24 @@
 proc mportopen_installed {name version revision variants options} {
     global macports::registry.path
     set regref [lindex [registry::entry imaged $name $version $revision $variants] 0]
-    set portfile_dir [file join ${registry.path} registry portfiles $name "${version}_${revision}${variants}"]
+    set portfile_dir [file join ${registry.path} registry portfiles $name ${version}_$revision$variants]
     file mkdir $portfile_dir
-    set fd [open "${portfile_dir}/Portfile" w]
+    set fd [open $portfile_dir/Portfile w]
     puts $fd [$regref portfile]
     close $fd
-    file mtime "${portfile_dir}/Portfile" [$regref date]
+    file mtime $portfile_dir/Portfile [$regref date]
 
     set variations {}
     set minusvariant [lrange [split [$regref negated_variants] -] 1 end]
     set plusvariant [lrange [split [$regref variants] +] 1 end]
     foreach v $plusvariant {
-        lappend variations $v "+"
+        lappend variations $v +
     }
     foreach v $minusvariant {
-        lappend variations $v "-"
+        lappend variations $v -
     }
     lappend options subport $name
-    return [mportopen "file://${portfile_dir}/" $options $variations]
+    return [mportopen file://$portfile_dir/ $options $variations]
 }
 
 # mportclose_installed
@@ -1647,7 +1658,7 @@
     }
     mportclose $mport
     set portfiles_dir [file join ${registry.path} registry portfiles $subport]
-    set portfile [file join $portfiles_dir "${version}_${revision}${portvariants}" Portfile]
+    set portfile [file join $portfiles_dir ${version}_$revision$portvariants Portfile]
     file delete -force $portfile [file dirname $portfile]
     if {[llength [glob -nocomplain -directory $portfiles_dir *]] == 0} {
         file delete -force $portfiles_dir
@@ -1676,12 +1687,12 @@
     foreach category [lsort -increasing -unique [readdir $root]] {
         set pathToCategory [file join $root $category]
         # process the category dirs but not _resources
-        if {[file isdirectory $pathToCategory] && [string index [file tail $pathToCategory] 0] != "_"} {
+        if {[file isdirectory $pathToCategory] && [string index [file tail $pathToCategory] 0] ne "_"} {
             # Iterate on port directories.
             foreach port [lsort -increasing -unique [readdir $pathToCategory]] {
                 set pathToPort [file join $pathToCategory $port]
                 if {[file isdirectory $pathToPort] &&
-                  [file exists [file join $pathToPort "Portfile"]]} {
+                  [file exists [file join $pathToPort Portfile]]} {
                     # Call the function.
                     $func [file join $category $port]
 
@@ -1731,7 +1742,7 @@
         if {$found} {
             return [file join $path $filename]
         } else {
-            return ""
+            return {}
         }
     } else {
         return $found
@@ -1745,21 +1756,21 @@
 proc _mportinstalled {mport} {
     # Check for the presence of the port in the registry
     set workername [ditem_key $mport workername]
-    return [$workername eval registry_exists_for_name \${subport}]
+    return [$workername eval {registry_exists_for_name $subport}]
 }
 
 # Determine if a port is active
 proc _mportactive {mport} {
     set workername [ditem_key $mport workername]
-    if {![catch {set reslist [$workername eval registry_active \${subport}]}] && [llength $reslist] > 0} {
+    if {![catch {set reslist [$workername eval {registry_active $subport}]}] && [llength $reslist] > 0} {
         set i [lindex $reslist 0]
         set name [lindex $i 0]
         set version [lindex $i 1]
         set revision [lindex $i 2]
         set variants [lindex $i 3]
         array set portinfo [mportinfo $mport]
-        if {$name == $portinfo(name) && $version == $portinfo(version)
-            && $revision == $portinfo(revision) && $variants == $portinfo(canonical_active_variants)} {
+        if {$name eq $portinfo(name) && $version eq $portinfo(version)
+            && $revision eq $portinfo(revision) && $variants eq $portinfo(canonical_active_variants)} {
             return 1
         }
     }
@@ -1771,7 +1782,7 @@
     if {[catch {set reslist [registry::active $portname]}]} {
         return 0
     } else {
-        return [expr [llength $reslist] > 0]
+        return [expr {[llength $reslist] > 0}]
     }
 }
 
@@ -1796,10 +1807,10 @@
         set workername [ditem_key $mport workername]
         set type [lindex [split $depspec :] 0]
         switch $type {
-            lib { return [$workername eval _libtest $depspec] }
-            bin { return [$workername eval _bintest $depspec] }
-            path { return [$workername eval _pathtest $depspec] }
-            port { return 0 }
+            lib {return [$workername eval [list _libtest $depspec]]}
+            bin {return [$workername eval [list _bintest $depspec]]}
+            path {return [$workername eval [_pathtest $depspec]]}
+            port {return 0}
             default {return -code error "unknown depspec type: $type"}
         }
         return 0
@@ -1821,7 +1832,7 @@
         [llength $portinfo(conflicts)] > 0} {
         ui_debug "Checking for conflicts against [_mportkey $mport subport]"
         foreach conflictport $portinfo(conflicts) {
-            if {[_mportispresent $mport port:${conflictport}]} {
+            if {[_mportispresent $mport port:$conflictport]} {
                 lappend conflictlist $conflictport
             }
         }
@@ -1829,14 +1840,14 @@
         ui_debug "[_mportkey $mport subport] has no conflicts"
     }
 
-    if {[llength ${conflictlist}] != 0} {
+    if {[llength $conflictlist] != 0} {
         if {[macports::global_option_isset ports_force]} {
-            ui_warn "Force option set; installing $portinfo(name) despite conflicts with: ${conflictlist}"
+            ui_warn "Force option set; installing $portinfo(name) despite conflicts with: $conflictlist"
         } else {
             if {![macports::ui_isset ports_debug]} {
-                ui_msg ""
+                ui_msg {}
             }
-            return -code error "Can't install $portinfo(name) because conflicting ports are installed: ${conflictlist}"
+            return -code error "Can't install $portinfo(name) because conflicting ports are installed: $conflictlist"
         }
     }
 }
@@ -1849,11 +1860,11 @@
     # xxx: set the work path?
     set workername [ditem_key $mport workername]
     $workername eval validate_macportsuser
-    if {![catch {$workername eval check_variants $target} result] && $result == 0 &&
+    if {![catch {$workername eval [list check_variants $target]} result] && $result == 0 &&
         ![catch {$workername eval check_supported_archs} result] && $result == 0 &&
-        ![catch {$workername eval eval_targets $target} result] && $result == 0} {
+        ![catch {$workername eval [list eval_targets $target]} result] && $result == 0} {
         # If auto-clean mode, clean-up after dependency install
-        if {[string equal ${macports::portautoclean} "yes"]} {
+        if {$macports::portautoclean eq "yes"]} {
             # Make sure we are back in the port path before clean
             # otherwise if the current directory had been changed to
             # inside the port,  the next port may fail when trying to
@@ -1871,7 +1882,7 @@
         # An error occurred.
         global ::logenabled ::debuglogname
         ui_error "Failed to install $portname"
-        ui_debug "$::errorInfo"
+        ui_debug $::errorInfo
         if {[info exists ::logenabled] && $::logenabled && [info exists ::debuglogname]} {
             ui_notice "Please see the log file for port $portname for details:\n    $::debuglogname"
         }
@@ -1888,11 +1899,11 @@
     # check for existence of macportsuser and use fallback if necessary
     $workername eval validate_macportsuser
     # check variants
-    if {[$workername eval check_variants $target] != 0} {
+    if {[$workername eval [list check_variants $target]] != 0} {
         return 1
     }
     set portname [_mportkey $mport subport]
-    if {$target != "clean"} {
+    if {$target ne "clean"} {
         macports::push_log $mport
     }
 
@@ -1915,9 +1926,9 @@
     if {[macports::_target_needs_deps $target] && [macports::_mport_has_deptypes $mport [macports::_deptypes_for_target $target $workername]]} {
         registry::exclusive_lock
         # see if we actually need to build this port
-        if {($target != "activate" && $target != "install") ||
-            ![$workername eval registry_exists \$subport \$version \$revision \$portvariants]} {
-    
+        if {($target ne "activate" && $target ne "install") ||
+            ![$workername eval {registry_exists $subport $version $revision $portvariants}]} {
+
             # upgrade dependencies that are already installed
             if {![macports::global_option_isset ports_nodeps]} {
                 macports::_upgrade_mport_deps $mport $target
@@ -1927,13 +1938,13 @@
         ui_msg -nonewline "$macports::ui_prefix Computing dependencies for [_mportkey $mport subport]"
         if {[macports::ui_isset ports_debug]} {
             # play nice with debug messages
-            ui_msg ""
+            ui_msg {}
         }
         if {[mportdepends $mport $target] != 0} {
             return 1
         }
         if {![macports::ui_isset ports_debug]} {
-            ui_msg ""
+            ui_msg {}
         }
 
         # Select out the dependents along the critical path,
@@ -1941,7 +1952,7 @@
         set dlist [dlist_append_dependents $macports::open_mports $mport {}]
 
         dlist_delete dlist $mport
-        
+
         # print the dep list
         if {[llength $dlist] > 0} {
             set depstring "$macports::ui_prefix Dependencies to be installed:"
@@ -1952,11 +1963,11 @@
         }
 
         # install them
-        set result [dlist_eval $dlist _mportactive [list _mportexec "activate"]]
+        set result [dlist_eval $dlist _mportactive [list _mportexec activate]]
 
         registry::exclusive_unlock
 
-        if {$result != {}} {
+        if {$result ne {}} {
             set errstring "The following dependencies were not installed:"
             foreach ditem $result {
                 append errstring " [ditem_key $ditem provides]"
@@ -1974,19 +1985,19 @@
         }
     } else {
         # No dependencies, but we still need to check for conflicts.
-        if {$target == "" || $target == "install" || $target == "activate"} {
+        if {$target eq {} || $target eq "install" || $target eq "activate"} {
             _mporterrorifconflictsinstalled $mport
         }
     }
 
     set clean 0
-    if {[string equal ${macports::portautoclean} "yes"] && ([string equal $target "install"] || [string equal $target "activate"])} {
+    if {$macports::portautoclean eq "yes"] && ([string equal $target "install"] || [string equal $target "activate"])} {
         # If we're doing an install, check if we should clean after
         set clean 1
     }
 
     # Build this port with the specified target
-    set result [$workername eval eval_targets $target]
+    set result [$workername eval [list eval_targets $target]]
 
     # If auto-clean mode and successful install, clean-up after install
     if {$result == 0 && $clean == 1} {
@@ -1995,7 +2006,7 @@
         catch {cd $portpath}
         $workername eval eval_targets clean
     }
-    
+
     global ::logenabled ::debuglogname
     if {[info exists ::logenabled] && $::logenabled && [info exists ::debuglogname]} {
         if {$result != 0} {
@@ -2025,14 +2036,14 @@
             continue
         }
         foreach depspec $portinfo($deptype) {
-            set dep_portname [$workername eval _get_dep_port $depspec]
-            if {$dep_portname != "" && ![info exists depscache(port:$dep_portname)] && [$test $dep_portname]} {
+            set dep_portname [$workername eval [list _get_dep_port $depspec]]
+            if {$dep_portname ne {} && ![info exists depscache(port:$dep_portname)] && [$test $dep_portname]} {
                 set variants {}
-    
+
                 # check that the dep has the required archs
                 set active_archs [_get_registry_archs $dep_portname]
-                if {$deptype != "depends_fetch" && $deptype != "depends_extract"
-                    && $active_archs != "" && $active_archs != "noarch" && $required_archs != "noarch"
+                if {$deptype ne "depends_fetch" && $deptype ne "depends_extract"
+                    && $active_archs ne {} && $active_archs ne "noarch" && $required_archs ne "noarch"
                     && [lsearch -exact $depends_skip_archcheck $dep_portname] == -1} {
                     set missing {}
                     foreach arch $required_archs {
@@ -2084,8 +2095,8 @@
                         }
                     }
                 }
-    
-                set status [macports::upgrade $dep_portname "port:$dep_portname" $variants $options depscache]
+
+                set status [macports::upgrade $dep_portname port:$dep_portname $variants $options depscache]
                 # status 2 means the port was not found in the index
                 if {$status != 0 && $status != 2 && ![macports::ui_isset ports_processall]} {
                     return -code error "upgrade $dep_portname failed"
@@ -2102,7 +2113,7 @@
     set regref [registry::open_entry [lindex $i 0] [lindex $i 1] [lindex $i 2] [lindex $i 3] [lindex $i 5]]
     set archs [registry::property_retrieve $regref archs]
     if {$archs == 0} {
-        set archs ""
+        set archs {}
     }
     return $archs
 }
@@ -2126,7 +2137,7 @@
 #
 # @param url source URL to check
 # @return a list containing filename and extension or an empty list
-proc _source_is_snapshot {url {filename ""} {extension ""}} {
+proc _source_is_snapshot {url {filename {}} {extension {}}} {
     upvar $filename myfilename
     upvar $extension myextension
 
@@ -2140,14 +2151,14 @@
     return 0
 }
 
-proc macports::getportbuildpath {id {portname ""}} {
+proc macports::getportbuildpath {id {portname {}}} {
     global macports::portdbpath
     regsub {://} $id {.} port_path
     regsub -all {/} $port_path {_} port_path
     return [file join $portdbpath build $port_path $portname]
 }
 
-proc macports::getportlogpath {id {portname ""}} {
+proc macports::getportlogpath {id {portname {}}} {
     global macports::portdbpath
     regsub {://} $id {.} port_path
     regsub -all {/} $port_path {_} port_path
@@ -2158,13 +2169,13 @@
     return [file join $portbuildpath work]
 }
 
-proc macports::getportworkpath_from_portdir {portpath {portname ""}} {
+proc macports::getportworkpath_from_portdir {portpath {portname {}}} {
     return [macports::getportworkpath_from_buildpath [macports::getportbuildpath $portpath $portname]]
 }
 
 proc macports::getindex {source} {
     # Special case file:// sources
-    if {[macports::getprotocol $source] == "file"} {
+    if {[macports::getprotocol $source] eq "file"} {
         return [file join [macports::getportdir $source] PortIndex]
     }
 
@@ -2195,12 +2206,12 @@
         switch -regexp -- [macports::getprotocol $source] {
             {^file$} {
                 set portdir [macports::getportdir $source]
-                set svn_cmd ""
+                set svn_cmd {}
                 catch {set svn_cmd [macports::findBinary svn]}
-                set git_cmd ""
+                set git_cmd {}
                 catch {set git_cmd [macports::findBinary git]}
-                if {$svn_cmd != "" && ([file exists $portdir/.svn] || ![catch {exec $svn_cmd info $portdir > /dev/null 2>@1}])} {
-                    set svn_commandline "$svn_cmd update --non-interactive ${portdir}"
+                if {$svn_cmd ne {} && ([file exists $portdir/.svn] || ![catch {exec $svn_cmd info $portdir > /dev/null 2>@1}])} {
+                    set svn_commandline "$svn_cmd update --non-interactive $portdir"
                     ui_debug $svn_commandline
                     if {
                         [catch {
@@ -2218,12 +2229,12 @@
                             }
                         }]
                     } {
-                        ui_debug "$::errorInfo"
+                        ui_debug $::errorInfo
                         ui_error "Synchronization of the local ports tree failed doing an svn update"
                         incr numfailed
                         continue
                     }
-                } elseif {$git_cmd != "" && [file exists $portdir/.git]} {
+                } elseif {$git_cmd ne {} && [file exists $portdir/.git]} {
                     set git_commandline "pushd $portdir ; $git_cmd pull --rebase ; popd"
                     ui_debug $git_commandline
                     if {
@@ -2242,7 +2253,7 @@
                             }
                         }]
                     } {
-                        ui_debug "$::errorInfo"
+                        ui_debug $::errorInfo
                         ui_error "Synchronization of the local ports tree failed doing a git pull --rebase"
                         incr numfailed
                         continue
@@ -2261,19 +2272,19 @@
                 file mkdir $destdir
 
                 if {$is_tarball} {
-                    set exclude_option ""
+                    set exclude_option {}
                     # need to do a few things before replacing the ports tree in this case
                     set destdir [file dirname $destdir]
                 } else {
                     # Keep rsync happy with a trailing slash
-                    if {[string index $source end] != "/"} {
-                        append source "/"
+                    if {[string index $source end] ne "/"} {
+                        append source /
                     }
                     # don't sync PortIndex yet; we grab the platform specific one afterwards
-                    set exclude_option "'--exclude=/PortIndex*'"
+                    set exclude_option '--exclude=/PortIndex*'
                 }
                 # Do rsync fetch
-                set rsync_commandline "${macports::autoconf::rsync_path} ${rsync_options} ${exclude_option} ${source} ${destdir}"
+                set rsync_commandline "$macports::autoconf::rsync_path $rsync_options $exclude_option $source $destdir"
                 ui_debug $rsync_commandline
                 if {[catch {system $rsync_commandline}]} {
                     ui_error "Synchronization of the local ports tree failed doing rsync"
@@ -2284,18 +2295,18 @@
                 if {$is_tarball} {
                     # verify signature for tarball
                     global macports::archivefetch_pubkeys
-                    set rsync_commandline "${macports::autoconf::rsync_path} ${rsync_options} ${exclude_option} ${source}.rmd160 ${destdir}"
+                    set rsync_commandline "$macports::autoconf::rsync_path $rsync_options $exclude_option $source.rmd160 $destdir"
                     ui_debug $rsync_commandline
                     if {[catch {system $rsync_commandline}]} {
                         ui_error "Synchronization of the ports tree signature failed doing rsync"
                         incr numfailed
                         continue
                     }
-                    set tarball "${destdir}/[file tail $source]"
-                    set signature "${tarball}.rmd160"
+                    set tarball $destdir/[file tail $source]
+                    set signature $tarball.rmd160
                     set openssl [macports::findBinary openssl $macports::autoconf::openssl_path]
                     set verified 0
-                    foreach pubkey ${macports::archivefetch_pubkeys} {
+                    foreach pubkey $macports::archivefetch_pubkeys {
                         if {![catch {exec $openssl dgst -ripemd160 -verify $pubkey -signature $signature $tarball} result]} {
                             set verified 1
                             ui_debug "successful verification with key $pubkey"
@@ -2313,8 +2324,8 @@
 
                     # extract tarball and move into place
                     set tar [macports::findBinary tar $macports::autoconf::tar_path]
-                    file mkdir ${destdir}/tmp
-                    set tar_cmd "$tar -C ${destdir}/tmp -xf ${tarball}"
+                    file mkdir $destdir/tmp
+                    set tar_cmd "$tar -C $destdir/tmp -xf $tarball"
                     ui_debug $tar_cmd
                     if {[catch {system $tar_cmd}]} {
                         ui_error "Failed to extract ports tree from tarball!"
@@ -2323,29 +2334,29 @@
                     }
                     # save the local PortIndex data
                     if {[file isfile $indexfile]} {
-                        file copy -force $indexfile ${destdir}/
-                        file rename -force $indexfile ${destdir}/tmp/ports/
-                        if {[file isfile ${indexfile}.quick]} {
-                            file rename -force ${indexfile}.quick ${destdir}/tmp/ports/
+                        file copy -force $indexfile $destdir/
+                        file rename -force $indexfile $destdir/tmp/ports/
+                        if {[file isfile $indexfile.quick]} {
+                            file rename -force $indexfile.quick $destdir/tmp/ports/
                         }
                     }
-                    file delete -force ${destdir}/ports
-                    file rename ${destdir}/tmp/ports ${destdir}/ports
-                    file delete -force ${destdir}/tmp
+                    file delete -force $destdir/ports
+                    file rename $destdir/tmp/ports $destdir/ports
+                    file delete -force $destdir/tmp
                 }
 
                 set needs_portindex 1
                 # now sync the index if the local file is missing or older than a day
-                if {![file isfile $indexfile] || [expr [clock seconds] - [file mtime $indexfile]] > 86400
+                if {![file isfile $indexfile] || [clock seconds] - [file mtime $indexfile] > 86400
                       || [info exists options(no_reindex)]} {
                     if {$is_tarball} {
                         # chop ports.tar off the end
                         set index_source [string range $source 0 end-[string length [file tail $source]]]
                     } else {
-                        set index_source $source 
+                        set index_source $source
                     }
-                    set remote_indexfile "${index_source}PortIndex_${macports::os_platform}_${macports::os_major}_${macports::os_arch}/PortIndex"
-                    set rsync_commandline "${macports::autoconf::rsync_path} ${rsync_options} $remote_indexfile ${destdir}"
+                    set remote_indexfile "${index_source}PortIndex_${macports::os_platform}_${macports::os_major}_$macports::os_arch/PortIndex"
+                    set rsync_commandline "$macports::autoconf::rsync_path $rsync_options $remote_indexfile $destdir"
                     ui_debug $rsync_commandline
                     if {[catch {system $rsync_commandline}]} {
                         ui_debug "Synchronization of the PortIndex failed doing rsync"
@@ -2356,11 +2367,11 @@
                             set ok 0
                             set needs_portindex 1
                             # verify signature for PortIndex
-                            set rsync_commandline "${macports::autoconf::rsync_path} ${rsync_options} ${remote_indexfile}.rmd160 ${destdir}"
+                            set rsync_commandline "$macports::autoconf::rsync_path $rsync_options $remote_indexfile.rmd160 $destdir"
                             ui_debug $rsync_commandline
                             if {![catch {system $rsync_commandline}]} {
-                                foreach pubkey ${macports::archivefetch_pubkeys} {
-                                    if {![catch {exec $openssl dgst -ripemd160 -verify $pubkey -signature ${destdir}/PortIndex.rmd160 ${destdir}/PortIndex} result]} {
+                                foreach pubkey $macports::archivefetch_pubkeys {
+                                    if {![catch {exec $openssl dgst -ripemd160 -verify $pubkey -signature $destdir/PortIndex.rmd160 $destdir/PortIndex} result]} {
                                         set ok 1
                                         set needs_portindex 0
                                         ui_debug "successful verification with key $pubkey"
@@ -2372,7 +2383,7 @@
                                 }
                                 if {$ok} {
                                     # move PortIndex into place
-                                    file rename -force ${destdir}/PortIndex ${destdir}/ports/
+                                    file rename -force $destdir/PortIndex $destdir/ports/
                                 }
                             }
                         }
@@ -2400,7 +2411,7 @@
                         }
                     }
 
-                    if {(![info exists options(ports_force)] || $options(ports_force) != "yes") && $updated <= 0} {
+                    if {(![info exists options(ports_force)] || $options(ports_force) ne "yes") && $updated <= 0} {
                         ui_info "No updates for $source"
                         continue
                     }
@@ -2408,11 +2419,11 @@
                     file mkdir $destdir
 
                     set verboseflag {}
-                    if {$macports::portverbose == "yes"} {
-                        set verboseflag "-v"
+                    if {$macports::portverbose eq "yes"} {
+                        set verboseflag -v
                     }
 
-                    if {[catch {eval curl fetch $verboseflag {$source} {$tarpath}} error]} {
+                    if {[catch {eval [list curl fetch $verboseflag $source $tarpath]} error]} {
                         ui_error "Fetching $source failed ($error)"
                         incr numfailed
                         continue
@@ -2421,15 +2432,15 @@
                     set extflag {}
                     switch $extension {
                         {tar.gz} {
-                            set extflag "-z"
+                            set extflag -z
                         }
                         {tar.bz2} {
-                            set extflag "-j"
+                            set extflag -j
                         }
                     }
 
                     set tar [macports::findBinary tar $macports::autoconf::tar_path]
-                    if { [catch { system "cd $destdir/.. && $tar ${verboseflag} ${extflag} -xf $filename" } error] } {
+                    if { [catch {system "cd $destdir/.. && $tar $verboseflag $extflag -xf $filename"} error]} {
                         ui_error "Extracting $source failed ($error)"
                         incr numfailed
                         continue
@@ -2439,9 +2450,9 @@
                         ui_warn "Setting world read permissions on parts of the ports tree failed, need root?"
                     }
 
-                    set platindex "PortIndex_${macports::os_platform}_${macports::os_major}_${macports::os_arch}/PortIndex"
-                    if {[file isfile ${destdir}/${platindex}] && [file isfile ${destdir}/${platindex}.quick]} {
-                        file rename -force "${destdir}/${platindex}" "${destdir}/${platindex}.quick" $destdir
+                    set platindex "PortIndex_${macports::os_platform}_${macports::os_major}_$macports::os_arch/PortIndex"
+                    if {[file isfile $destdir/$platindex] && [file isfile $destdir/$platindex.quick]} {
+                        file rename -force $destdir/$platindex $destdir/$platindex.quick $destdir
                     }
 
                     file delete $tarpath
@@ -2449,21 +2460,21 @@
                     # sync just a PortIndex file
                     set indexfile [macports::getindex $source]
                     file mkdir [file dirname $indexfile]
-                    curl fetch ${source}/PortIndex $indexfile
-                    curl fetch ${source}/PortIndex.quick ${indexfile}.quick
+                    curl fetch $source/PortIndex $indexfile
+                    curl fetch $source/PortIndex.quick $indexfile.quick
                 }
             }
             default {
                 ui_warn "Unknown synchronization protocol for $source"
             }
         }
-        
+
         if {$needs_portindex} {
             set any_needed_portindex 1
             if {![info exists options(no_reindex)]} {
                 global macports::prefix
                 set indexdir [file dirname [macports::getindex $source]]
-                if {[catch {system "${macports::prefix}/bin/portindex $indexdir"}]} {
+                if {[catch {system "$macports::prefix/bin/portindex $indexdir"}]} {
                     ui_error "updating PortIndex for $source failed"
                 }
             }
@@ -2483,15 +2494,15 @@
 proc mportsearch {pattern {case_sensitive yes} {matchstyle regexp} {field name}} {
     global macports::portdbpath macports::sources
     set matches [list]
-    set easy [expr { $field == "name" }]
+    set easy [expr {$field eq "name"}]
 
     set found 0
     foreach source $sources {
         set source [lindex $source 0]
         set protocol [macports::getprotocol $source]
-        if {$protocol == "mports"} {
+        if {$protocol eq "mports"} {
             set res [macports::index::search $macports::portdbpath $source [list name $pattern]]
-            eval lappend matches $res
+            lappend matches {*}$res
         } else {
             if {[catch {set fd [open [macports::getindex $source] r]} result]} {
                 ui_warn "Can't open index file for source: $source"
@@ -2514,14 +2525,20 @@
 
                         switch $matchstyle {
                             exact {
-                                set matchres [expr 0 == ( {$case_sensitive == "yes"} ? [string compare $pattern $target] : [string compare -nocase $pattern $target] )]
+                                set matchres [expr {0 eq ({$case_sensitive eq "yes"} ?
+                                    [string compare $pattern $target] :
+                                    [string compare -nocase $pattern $target])}]
                             }
                             glob {
-                                set matchres [expr {$case_sensitive == "yes"} ? [string match $pattern $target] : [string match -nocase $pattern $target]]
+                                set matchres [expr {$case_sensitive eq "yes" ?
+                                    [string match $pattern $target] :
+                                    [string match -nocase $pattern $target]}]
                             }
                             regexp -
                             default {
-                                set matchres [expr {$case_sensitive == "yes"} ? [regexp -- $pattern $target] : [regexp -nocase -- $pattern $target]]
+                                set matchres [expr {$case_sensitive eq "yes" ?
+                                    [regexp -- $pattern $target] :
+                                    [regexp -nocase -- $pattern $target]}]
                             }
                         }
 
@@ -2532,14 +2549,14 @@
                             switch $protocol {
                                 rsync {
                                     # Rsync files are local
-                                    set source_url "file://[macports::getsourcepath $source]"
+                                    set source_url file://[macports::getsourcepath $source]
                                 }
                                 https -
                                 http -
                                 ftp {
                                     if {[_source_is_snapshot $source filename extension]} {
                                         # daily snapshot tarball
-                                        set source_url "file://[macports::getsourcepath $source]"
+                                        set source_url file://[macports::getsourcepath $source]
                                     } else {
                                         # default action
                                         set source_url $source
@@ -2550,9 +2567,9 @@
                                 }
                             }
                             if {[info exists portinfo(portarchive)]} {
-                                set porturl ${source_url}/$portinfo(portarchive)
+                                set porturl $source_url/$portinfo(portarchive)
                             } elseif {[info exists portinfo(portdir)]} {
-                                set porturl ${source_url}/$portinfo(portdir)
+                                set porturl $source_url/$portinfo(portdir)
                             }
                             if {[info exists porturl]} {
                                 lappend line porturl $porturl
@@ -2564,7 +2581,7 @@
                             lappend matches $line
                         }
                     }
-                } catch {*} {
+                } catch * {
                     ui_warn "It looks like your PortIndex file for $source may be corrupt."
                     throw
                 } finally {
@@ -2593,7 +2610,7 @@
     foreach source $sources {
         set source [lindex $source 0]
         set protocol [macports::getprotocol $source]
-        if {$protocol != "mports"} {
+        if {$protocol ne "mports"} {
             global macports::quick_index
             if {![info exists quick_index($sourceno,[string tolower $name])]} {
                 incr sourceno 1
@@ -2618,13 +2635,13 @@
 
                     switch $protocol {
                         rsync {
-                            set source_url "file://[macports::getsourcepath $source]"
+                            set source_url file://[macports::getsourcepath $source]
                         }
                         https -
                         http -
                         ftp {
                             if {[_source_is_snapshot $source filename extension]} {
-                                set source_url "file://[macports::getsourcepath $source]"
+                                set source_url file://[macports::getsourcepath $source]
                              } else {
                                 set source_url $source
                              }
@@ -2634,9 +2651,9 @@
                         }
                     }
                     if {[info exists portinfo(portarchive)]} {
-                        set porturl ${source_url}/$portinfo(portarchive)
+                        set porturl $source_url/$portinfo(portarchive)
                     } elseif {[info exists portinfo(portdir)]} {
-                        set porturl ${source_url}/$portinfo(portdir)
+                        set porturl $source_url/$portinfo(portdir)
                     }
                     if {[info exists porturl]} {
                         lappend line porturl $porturl
@@ -2645,7 +2662,7 @@
                     lappend matches $line
                     close $fd
                     set fd -1
-                } catch {*} {
+                } catch * {
                     ui_warn "It looks like your PortIndex file for $source may be corrupt."
                 } finally {
                     if {$fd != -1} {
@@ -2659,7 +2676,7 @@
         } else {
             set res [macports::index::search $macports::portdbpath $source [list name $name]]
             if {[llength $res] > 0} {
-                eval lappend matches $res
+                lappend matches {*}$res
                 break
             }
         }
@@ -2677,7 +2694,7 @@
     foreach source $sources {
         set source [lindex $source 0]
         set protocol [macports::getprotocol $source]
-        if {$protocol != "mports"} {
+        if {$protocol ne "mports"} {
             if {![catch {set fd [open [macports::getindex $source] r]} result]} {
                 try {
                     incr found 1
@@ -2691,13 +2708,13 @@
 
                         switch $protocol {
                             rsync {
-                                set source_url "file://[macports::getsourcepath $source]"
+                                set source_url file://[macports::getsourcepath $source]
                             }
                             https -
                             http -
                             ftp {
                                 if {[_source_is_snapshot $source filename extension]} {
-                                    set source_url "file://[macports::getsourcepath $source]"
+                                    set source_url file://[macports::getsourcepath $source]
                                 } else {
                                     set source_url $source
                                 }
@@ -2707,16 +2724,16 @@
                             }
                         }
                         if {[info exists portinfo(portdir)]} {
-                            set porturl ${source_url}/$portinfo(portdir)
+                            set porturl $source_url/$portinfo(portdir)
                         } elseif {[info exists portinfo(portarchive)]} {
-                            set porturl ${source_url}/$portinfo(portarchive)
+                            set porturl $source_url/$portinfo(portarchive)
                         }
                         if {[info exists porturl]} {
                             lappend line porturl $porturl
                         }
                         lappend matches $name $line
                     }
-                } catch {*} {
+                } catch * {
                     ui_warn "It looks like your PortIndex file for $source may be corrupt."
                     throw
                 } finally {
@@ -2727,7 +2744,7 @@
             }
         } else {
             set res [macports::index::search $macports::portdbpath $source [list name .*]]
-            eval lappend matches $res
+            lappend matches {*}$res
         }
     }
     if {!$found} {
@@ -2751,20 +2768,20 @@
         # chop off any tags
         set source [lindex $source 0]
         set index [macports::getindex $source]
-        if {![file exists ${index}]} {
+        if {![file exists $index]} {
             incr sourceno
             continue
         }
-        if {![file exists ${index}.quick]} {
+        if {![file exists $index.quick]} {
             ui_warn "No quick index file found, attempting to generate one for source: $source"
-            if {[catch {set quicklist [mports_generate_quickindex ${index}]}]} {
+            if {[catch {set quicklist [mports_generate_quickindex $index]}]} {
                 incr sourceno
                 continue
             }
         }
         # only need to read the quick index file if we didn't just update it
         if {![info exists quicklist]} {
-            if {[catch {set fd [open ${index}.quick r]} result]} {
+            if {[catch {set fd [open $index.quick r]} result]} {
                 ui_warn "Can't open quick index file for source: $source"
                 incr sourceno
                 continue
@@ -2773,7 +2790,7 @@
                 close $fd
             }
         }
-        foreach entry [split $quicklist "\n"] {
+        foreach entry [split $quicklist \n] {
             set quick_index($sourceno,[lindex $entry 0]) [lindex $entry 1]
         }
         incr sourceno 1
@@ -2784,26 +2801,26 @@
 }
 
 proc mports_generate_quickindex {index} {
-    if {[catch {set indexfd [open ${index} r]} result] || [catch {set quickfd [open ${index}.quick w]} result]} {
+    if {[catch {set indexfd [open $index r]} result] || [catch {set quickfd [open $index.quick w]} result]} {
         ui_warn "Can't open index file: $index"
         return -code error
     } else {
         try {
             set offset [tell $indexfd]
-            set quicklist ""
+            set quicklist {}
             while {[gets $indexfd line] >= 0} {
                 if {[llength $line] != 2} {
                     continue
                 }
                 set name [lindex $line 0]
-                append quicklist "[string tolower $name] ${offset}\n"
+                append quicklist "[string tolower $name] $offset\n"
 
                 set len [lindex $line 1]
                 read $indexfd $len
                 set offset [tell $indexfd]
             }
             puts -nonewline $quickfd $quicklist
-        } catch {*} {
+        } catch * {
             ui_warn "It looks like your PortIndex file $index may be corrupt."
             throw
         } finally {
@@ -2849,7 +2866,8 @@
 
 proc _mportkey {mport key} {
     set workername [ditem_key $mport workername]
-    return [$workername eval "return \$${key}"]
+	set code {return $key}
+    return [$workername eval [string map [list \$key [list $key]] {return $key}]] 
 }
 
 # mportdepends builds the list of mports which the given port depends on.
@@ -2867,7 +2885,7 @@
 #                  dependencies ports.
 # accDeps -> accumulator for recursive calls
 # return 0 if everything was ok, an non zero integer otherwise.
-proc mportdepends {mport {target ""} {recurseDeps 1} {skipSatisfied 1} {accDeps 0}} {
+proc mportdepends {mport {target {}} {recurseDeps 1} {skipSatisfied 1} {accDeps 0}} {
 
     array set portinfo [mportinfo $mport]
     if {$accDeps} {
@@ -2878,11 +2896,11 @@
 
     # progress indicator
     if {![macports::ui_isset ports_debug]} {
-        ui_info -nonewline "."
+        ui_info -nonewline .
         flush stdout
     }
-    
-    if {$target == "" || $target == "install" || $target == "activate"} {
+
+    if {$target eq {} || $target eq "install" || $target eq "activate"} {
         _mporterrorifconflictsinstalled $mport
     }
 
@@ -2909,18 +2927,20 @@
         }
         foreach depspec $portinfo($deptype) {
             # get the portname that satisfies the depspec
-            set dep_portname [$workername eval _get_dep_port $depspec]
+            set dep_portname [$workername eval [list _get_dep_port $depspec]]
             # skip port/archs combos we've already seen, and ones with the same port but less archs than ones we've seen (or noarch)
-            set seenkey "${dep_portname},[join $required_archs ,]"
+            set seenkey $dep_portname,[join $required_archs ,]
             set seen 0
             if {[info exists port_seen($seenkey)]} {
                 set seen 1
             } else {
-                set prev_seenkeys [array names port_seen ${dep_portname},*]
+                set prev_seenkeys [array names port_seen $dep_portname,*]
                 set nrequired [llength $required_archs]
                 foreach key $prev_seenkeys {
                     set key_archs [lrange [split $key ,] 1 end]
-                    if {$key_archs == "noarch" || $required_archs == "noarch" || [llength $key_archs] > $nrequired} {
+                    if {$key_archs eq "noarch" || $required_archs eq "noarch"
+                        || [llength $key_archs] > $nrequired} {
+
                         set seen 1
                         set seenkey $key
                         break
@@ -2934,31 +2954,35 @@
                 }
                 continue
             }
-            
+
             # Is that dependency satisfied or this port installed?
             # If we don't skip or if it is not, add it to the list.
             set present [_mportispresent $mport $depspec]
 
-            if {!$skipSatisfied && $dep_portname == ""} {
+            if {!$skipSatisfied && $dep_portname eq {}} {
                 set dep_portname [lindex [split $depspec :] end]
             }
 
             set check_archs 0
-            if {$dep_portname != "" && $deptype != "depends_fetch" && $deptype != "depends_extract" && [lsearch -exact $depends_skip_archcheck $dep_portname] == -1} {
+            if {$dep_portname ne {} && $deptype ne "depends_fetch" && $deptype ne "depends_extract"
+                && [lsearch -exact $depends_skip_archcheck $dep_portname] == -1} {
+
                 set check_archs 1
             }
 
             # need to open the portfile even if the dep is installed if it doesn't have the right archs
             set parse 0
-            if {!$skipSatisfied || !$present || ($check_archs && ![macports::_active_supports_archs $dep_portname $required_archs])} {
+            if {!$skipSatisfied || !$present || ($check_archs
+                && ![macports::_active_supports_archs $dep_portname $required_archs])} {
+
                 set parse 1
             }
             if {$parse} {
                 # Find the porturl
                 if {[catch {set res [mportlookup $dep_portname]} error]} {
                     global errorInfo
-                    ui_msg ""
-                    ui_debug "$errorInfo"
+                    ui_msg {}
+                    ui_debug $errorInfo
                     ui_error "Internal error: port lookup failed: $error"
                     return 1
                 }
@@ -2967,7 +2991,7 @@
                 array set dep_portinfo [lindex $res 1]
                 if {![info exists dep_portinfo(porturl)]} {
                     if {![macports::ui_isset ports_debug]} {
-                        ui_msg ""
+                        ui_msg {}
                     }
                     ui_error "Dependency '$dep_portname' not found."
                     return 1
@@ -2981,7 +3005,7 @@
                 # because mportexec only closes each open mport once.
                 set depport [dlist_match_multi $macports::open_mports [list porturl $dep_portinfo(porturl) options $dep_options]]
 
-                if {$depport == {}} {
+                if {$depport eq {}} {
                     # We haven't opened this one yet.
                     set depport [mportopen $dep_portinfo(porturl) $dep_options $variations]
                 }
@@ -2993,14 +3017,14 @@
 
                 set supported_archs [_mportkey $depport supported_archs]
                 array unset variation_array
-                array set variation_array [[ditem_key $depport workername] eval "array get variations"]
+                array set variation_array [[ditem_key $depport workername] eval array get variations]
                 mportclose $depport
                 set arch_mismatch 1
                 set has_universal 0
                 if {[info exists dep_portinfo(variants)] && [lsearch -exact $dep_portinfo(variants) universal] != -1} {
                     # a universal variant is offered
                     set has_universal 1
-                    if {![info exists variation_array(universal)] || $variation_array(universal) != "+"} {
+                    if {![info exists variation_array(universal)] || $variation_array(universal) ne "+"} {
                         set variation_array(universal) +
                         # try again with +universal
                         set depport [mportopen $dep_portinfo(porturl) $dep_options [array get variation_array]]
@@ -3022,13 +3046,13 @@
                 }
 
                 # Append the sub-port's provides to the port's requirements list.
-                set depport_provides "[ditem_key $depport provides]"
+                set depport_provides [ditem_key $depport provides]
                 ditem_append_unique $mport requires $depport_provides
                 # record actual archs we ended up getting
-                set port_seen(${dep_portname},[join [macports::_mport_archs $depport] ,]) $depport_provides
-            } elseif {$present && $dep_portname != ""} {
+                set port_seen($dep_portname,[join [macports::_mport_archs $depport] ,]) $depport_provides
+            } elseif {$present && $dep_portname ne {}} {
                 # record actual installed archs
-                set port_seen(${dep_portname},[join [macports::_active_archs $dep_portname] ,]) 0
+                set port_seen($dep_portname,[join [macports::_active_archs $dep_portname] ,]) 0
             }
         }
     }
@@ -3037,7 +3061,7 @@
     if {$recurseDeps} {
         foreach depport $depPorts {
             # Sub ports should be installed (all dependencies must be satisfied).
-            set res [mportdepends $depport "" $recurseDeps $skipSatisfied 1]
+            set res [mportdepends $depport {} $recurseDeps $skipSatisfied 1]
             if {$res != 0} {
                 return $res
             }
@@ -3049,11 +3073,11 @@
 
 # check if the given mport can support dependents with the given archs
 proc macports::_mport_supports_archs {mport required_archs} {
-    if {$required_archs == "noarch"} {
+    if {$required_archs eq "noarch"} {
         return 1
     }
     set provided_archs [_mport_archs $mport]
-    if {$provided_archs == "noarch"} {
+    if {$provided_archs eq "noarch"} {
         return 1
     }
     foreach arch $required_archs {
@@ -3072,14 +3096,14 @@
 
 # check if the active version of a port supports the given archs
 proc macports::_active_supports_archs {portname required_archs} {
-    if {$required_archs == "noarch"} {
+    if {$required_archs eq "noarch"} {
         return 1
     }
     if {[catch {registry::active $portname}]} {
         return 0
     }
     set provided_archs [_active_archs $portname]
-    if {$provided_archs == "noarch" || $provided_archs == "" || $provided_archs == 0} {
+    if {$provided_archs eq "noarch" || $provided_archs eq {} || $provided_archs == 0} {
         return 1
     }
     foreach arch $required_archs {
@@ -3093,7 +3117,7 @@
 # get the archs for a given active port
 proc macports::_active_archs {portname} {
     if {[catch {set ilist [registry::active $portname]}]} {
-        return ""
+        return {}
     }
     set i [lindex $ilist 0]
     set regref [registry::open_entry $portname [lindex $i 1] [lindex $i 2] [lindex $i 3] [lindex $i 5]]
@@ -3104,10 +3128,10 @@
 proc macports::_explain_arch_mismatch {port dep required_archs supported_archs has_universal} {
     global macports::universal_archs
     if {![macports::ui_isset ports_debug]} {
-        ui_msg ""
+        ui_msg {}
     }
     ui_error "Cannot install $port for the arch(s) '$required_archs' because"
-    if {$supported_archs != ""} {
+    if {$supported_archs ne {}} {
         foreach arch $required_archs {
             if {[lsearch -exact $supported_archs $arch] == -1} {
                 ui_error "its dependency $dep only supports the arch(s) '$supported_archs'."
@@ -3134,7 +3158,7 @@
 proc macports::_mport_has_deptypes {mport deptypes} {
     array set portinfo [mportinfo $mport]
     foreach type $deptypes {
-        if {[info exists portinfo($type)] && $portinfo($type) != ""} {
+        if {[info exists portinfo($type)] && $portinfo($type) ne {}} {
             return 1
         }
     }
@@ -3170,14 +3194,14 @@
 proc macports::_deptypes_for_target {target workername} {
     switch $target {
         fetch       -
-        checksum    { return "depends_fetch" }
+        checksum    {return depends_fetch}
         extract     -
-        patch       { return "depends_fetch depends_extract" }
+        patch       {return [list depends_fetch depends_extract]}
         configure   -
-        build       { return "depends_fetch depends_extract depends_build depends_lib" }
+        build       {return [list depends_fetch depends_extract depends_build depends_lib]}
         test        -
         srpm        -
-        destroot    { return "depends_fetch depends_extract depends_build depends_lib depends_run" }
+        destroot    {return [list depends_fetch depends_extract depends_build depends_lib depends_run]}
         dmg         -
         pkg         -
         mdmg        -
@@ -3186,50 +3210,50 @@
         dpkg        {
             if {[global_option_isset ports_binary_only] ||
                 (![global_option_isset ports_source_only] && [$workername eval _archive_available])} {
-                return "depends_lib depends_run"
+                return [list depends_lib depends_run]
             } else {
-                return "depends_fetch depends_extract depends_build depends_lib depends_run"
+                return [list depends_fetch depends_extract depends_build depends_lib depends_run]
             }
         }
         install     -
         activate    -
-        ""          {
-            if {[global_option_isset ports_binary_only] ||
-                [$workername eval registry_exists \$subport \$version \$revision \$portvariants]
+        {}          {
+            if {[global_option_isset ports_binary_only]
+                || [$workername eval {registry_exists $subport $version $revision $portvariants}]
                 || (![global_option_isset ports_source_only] && [$workername eval _archive_available])} {
-                return "depends_lib depends_run"
+                return [list depends_lib depends_run]
             } else {
-                return "depends_fetch depends_extract depends_build depends_lib depends_run"
+                return [list depends_fetch depends_extract depends_build depends_lib depends_run]
             }
         }
     }
-    return ""
+    return {}
 }
 
 # selfupdate procedure
-proc macports::selfupdate {{optionslist {}} {updatestatusvar ""}} {
+proc macports::selfupdate {{optionslist {}} {updatestatusvar {}}} {
     global macports::prefix macports::portdbpath macports::libpath \
            macports::rsync_server macports::rsync_dir macports::rsync_options \
            macports::autoconf::macports_version macports::autoconf::rsync_path \
            tcl_platform macports::autoconf::openssl_path macports::autoconf::tar_path
     array set options $optionslist
-    
+
     # variable that indicates whether we actually updated base
-    if {$updatestatusvar != ""} {
+    if {$updatestatusvar ne {}} {
         upvar $updatestatusvar updatestatus
         set updatestatus no
     }
 
     # are we syncing a tarball? (implies detached signature)
     set is_tarball 0
-    if {[string range ${rsync_dir} end-3 end] == ".tar"} {
+    if {[string range $rsync_dir end-3 end] eq ".tar"} {
         set is_tarball 1
-        set mp_source_path [file join $portdbpath sources ${rsync_server} [file dirname ${rsync_dir}]]
+        set mp_source_path [file join $portdbpath sources $rsync_server [file dirname $rsync_dir]]
     } else {
-        if {[string index $rsync_dir end] != "/"} {
-            append rsync_dir "/"
+        if {[string index $rsync_dir end] ne "/"} {
+            append rsync_dir /
         }
-        set mp_source_path [file join $portdbpath sources ${rsync_server} ${rsync_dir}]
+        set mp_source_path [file join $portdbpath sources $rsync_server $rsync_dir]
     }
     # create the path to the to be downloaded sources if it doesn't exist
     if {![file exists $mp_source_path]} {
@@ -3239,21 +3263,21 @@
 
     # sync the MacPorts sources
     ui_msg "$macports::ui_prefix Updating MacPorts base sources using rsync"
-    if { [catch { system "$rsync_path $rsync_options rsync://${rsync_server}/${rsync_dir} $mp_source_path" } result ] } {
+    if {[catch {system "$rsync_path $rsync_options rsync://$rsync_server/$rsync_dir $mp_source_path"} result ]} {
        return -code error "Error synchronizing MacPorts sources: $result"
     }
 
     if {$is_tarball} {
         # verify signature for tarball
         global macports::archivefetch_pubkeys
-        if { [catch { system "$rsync_path $rsync_options rsync://${rsync_server}/${rsync_dir}.rmd160 $mp_source_path" } result ] } {
+        if {[catch {system "$rsync_path $rsync_options rsync://$rsync_server/$rsync_dir.rmd160 $mp_source_path" } result]} {
             return -code error "Error synchronizing MacPorts source signature: $result"
         }
         set openssl [findBinary openssl $macports::autoconf::openssl_path]
-        set tarball "${mp_source_path}/[file tail $rsync_dir]"
-        set signature "${tarball}.rmd160"
+        set tarball $mp_source_path/[file tail $rsync_dir]
+        set signature $tarball.rmd160
         set verified 0
-        foreach pubkey ${macports::archivefetch_pubkeys} {
+        foreach pubkey $macports::archivefetch_pubkeys {
             if {![catch {exec $openssl dgst -ripemd160 -verify $pubkey -signature $signature $tarball} result]} {
                 set verified 1
                 ui_debug "successful verification with key $pubkey"
@@ -3266,26 +3290,26 @@
         if {!$verified} {
             return -code error "Failed to verify signature for MacPorts source!"
         }
-        
+
         # extract tarball and move into place
         set tar [macports::findBinary tar $macports::autoconf::tar_path]
-        file mkdir ${mp_source_path}/tmp
-        set tar_cmd "$tar -C ${mp_source_path}/tmp -xf ${tarball}"
+        file mkdir $mp_source_path/tmp
+        set tar_cmd "$tar -C $mp_source_path/tmp -xf $tarball"
         ui_debug $tar_cmd
         if {[catch {system $tar_cmd}]} {
             return -code error "Failed to extract MacPorts sources from tarball!"
         }
-        file delete -force ${mp_source_path}/base
-        file rename ${mp_source_path}/tmp/base ${mp_source_path}/base
-        file delete -force ${mp_source_path}/tmp
+        file delete -force $mp_source_path/base
+        file rename $mp_source_path/tmp/base $mp_source_path/base
+        file delete -force $mp_source_path/tmp
         # set the final extracted source path
-        set mp_source_path ${mp_source_path}/base
+        set mp_source_path $mp_source_path/base
     }
 
     # echo current MacPorts version
     ui_msg "MacPorts base version $macports::autoconf::macports_version installed,"
 
-    if { [info exists options(ports_force)] && $options(ports_force) == "yes" } {
+    if {[info exists options(ports_force)] && $options(ports_force) eq "yes"} {
         set use_the_force_luke yes
         ui_debug "Forcing a rebuild and reinstallation of MacPorts"
     } else {
@@ -3310,9 +3334,9 @@
     set comp [vercmp $macports_version_new $macports::autoconf::macports_version]
 
     # syncing ports tree.
-    if {![info exists options(ports_selfupdate_nosync)] || $options(ports_selfupdate_nosync) != "yes"} {
+    if {![info exists options(ports_selfupdate_nosync)] || $options(ports_selfupdate_nosync) ne "yes"} {
         if {$comp > 0} {
-            # updated portfiles potentially need new base to parse - tell sync to try to 
+            # updated portfiles potentially need new base to parse - tell sync to try to
             # use prefabricated PortIndex files and signal if it couldn't
             lappend optionslist no_reindex 1 needed_portindex_var needed_portindex
         }
@@ -3321,24 +3345,24 @@
         }
     }
 
-    if {$use_the_force_luke == "yes" || $comp > 0} {
-        if {[info exists options(ports_dryrun)] && $options(ports_dryrun) == "yes"} {
+    if {$use_the_force_luke eq "yes" || $comp > 0} {
+        if {[info exists options(ports_dryrun)] && $options(ports_dryrun) eq "yes"} {
             ui_msg "$macports::ui_prefix MacPorts base is outdated, selfupdate would install $macports_version_new (dry run)"
         } else {
             ui_msg "$macports::ui_prefix MacPorts base is outdated, installing new version $macports_version_new"
 
             # get installation user/group and permissions
-            set owner [file attributes ${prefix} -owner]
-            set group [file attributes ${prefix} -group]
-            set perms [string range [file attributes ${prefix} -permissions] end-3 end]
-            if {$tcl_platform(user) != "root" && ![string equal $tcl_platform(user) $owner]} {
-                return -code error "User $tcl_platform(user) does not own ${prefix} - try using sudo"
+            set owner [file attributes $prefix -owner]
+            set group [file attributes $prefix -group]
+            set perms [string range [file attributes $prefix -permissions] end-3 end]
+            if {$tcl_platform(user) ne "root" && ![string equal $tcl_platform(user) $owner]} {
+                return -code error "User $tcl_platform(user) does not own $prefix - try using sudo"
             }
             ui_debug "Permissions OK"
 
             # where to install a link to our macports1.0 tcl package
             set mp_tclpackage_path [file join $portdbpath .tclpackage]
-            if { [file exists $mp_tclpackage_path]} {
+            if {[file exists $mp_tclpackage_path]} {
                 set fd [open $mp_tclpackage_path r]
                 gets $fd tclpackage
                 close $fd
@@ -3348,26 +3372,27 @@
 
             set configure_args "--prefix=$prefix --with-tclpackage=$tclpackage --with-install-user=$owner --with-install-group=$group --with-directory-mode=$perms"
             # too many users have an incompatible readline in /usr/local, see ticket #10651
-            if {$tcl_platform(os) != "Darwin" || $prefix == "/usr/local"
-                || ([glob -nocomplain "/usr/local/lib/lib{readline,history}*"] == "" && [glob -nocomplain "/usr/local/include/readline/*.h"] == "")} {
+            if {$tcl_platform(os) ne "Darwin" || $prefix eq "/usr/local"
+                || ([glob -nocomplain /usr/local/lib/lib{readline,history}*] eq {}
+                && [glob -nocomplain /usr/local/include/readline/*.h] eq {})} {
                 append configure_args " --enable-readline"
             } else {
                 ui_warn "Disabling readline support due to readline in /usr/local"
             }
 
-            if {$prefix == "/usr/local" || $prefix == "/usr"} {
+            if {$prefix eq "/usr/local" || $prefix eq "/usr"} {
                 append configure_args " --with-unsupported-prefix"
             }
 
             # Choose a sane compiler
-            set cc_arg ""
-            if {$::macports::os_platform == "darwin"} {
+            set cc_arg {}
+            if {$::macports::os_platform eq "darwin"} {
                 set cc_arg "CC=/usr/bin/cc OBJC=/usr/bin/cc "
             }
 
             # do the actual configure, build and installation of new base
             ui_msg "Installing new MacPorts release in $prefix as $owner:$group; permissions $perms; Tcl-Package in $tclpackage\n"
-            if { [catch { system "cd $mp_source_path && ${cc_arg}./configure $configure_args && make SELFUPDATING=1 && make install SELFUPDATING=1" } result] } {
+            if {[catch {system "cd $mp_source_path && $cc_arg./configure $configure_args && make SELFUPDATING=1 && make install SELFUPDATING=1"} result]} {
                 return -code error "Error installing new MacPorts base: $result"
             }
             if {[info exists updatestatus]} {
@@ -3383,11 +3408,11 @@
     # set the MacPorts sources to the right owner
     set sources_owner [file attributes [file join $portdbpath sources/] -owner]
     ui_debug "Setting MacPorts sources ownership to $sources_owner"
-    if { [catch { exec [findBinary chown $macports::autoconf::chown_path] -R $sources_owner [file join $portdbpath sources/] } result] } {
+    if {[catch { exec [findBinary chown $macports::autoconf::chown_path] -R $sources_owner [file join $portdbpath sources/] } result]} {
         return -code error "Couldn't change permissions of the MacPorts sources at $mp_source_path to $sources_owner: $result"
     }
 
-    if {![info exists options(ports_selfupdate_nosync)] || $options(ports_selfupdate_nosync) != "yes"} {
+    if {![info exists options(ports_selfupdate_nosync)] || $options(ports_selfupdate_nosync) ne "yes"} {
         if {[info exists needed_portindex]} {
             ui_msg "Not all sources could be fully synced using the old version of MacPorts."
             ui_msg "Please run selfupdate again now that MacPorts base has been updated."
@@ -3406,13 +3431,13 @@
 #   1 = general failure
 #   2 = port name not found in index
 #   3 = port not installed
-proc macports::upgrade {portname dspec variationslist optionslist {depscachename ""}} {
+proc macports::upgrade {portname dspec variationslist optionslist {depscachename {}}} {
     # only installed ports can be upgraded
     if {![registry::entry_exists_for_name $portname]} {
         ui_error "$portname is not installed"
         return 3
     }
-    if {![string match "" $depscachename]} {
+    if {![string match {} $depscachename]} {
         upvar $depscachename depscache
     } else {
         array set depscache {}
@@ -3423,10 +3448,10 @@
         set macports::global_options(ports_nodeps) yes
         set orig_nodeps no
     }
-    
+
     # run the actual upgrade
     set status [macports::_upgrade $portname $dspec $variationslist $optionslist depscache]
-    
+
     if {!$orig_nodeps} {
         unset -nocomplain macports::global_options(ports_nodeps)
     }
@@ -3435,11 +3460,11 @@
 }
 
 # main internal upgrade procedure
-proc macports::_upgrade {portname dspec variationslist optionslist {depscachename ""}} {
+proc macports::_upgrade {portname dspec variationslist optionslist {depscachename {}}} {
     global macports::global_variations
     array set options $optionslist
 
-    if {![string match "" $depscachename]} {
+    if {![string match {} $depscachename]} {
         upvar $depscachename depscache
     }
 
@@ -3462,12 +3487,12 @@
     # check if the port is in tree
     if {[catch {mportlookup $portname} result]} {
         global errorInfo
-        ui_debug "$errorInfo"
+        ui_debug $errorInfo
         ui_error "port lookup failed: $result"
         return 1
     }
     # argh! port doesnt exist!
-    if {$result == ""} {
+    if {$result eq {}} {
         ui_warn "No port $portname found in the index."
         return 2
     }
@@ -3478,15 +3503,15 @@
     set options(subport) $portname
 
     set ilist {}
-    if { [catch {set ilist [registry::installed $portname ""]} result] } {
-        if {$result == "Registry error: $portname not registered as installed." } {
+    if {[catch {set ilist [registry::installed $portname {}]} result]} {
+        if {$result eq "Registry error: $portname not registered as installed."} {
             ui_debug "$portname is *not* installed by MacPorts"
 
             # We need to pass _mportispresent a reference to the mport that is
             # actually declaring the dependency on the one we're checking for.
             # We got here via _upgrade_dependencies, so we grab it from 2 levels up.
             upvar 2 mport parentmport
-            if {![_mportispresent $parentmport $dspec ] } {
+            if {![_mportispresent $parentmport $dspec]} {
                 # open porthandle
                 set porturl $portinfo(porturl)
                 if {![info exists porturl]} {
@@ -3497,14 +3522,14 @@
 
                 if {[catch {set mport [mportopen $porturl [array get options] [array get variations]]} result]} {
                     global errorInfo
-                    ui_debug "$errorInfo"
+                    ui_debug $errorInfo
                     ui_error "Unable to open port: $result"
                     return 1
                 }
                 # While we're at it, update the portinfo
                 array unset portinfo
                 array set portinfo [mportinfo $mport]
-                
+
                 # upgrade its dependencies first
                 set status [_upgrade_dependencies portinfo depscache variationslist options]
                 if {$status != 0 && $status != 2 && ![ui_isset ports_processall]} {
@@ -3514,7 +3539,7 @@
                 # now install it
                 if {[catch {set result [mportexec $mport activate]} result]} {
                     global errorInfo
-                    ui_debug "$errorInfo"
+                    ui_debug $errorInfo
                     ui_error "Unable to exec port: $result"
                     catch {mportclose $mport}
                     return 1
@@ -3525,7 +3550,7 @@
                     return $result
                 }
                 # we just installed it, so mark it done in the cache
-                set depscache(port:${portname}) 1
+                set depscache(port:$portname) 1
                 mportclose $mport
             } else {
                 # dependency is satisfied by something other than the named port
@@ -3542,17 +3567,17 @@
         }
     } else {
         # we'll now take care of upgrading it, so we can add it to the cache
-        set depscache(port:${portname}) 1
+        set depscache(port:$portname) 1
     }
-    
+
     # set version_in_tree and revision_in_tree
     if {![info exists portinfo(version)]} {
         ui_error "Invalid port entry for $portname, missing version"
         return 1
     }
-    set version_in_tree "$portinfo(version)"
-    set revision_in_tree "$portinfo(revision)"
-    set epoch_in_tree "$portinfo(epoch)"
+    set version_in_tree $portinfo(version)
+    set revision_in_tree $portinfo(revision)
+    set epoch_in_tree $portinfo(epoch)
 
     # find latest version installed and active version (if any)
     set anyactive no
@@ -3562,7 +3587,7 @@
         set version [lindex $i 1]
         set revision [lindex $i 2]
         set epoch [lindex $i 5]
-        if { $version_installed == {} || ($epoch > $epoch_installed && $version != $version_installed) ||
+        if {$version_installed eq {} || ($epoch > $epoch_installed && $version ne $version_installed) ||
                 ($epoch >= $epoch_installed && [vercmp $version $version_installed] > 0)
                 || ($epoch >= $epoch_installed
                     && [vercmp $version $version_installed] == 0
@@ -3585,10 +3610,10 @@
 
     # output version numbers
     ui_debug "epoch: in tree: $epoch_in_tree installed: $epoch_installed"
-    ui_debug "$portname ${version_in_tree}_${revision_in_tree} exists in the ports tree"
-    ui_debug "$portname ${version_installed}_${revision_installed} $variant_installed is the latest installed"
+    ui_debug "$portname ${version_in_tree}_$revision_in_tree exists in the ports tree"
+    ui_debug "$portname ${version_installed}_$revision_installed $variant_installed is the latest installed"
     if {$anyactive} {
-        ui_debug "$portname ${version_active}_${revision_active} $variant_active is active"
+        ui_debug "$portname ${version_active}_$revision_active $variant_active is active"
         # save existing variant for later use
         set oldvariant $variant_active
         set regref [registry::open_entry $portname $version_active $revision_active $variant_active $epoch_active]
@@ -3618,23 +3643,23 @@
     # upgrade; while variations gets existing variants and global variations
     # merged in later on, so it applies only to this port's upgrade
     array set variations $variationslist
-    
+
     set globalvarlist [array get macports::global_variations]
 
     set minusvariant [lrange [split $oldnegatedvariant -] 1 end]
     set plusvariant [lrange [split $oldvariant +] 1 end]
-    ui_debug "Merging existing variants '${oldvariant}${oldnegatedvariant}' into variants"
+    ui_debug "Merging existing variants '$oldvariant$oldnegatedvariant' into variants"
     set oldvariantlist [list]
     foreach v $plusvariant {
-        lappend oldvariantlist $v "+"
+        lappend oldvariantlist $v +
     }
     foreach v $minusvariant {
-        lappend oldvariantlist $v "-"
+        lappend oldvariantlist $v -
     }
 
     # merge in the old variants
     foreach {variation value} $oldvariantlist {
-        if { ![info exists variations($variation)]} {
+        if {![info exists variations($variation)]} {
             set variations($variation) $value
         }
     }
@@ -3642,24 +3667,24 @@
     # Now merge in the global (i.e. variants.conf) variations.
     # We wait until now so that existing variants for this port
     # override global variations
-    foreach { variation value } $globalvarlist {
-        if { ![info exists variations($variation)] } {
+    foreach {variation value} $globalvarlist {
+        if {![info exists variations($variation)] } {
             set variations($variation) $value
         }
     }
 
     ui_debug "new fully merged portvariants: [array get variations]"
-    
+
     # at this point we need to check if a different port will be replacing this one
     if {[info exists portinfo(replaced_by)] && ![info exists options(ports_upgrade_no-replace)]} {
         ui_msg "$macports::ui_prefix $portname is replaced by $portinfo(replaced_by)"
         if {[catch {mportlookup $portinfo(replaced_by)} result]} {
             global errorInfo
-            ui_debug "$errorInfo"
+            ui_debug $errorInfo
             ui_error "port lookup failed: $result"
             return 1
         }
-        if {$result == ""} {
+        if {$result eq {}} {
             ui_error "No port $portinfo(replaced_by) found."
             return 1
         }
@@ -3671,7 +3696,7 @@
         if {![info exists porturl]} {
             set porturl file://./
         }
-        set depscache(port:${newname}) 1
+        set depscache(port:$newname) 1
     } else {
         set newname $portname
     }
@@ -3682,7 +3707,7 @@
 
     if {[catch {set mport [mportopen $porturl [array get interp_options] [array get variations]]} result]} {
         global errorInfo
-        ui_debug "$errorInfo"
+        ui_debug $errorInfo
         ui_error "Unable to open port: $result"
         return 1
     }
@@ -3690,28 +3715,31 @@
 
     array unset portinfo
     array set portinfo [mportinfo $mport]
-    set version_in_tree "$portinfo(version)"
-    set revision_in_tree "$portinfo(revision)"
-    set epoch_in_tree "$portinfo(epoch)"
+    set version_in_tree $portinfo(version)
+    set revision_in_tree $portinfo(revision)
+    set epoch_in_tree $portinfo(epoch)
 
     set build_override 0
     set will_install yes
     # check installed version against version in ports
-    if { ( [vercmp $version_installed $version_in_tree] > 0
+    if {([vercmp $version_installed $version_in_tree] > 0
             || ([vercmp $version_installed $version_in_tree] == 0
-                && [vercmp $revision_installed $revision_in_tree] >= 0 ))
-        && ![info exists options(ports_upgrade_force)] } {
-        if {$portname != $newname} {
+                && [vercmp $revision_installed $revision_in_tree] >= 0))
+        && ![info exists options(ports_upgrade_force)]} {
+        if {$portname ne $newname} {
             ui_debug "ignoring versions, installing replacement port"
-        } elseif { $epoch_installed < $epoch_in_tree && $version_installed != $version_in_tree } {
+        } elseif { $epoch_installed < $epoch_in_tree && $version_installed ne $version_in_tree } {
             set build_override 1
             ui_debug "epoch override ... upgrading!"
-        } elseif {[info exists options(ports_upgrade_enforce-variants)] && $options(ports_upgrade_enforce-variants) eq "yes"
-                  && [info exists portinfo(canonical_active_variants)] && $portinfo(canonical_active_variants) != $oldvariant} {
+        } elseif {[info exists options(ports_upgrade_enforce-variants)]
+            && $options(ports_upgrade_enforce-variants) eq "yes"
+            && [info exists portinfo(canonical_active_variants)]
+            && $portinfo(canonical_active_variants) ne $oldvariant} {
+
             ui_debug "variant override ... upgrading!"
-        } elseif {$os_platform_installed != "" && $os_major_installed != "" && $os_platform_installed != 0
-                  && ([_mportkey $mport "{os.platform}"] != $os_platform_installed
-                  || [_mportkey $mport "{os.major}"] != $os_major_installed)} {
+        } elseif {$os_platform_installed ne {} && $os_major_installed ne {} && $os_platform_installed != 0
+                  && ([_mportkey $mport "{os.platform}"] ne $os_platform_installed
+                  || [_mportkey $mport "{os.major}"] ne $os_major_installed)} {
             ui_debug "platform mismatch ... upgrading!"
             set build_override 1
         } elseif {$is_revupgrade_second_run} {
@@ -3722,14 +3750,14 @@
             # in the first run of rev-upgrade, only activate possibly already existing files and check for missing dependencies
             set will_install yes
         } else {
-            if {[info exists portinfo(canonical_active_variants)] && $portinfo(canonical_active_variants) != $oldvariant} {
+            if {[info exists portinfo(canonical_active_variants)] && $portinfo(canonical_active_variants) ne $oldvariant} {
                 if {[llength $variationslist] > 0} {
-                    ui_warn "Skipping upgrade since $portname ${version_installed}_${revision_installed} >= $portname ${version_in_tree}_${revision_in_tree}, even though installed variants \"$oldvariant\" do not match \"$portinfo(canonical_active_variants)\". Use 'upgrade --enforce-variants' to switch to the requested variants."
+                    ui_warn "Skipping upgrade since $portname ${version_installed}_$revision_installed >= $portname ${version_in_tree}_$revision_in_tree, even though installed variants \"$oldvariant\" do not match \"$portinfo(canonical_active_variants)\". Use 'upgrade --enforce-variants' to switch to the requested variants."
                 } else {
-                    ui_debug "Skipping upgrade since $portname ${version_installed}_${revision_installed} >= $portname ${version_in_tree}_${revision_in_tree}, even though installed variants \"$oldvariant\" do not match \"$portinfo(canonical_active_variants)\"."
+                    ui_debug "Skipping upgrade since $portname ${version_installed}_$revision_installed >= $portname ${version_in_tree}_$revision_in_tree, even though installed variants \"$oldvariant\" do not match \"$portinfo(canonical_active_variants)\"."
                 }
             } else {
-                ui_debug "No need to upgrade! $portname ${version_installed}_${revision_installed} >= $portname ${version_in_tree}_${revision_in_tree}"
+                ui_debug "No need to upgrade! $portname ${version_installed}_$revision_installed >= $portname ${version_in_tree}_$revision_in_tree"
             }
             set will_install no
         }
@@ -3748,7 +3776,8 @@
     # first upgrade dependencies
     if {![info exists options(ports_nodeps)] && !$is_revupgrade} {
         # the last arg is because we might have to build from source if a rebuild is being forced
-        set status [_upgrade_dependencies portinfo depscache variationslist options [expr $will_build && $already_installed]]
+        set status [_upgrade_dependencies portinfo depscache variationslist options [expr {
+            $will_build && $already_installed}]]
         if {$status != 0 && $status != 2 && ![ui_isset ports_processall]} {
             catch {mportclose $mport}
             return $status
@@ -3770,11 +3799,11 @@
                 set deplist [registry::list_dependents $portname $version_installed $revision_installed $variant_installed]
             }
 
-            if { [llength deplist] > 0 } {
+            if {[llength deplist] > 0} {
                 foreach dep $deplist {
                     set mpname [lindex $dep 2]
-                    if {![llength [array get depscache port:${mpname}]]} {
-                        set status [macports::_upgrade $mpname port:${mpname} $variationslist [array get options] depscache]
+                    if {![llength [array get depscache port:$mpname]]} {
+                        set status [macports::_upgrade $mpname port:$mpname $variationslist [array get options] depscache]
                         if {$status != 0 && $status != 2 && ![ui_isset ports_processall]} {
                             catch {mportclose $mport}
                             return $status
@@ -3795,7 +3824,7 @@
             # Ideally this would be done in the interp_options when we mportopen,
             # but we don't know if we want to do this at that point.
             set workername [ditem_key $mport workername]
-            $workername eval "set force_archive_refresh yes"
+            $workername eval set force_archive_refresh yes
 
             # run archivefetch and destroot for version_in_tree
             # doing this instead of just running install ensures that we have the
@@ -3803,7 +3832,7 @@
             # existing one.
             if {[catch {set result [mportexec $mport archivefetch]} result] || $result != 0} {
                 if {[info exists ::errorInfo]} {
-                    ui_debug "$::errorInfo"
+                    ui_debug $::errorInfo
                 }
                 ui_error "Unable to upgrade port: $result"
                 catch {mportclose $mport}
@@ -3812,7 +3841,7 @@
             # the following is a noop if archivefetch found an archive
             if {[catch {set result [mportexec $mport destroot]} result] || $result != 0} {
                 if {[info exists ::errorInfo]} {
-                    ui_debug "$::errorInfo"
+                    ui_debug $::errorInfo
                 }
                 ui_error "Unable to upgrade port: $result"
                 catch {mportclose $mport}
@@ -3823,7 +3852,7 @@
             # install version_in_tree (but don't activate yet)
             if {[catch {set result [mportexec $mport install]} result] || $result != 0} {
                 if {[info exists ::errorInfo]} {
-                    ui_debug "$::errorInfo"
+                    ui_debug $::errorInfo
                 }
                 ui_error "Unable to upgrade port: $result"
                 catch {mportclose $mport}
@@ -3835,19 +3864,19 @@
     # are we installing an existing version due to force or epoch override?
     if {$already_installed
         && ([info exists options(ports_upgrade_force)] || $build_override == 1)} {
-         ui_debug "Uninstalling $newname ${version_in_tree}_${revision_in_tree}$portinfo(canonical_active_variants)"
+         ui_debug "Uninstalling $newname ${version_in_tree}_$revision_in_tree$portinfo(canonical_active_variants)"
         # we have to force the uninstall in case of dependents
         set force_cur [info exists options(ports_force)]
         set options(ports_force) yes
-        set existing_epoch [lindex [lindex [registry::installed $newname ${version_in_tree}_${revision_in_tree}$portinfo(canonical_active_variants)] 0] 5]
+        set existing_epoch [lindex [lindex [registry::installed $newname ${version_in_tree}_$revision_in_tree$portinfo(canonical_active_variants)] 0] 5]
         set newregref [registry::open_entry $newname $version_in_tree $revision_in_tree $portinfo(canonical_active_variants) $existing_epoch]
         if {$is_dryrun eq "yes"} {
-            ui_msg "Skipping uninstall $newname @${version_in_tree}_${revision_in_tree}$portinfo(canonical_active_variants) (dry run)"
+            ui_msg "Skipping uninstall $newname @${version_in_tree}_$revision_in_tree$portinfo(canonical_active_variants) (dry run)"
         } elseif {![registry::run_target $newregref uninstall [array get options]]
                   && [catch {registry_uninstall::uninstall $newname $version_in_tree $revision_in_tree $portinfo(canonical_active_variants) [array get options]} result]} {
             global errorInfo
-            ui_debug "$errorInfo"
-            ui_error "Uninstall $newname ${version_in_tree}_${revision_in_tree}$portinfo(canonical_active_variants) failed: $result"
+            ui_debug $errorInfo
+            ui_error "Uninstall $newname ${version_in_tree}_$revision_in_tree$portinfo(canonical_active_variants) failed: $result"
             catch {mportclose $mport}
             return 1
         }
@@ -3855,23 +3884,23 @@
             unset options(ports_force)
         }
         if {$anyactive && $version_in_tree == $version_active && $revision_in_tree == $revision_active
-            && $portinfo(canonical_active_variants) == $variant_active && $portname == $newname} {
+            && $portinfo(canonical_active_variants) eq $variant_active && $portname == $newname} {
             set anyactive no
         }
     }
-    if {$anyactive && $portname != $newname} {
+    if {$anyactive && $portname ne $newname} {
         # replaced_by in effect, deactivate the old port
         # we have to force the deactivate in case of dependents
         set force_cur [info exists options(ports_force)]
         set options(ports_force) yes
         if {$is_dryrun eq "yes"} {
-            ui_msg "Skipping deactivate $portname @${version_active}_${revision_active}${variant_active} (dry run)"
+            ui_msg "Skipping deactivate $portname @${version_active}_$revision_active$variant_active (dry run)"
         } elseif {![catch {registry::active $portname}] &&
                   ![registry::run_target $regref deactivate [array get options]]
                   && [catch {portimage::deactivate $portname $version_active $revision_active $variant_active [array get options]} result]} {
             global errorInfo
-            ui_debug "$errorInfo"
-            ui_error "Deactivating $portname @${version_active}_${revision_active}${variant_active} failed: $result"
+            ui_debug $errorInfo
+            ui_error "Deactivating $portname @${version_active}_$revision_active$variant_active failed: $result"
             catch {mportclose $mport}
             return 1
         }
@@ -3880,7 +3909,7 @@
         }
         set anyactive no
     }
-    if {[info exists options(port_uninstall_old)] && $portname == $newname} {
+    if {[info exists options(port_uninstall_old)] && $portname eq $newname} {
         # uninstalling now could fail due to dependents when not forced,
         # because the new version is not installed
         set uninstall_later yes
@@ -3888,13 +3917,13 @@
 
     if {$is_dryrun eq "yes"} {
         if {$anyactive} {
-            ui_msg "Skipping deactivate $portname @${version_active}_${revision_active}${variant_active} (dry run)"
+            ui_msg "Skipping deactivate $portname @${version_active}_$revision_active$variant_active (dry run)"
         }
-        ui_msg "Skipping activate $newname @${version_in_tree}_${revision_in_tree}$portinfo(canonical_active_variants) (dry run)"
+        ui_msg "Skipping activate $newname @${version_in_tree}_$revision_in_tree$portinfo(canonical_active_variants) (dry run)"
     } elseif {[catch {set result [mportexec $mport activate]} result]} {
         global errorInfo
-        ui_debug "$errorInfo"
-        ui_error "Couldn't activate $newname ${version_in_tree}_${revision_in_tree}$portinfo(canonical_active_variants): $result"
+        ui_debug $errorInfo
+        ui_error "Couldn't activate $newname ${version_in_tree}_$revision_in_tree$portinfo(canonical_active_variants): $result"
         catch {mportclose $mport}
         return 1
     }
@@ -3905,7 +3934,7 @@
         set options(ports_nodeps) 1
 
         registry::open_dep_map
-        if {$portname != $newname} {
+        if {$portname ne $newname} {
             set deplist [registry::list_dependents $newname $version_in_tree $revision_in_tree $portinfo(canonical_active_variants)]
         } else {
             set deplist [list]
@@ -3916,11 +3945,11 @@
             set deplist [concat $deplist [registry::list_dependents $portname $version_installed $revision_installed $variant_installed]]
         }
 
-        if { [llength deplist] > 0 } {
+        if {[llength deplist] > 0} {
             foreach dep $deplist {
                 set mpname [lindex $dep 2]
-                if {![llength [array get depscache port:${mpname}]]} {
-                    set status [macports::_upgrade $mpname port:${mpname} $variationslist [array get options] depscache]
+                if {![llength [array get depscache port:$mpname]]} {
+                    set status [macports::_upgrade $mpname port:$mpname $variationslist [array get options] depscache]
                     if {$status != 0 && $status != 2 && ![ui_isset ports_processall]} {
                         catch {mportclose $mport}
                         return $status
@@ -3930,26 +3959,26 @@
         }
     }
 
-    if {[info exists uninstall_later] && $uninstall_later == yes} {
+    if {[info exists uninstall_later] && $uninstall_later eq yes} {
         foreach i $ilist {
             set version [lindex $i 1]
             set revision [lindex $i 2]
             set variant [lindex $i 3]
-            if {$version == $version_in_tree && $revision == $revision_in_tree && $variant == $portinfo(canonical_active_variants) && $portname == $newname} {
+            if {$version eq $version_in_tree && $revision eq $revision_in_tree && $variant eq $portinfo(canonical_active_variants) && $portname eq $newname} {
                 continue
             }
             set epoch [lindex $i 5]
-            ui_debug "Uninstalling $portname ${version}_${revision}${variant}"
+            ui_debug "Uninstalling $portname ${version}_$revision$variant"
             set regref [registry::open_entry $portname $version $revision $variant $epoch]
             if {$is_dryrun eq "yes"} {
-                ui_msg "Skipping uninstall $portname @${version}_${revision}${variant} (dry run)"
+                ui_msg "Skipping uninstall $portname @${version}_$revision$variant (dry run)"
             } elseif {![registry::run_target $regref uninstall $optionslist]
                       && [catch {registry_uninstall::uninstall $portname $version $revision $variant $optionslist} result]} {
                 global errorInfo
-                ui_debug "$errorInfo"
+                ui_debug $errorInfo
                 # replaced_by can mean that we try to uninstall all versions of the old port, so handle errors due to dependents
-                if {$result != "Please uninstall the ports that depend on $portname first." && ![ui_isset ports_processall]} {
-                    ui_error "Uninstall $portname @${version}_${revision}${variant} failed: $result"
+                if {$result ne "Please uninstall the ports that depend on $portname first." && ![ui_isset ports_processall]} {
+                    ui_error "Uninstall $portname @${version}_$revision$variant failed: $result"
                     catch {mportclose $mport}
                     return 1
                 }
@@ -3995,9 +4024,9 @@
     foreach dtype $dtypes {
         if {[info exists portinfo($dtype)]} {
             foreach i $portinfo($dtype) {
-                set d [$parentworker eval _get_dep_port $i]
-                if {![llength [array get depscache port:${d}]] && ![llength [array get depscache $i]]} {
-                    if {$d != ""} {
+                set d [$parentworker eval [list _get_dep_port $i]]
+                if {![llength [array get depscache port:$d]] && ![llength [array get depscache $i]]} {
+                    if {$d ne {}} {
                         set dspec port:$d
                     } else {
                         set dspec $i
@@ -4023,10 +4052,10 @@
 #            $macports::prefix/etc/select.
 #   * version: This argument is only used by the 'set' command.
 # On error mportselect returns with the code 'error'.
-proc mportselect {command group {version ""}} {
+proc mportselect {command group {version {}}} {
     ui_debug "mportselect \[$command] \[$group] \[$version]"
 
-    set conf_path "$macports::prefix/etc/select/$group"
+    set conf_path $macports::prefix/etc/select/$group
     if {![file isdirectory $conf_path]} {
         return -code error "The specified group '$group' does not exist."
     }
@@ -4036,7 +4065,7 @@
             if {[catch {set versions [glob -directory $conf_path *]} result]} {
                 global errorInfo
                 ui_debug "$result: $errorInfo"
-                return -code error [concat "No configurations associated " \
+                return -code error [concat "No configurations associated" \
                                            "with '$group' were found."]
             }
 
@@ -4054,7 +4083,7 @@
         }
         set {
             # Use $conf_path/$version to read in sources.
-            if {$version == "" || $version == "base" || $version == "current"
+            if {$version eq {} || $version eq "base" || $version eq "current"
                     || [catch {set src_file [open "$conf_path/$version"]} result]} {
                 global errorInfo
                 ui_debug "$result: $errorInfo"
@@ -4064,14 +4093,14 @@
             close $src_file
 
             # Use $conf_path/base to read in targets.
-            if {[catch {set tgt_file [open "$conf_path/base"]} result]} {
+            if {[catch {set tgt_file [open $conf_path/base]} result]} {
                 global errorInfo
                 ui_debug "$result: $errorInfo"
-                return -code error [concat "The configuration file " \
-                                           "'$conf_path/base' could not be " \
+                return -code error [concat "The configuration file" \
+                                           "'$conf_path/base' could not be" \
                                            "opened."]
             }
-            set tgts [split [read -nonewline $tgt_file] "\n"]
+            set tgts [split [read -nonewline $tgt_file] \n]
             close $tgt_file
 
             # Iterate through the configuration files executing the specified
@@ -4103,11 +4132,11 @@
                         ui_debug "ln -sf $src $tgt"
                     }
                 }
-                set i [expr $i+1]
+                set i [expr {$i+1}]
             }
 
             # Update the selected version.
-            set selected_version "$conf_path/current"
+            set selected_version $conf_path/current
             if {[file exists $selected_version]} {
                 file delete $selected_version
             }
@@ -4115,10 +4144,10 @@
             return
         }
         show {
-            set selected_version "$conf_path/current"
+            set selected_version $conf_path/current
 
             if {![file exists $selected_version]} {
-                return "none"
+                return none
             } else {
                 return [file readlink $selected_version]
             }
@@ -4135,19 +4164,19 @@
     if {[info exists env(TMPDIR)]} {
         return $env(TMPDIR)
     } else {
-        return "/tmp"
+        return /tmp
     }
 }
 
 # check if the system we're on can run code of the given architecture
 proc macports::arch_runnable {arch} {
     global macports::os_major macports::os_arch macports::os_platform
-    if {${macports::os_platform} == "darwin"} {
-        if {${macports::os_major} >= 11 && [string first "ppc" $arch] == 0} {
+    if {$macports::os_platform eq "darwin"} {
+        if {$macports::os_major >= 11 && [string first "ppc" $arch] == 0} {
             return no
-        } elseif {${macports::os_arch} == "i386" && $arch == "ppc64"} {
+        } elseif {$macports::os_arch eq "i386" && $arch eq "ppc64"} {
             return no
-        } elseif {${macports::os_major} <= 8 && $arch == "x86_64"} {
+        } elseif {$macports::os_major <= 8 && $arch eq "x86_64"} {
             return no
         }
     }
@@ -4170,7 +4199,7 @@
 
     set files [registry::file search active 1 binary -null]
     set files_count [llength $files]
-    set fancy_output [expr ![macports::ui_isset ports_debug] && [isatty stdout]]
+    set fancy_output [expr {![macports::ui_isset ports_debug] && [isatty stdout]}]
     if {$files_count > 0} {
         registry::write {
             try {
@@ -4179,7 +4208,8 @@
                 foreach f $files {
                     if {$fancy_output} {
                         if {$files_count < 10000 || $i % 10 == 1 || $i == $files_count} {
-                            ui_msg -nonewline "\r$macports::ui_prefix Updating database of binaries: [expr ($i * 1000 / $files_count) / 10.0]%"
+                            ui_msg -nonewline "\r$macports::ui_prefix Updating database of binaries: [expr {
+                                ($i * 1000 / $files_count) / 10.0}]%"
                             flush stdout
                         }
                     }
@@ -4190,7 +4220,7 @@
                     if {0 != [catch {$f binary [fileIsBinary $fpath]} fileIsBinaryError]} {
                         # handle errors (e.g. file not found, permission denied) gracefully
                         if {$fancy_output} {
-                            ui_msg ""
+                            ui_msg {}
                         }
                         ui_warn "Error determining file type of `$fpath': $fileIsBinaryError"
                         ui_warn "A file belonging to the `[[registry::entry owner $fpath] name]' port is missing or unreadable. Consider reinstalling it."
@@ -4201,7 +4231,7 @@
                 throw
             }
         }
-        ui_msg ""
+        ui_msg {}
     }
 
     set broken_files {};
@@ -4210,7 +4240,7 @@
     if {$binary_count > 0} {
         ui_msg -nonewline "$macports::ui_prefix Scanning binaries for linking errors"
         set handle [machista::create_handle]
-        if {$handle == "NULL"} {
+        if {$handle eq "NULL"} {
             error "Error creating libmachista handle"
         }
         array unset files_warned_about
@@ -4220,7 +4250,8 @@
         foreach b $binaries {
             if {$fancy_output} {
                 if {$binary_count < 10000 || $i % 10 == 1 || $i == $binary_count} {
-                    ui_msg -nonewline "\r$macports::ui_prefix Scanning binaries for linking errors: [expr ($i * 1000 / $binary_count) / 10.0]%"
+                    ui_msg -nonewline "\r$macports::ui_prefix Scanning binaries for linking errors: [expr {
+                        ($i * 1000 / $binary_count) / 10.0}]%"
                     flush stdout
                 }
             }
@@ -4236,62 +4267,62 @@
                 if {$returncode == $machista::EMAGIC} {
                     # not a Mach-O file
                     # ignore silently, these are only static libs anyway
-                    #ui_debug "Error parsing file ${bpath}: [machista::strerror $returncode]"
+                    #ui_debug "Error parsing file $bpath: [machista::strerror $returncode]"
                 } else {
                     if {$fancy_output} {
-                        ui_msg ""
+                        ui_msg {}
                     }
-                    ui_warn "Error parsing file ${bpath}: [machista::strerror $returncode]"
+                    ui_warn "Error parsing file $bpath: [machista::strerror $returncode]"
                 }
                 continue;
             }
 
             set architecture [$result cget -mt_archs]
-            while {$architecture != "NULL"} {
-                if {[info exists options(ports_rev-upgrade_id-loadcmd-check)] && $options(ports_rev-upgrade_id-loadcmd-check) == "yes"} {
-                    if {[$architecture cget -mat_install_name] != "NULL" && [$architecture cget -mat_install_name] != ""} {
+            while {$architecture ne "NULL"} {
+                if {[info exists options(ports_rev-upgrade_id-loadcmd-check)] && $options(ports_rev-upgrade_id-loadcmd-check) eq "yes"} {
+                    if {[$architecture cget -mat_install_name] ne "NULL" && [$architecture cget -mat_install_name] ne {}} {
                         # check if this lib's install name actually refers to this file itself
                         # if this is not the case software linking against this library might have erroneous load commands
                         if {0 == [catch {set idloadcmdpath [revupgrade_handle_special_paths $bpath [$architecture cget -mat_install_name]]}]} {
-                            if {[string index $idloadcmdpath 0] != "/"} {
+                            if {[string index $idloadcmdpath 0] ne "/"} {
                                 set port [registry::entry owner $bpath]
-                                if {$port != ""} {
+                                if {$port ne {}} {
                                     set portname [$port name]
                                 } else {
-                                    set portname "<unknown-port>"
+                                    set portname <unknown-port>
                                 }
                                 if {$fancy_output} {
-                                    ui_msg ""
+                                    ui_msg {}
                                 }
-                                ui_warn "ID load command in ${bpath}, arch [machista::get_arch_name [$architecture cget -mat_arch]] (belonging to port $portname) contains relative path"
+                                ui_warn "ID load command in $bpath, arch [machista::get_arch_name [$architecture cget -mat_arch]] (belonging to port $portname) contains relative path"
                             } elseif {![file exists $idloadcmdpath]} {
                                 set port [registry::entry owner $bpath]
-                                if {$port != ""} {
+                                if {$port ne {}} {
                                     set portname [$port name]
                                 } else {
-                                    set portname "<unknown-port>"
+                                    set portname <unknown-port>
                                 }
                                 if {$fancy_output} {
-                                    ui_msg ""
+                                    ui_msg {}
                                 }
-                                ui_warn "ID load command in ${bpath}, arch [machista::get_arch_name [$architecture cget -mat_arch]] refers to non-existant file $idloadcmdpath"
+                                ui_warn "ID load command in $bpath, arch [machista::get_arch_name [$architecture cget -mat_arch]] refers to non-existant file $idloadcmdpath"
                                 ui_warn "This is probably a bug in the $portname port and might cause problems in libraries linking against this file"
                             } else {
-    
+
                                 set hash_this [sha256 file $bpath]
                                 set hash_idloadcmd [sha256 file $idloadcmdpath]
-    
-                                if {$hash_this != $hash_idloadcmd} {
+
+                                if {$hash_this ne $hash_idloadcmd} {
                                     set port [registry::entry owner $bpath]
-                                    if {$port != ""} {
+                                    if {$port ne {}} {
                                         set portname [$port name]
                                     } else {
-                                        set portname "<unknown-port>"
+                                        set portname <unknown-port>
                                     }
                                     if {$fancy_output} {
-                                        ui_msg ""
+                                        ui_msg {}
                                     }
-                                    ui_warn "ID load command in ${bpath}, arch [machista::get_arch_name [$architecture cget -mat_arch]] refers to file $idloadcmdpath, which is a different file"
+                                    ui_warn "ID load command in $bpath, arch [machista::get_arch_name [$architecture cget -mat_arch]] refers to file $idloadcmdpath, which is a different file"
                                     ui_warn "This is probably a bug in the $portname port and might cause problems in libraries linking against this file"
                                 }
                             }
@@ -4308,7 +4339,7 @@
 
                 set loadcommand [$architecture cget -mat_loadcmds]
 
-                while {$loadcommand != "NULL"} {
+                while {$loadcommand ne "NULL"} {
                     if {0 != [catch {set filepath [revupgrade_handle_special_paths $bpath [$loadcommand cget -mlt_install_name]]}]} {
                         set loadcommand [$loadcommand cget -next]
                         continue;
@@ -4321,7 +4352,7 @@
                     if {$libreturncode != $machista::SUCCESS} {
                         if {![info exists files_warned_about($filepath)]} {
                             if {[macports::ui_isset ports_verbose]} {
-                                ui_msg ""
+                                ui_msg {}
                             }
                             ui_info "Could not open $filepath: [machista::strerror $libreturncode] (referenced from $bpath)"
                             set files_warned_about($filepath) yes
@@ -4336,15 +4367,15 @@
 
                     set libarchitecture [$libresult cget -mt_archs]
                     set libarch_found false;
-                    while {$libarchitecture != "NULL"} {
-                        if {[$architecture cget -mat_arch] != [$libarchitecture cget -mat_arch]} {
+                    while {$libarchitecture ne "NULL"} {
+                        if {[$architecture cget -mat_arch] ne [$libarchitecture cget -mat_arch]} {
                             set libarchitecture [$libarchitecture cget -next]
                             continue;
                         }
 
-                        if {[$loadcommand cget -mlt_version] != [$libarchitecture cget -mat_version] && [$loadcommand cget -mlt_comp_version] > [$libarchitecture cget -mat_comp_version]} {
+                        if {[$loadcommand cget -mlt_version] ne [$libarchitecture cget -mat_version] && [$loadcommand cget -mlt_comp_version] > [$libarchitecture cget -mat_comp_version]} {
                             if {[macports::ui_isset ports_verbose]} {
-                                ui_msg ""
+                                ui_msg {}
                             }
                             ui_info "Incompatible library version: $bpath requires version [machista::format_dylib_version [$loadcommand cget -mlt_comp_version]] or later, but $filepath provides version [machista::format_dylib_version [$libarchitecture cget -mat_comp_version]]"
                             ui_debug "Marking $bpath as broken"
@@ -4355,7 +4386,7 @@
                         break;
                     }
 
-                    if {$libarch_found == false} {
+                    if {$libarch_found eq false} {
                         ui_debug "Missing architecture [machista::get_arch_name [$architecture cget -mat_arch]] in file $filepath"
                         if {[path_is_in_prefix $filepath]} {
                             ui_debug "Marking $bpath as broken"
@@ -4371,7 +4402,7 @@
                 set architecture [$architecture cget -next]
             }
         }
-        ui_msg ""
+        ui_msg {}
 
         machista::destroy_handle $handle
 
@@ -4384,7 +4415,7 @@
         set broken_files [lsort -unique $broken_files]
         foreach file $broken_files {
             set port [registry::entry owner $file]
-            if {$port != ""} {
+            if {$port ne {}} {
                 lappend broken_ports $port
                 lappend broken_files_by_port($port) $file
             } else {
@@ -4393,13 +4424,13 @@
         }
         set broken_ports [lsort -unique $broken_ports]
 
-        if {${macports::revupgrade_mode} == "rebuild"} {
+        if {$macports::revupgrade_mode eq "rebuild"} {
             # don't try to rebuild ports that don't exist in the tree
             set temp_broken_ports {}
             foreach port $broken_ports {
                 set portname [$port name]
                 if {[catch {mportlookup $portname} result]} {
-                    ui_debug "$::errorInfo"
+                    ui_debug $::errorInfo
                     error "lookup of portname $portname failed: $result"
                 }
                 if {[llength $result] >= 2} {
@@ -4431,7 +4462,8 @@
                 if {$fancy_output} {
                     ui_error "Please run port -d -y rev-upgrade and use the output to report a bug."
                 }
-                error "Port $portname still broken after rebuilding [expr $broken_port_counts($portname) - 1] time(s)"
+                error "Port $portname still broken after rebuilding [expr {
+                    $broken_port_counts($portname) - 1}] time(s)"
             } elseif {$broken_port_counts($portname) > 1 && [global_option_isset ports_binary_only]} {
                 error "Port $portname still broken after reinstalling -- can't rebuild due to binary-only mode"
             }
@@ -4439,7 +4471,7 @@
         }
         unset temp_broken_ports
 
-        if {${macports::revupgrade_mode} != "rebuild"} {
+        if {$macports::revupgrade_mode ne "rebuild"} {
             ui_msg "$macports::ui_prefix Found [llength $broken_ports] broken port(s):"
             foreach port $broken_ports {
                 ui_msg "     [$port name] @[$port version] [$port variants][$port negated_variants]"
@@ -4492,7 +4524,7 @@
                     set index [lsearch -exact $unsorted_ports $port]
                     set unsorted_ports [lreplace $unsorted_ports $index $index]
 
-                    # remove edges 
+                    # remove edges
                     foreach target $revadjlist($port) {
                         set index [lsearch -exact $adjlist($target) $port]
                         set adjlist($target) [lreplace $adjlist($target) $index $index]
@@ -4531,7 +4563,7 @@
             set portname [$port name]
             if {![info exists depscache(port:$portname)]} {
                 # set rev-upgrade options and nodeps if this is not the first run
-                set my_options(ports_revupgrade) "yes"
+                set my_options(ports_revupgrade) yes
                 unset -nocomplain my_options(ports_nodeps)
                 unset -nocomplain my_options(ports_revupgrade_second_run)
                 if {$broken_port_counts($portname) > 1} {
@@ -4542,8 +4574,7 @@
                 }
 
                 # call macports::upgrade with ports_revupgrade option to rebuild the port
-                set status [macports::upgrade $portname "port:$portname" \
-                    {} [array get my_options] depscache]
+                set status [macports::upgrade $portname port:$portname {} [array get my_options] depscache]
                 ui_debug "Rebuilding port $portname finished with status $status"
                 if {$status != 0} {
                     error "Error rebuilding $portname"
@@ -4551,7 +4582,7 @@
             }
         }
 
-        if {[info exists options(ports_dryrun)] && $options(ports_dryrun) == "yes"} {
+        if {[info exists options(ports_dryrun)] && $options(ports_dryrun) eq "yes"} {
             ui_warn "If this was no dry run, rev-upgrade would now run the checks again to find unresolved and newly created problems"
             return 0
         }
@@ -4584,21 +4615,21 @@
 proc macports::revupgrade_handle_special_paths {fname path} {
     set corrected_path $path
 
-    set loaderpath_idx [string first "@loader_path" $corrected_path]
+    set loaderpath_idx [string first @loader_path $corrected_path]
     if {$loaderpath_idx != -1} {
         set corrected_path [string replace $corrected_path $loaderpath_idx $loaderpath_idx+11 [file dirname $fname]]
     }
 
-    set executablepath_idx [string first "@executable_path" $corrected_path]
+    set executablepath_idx [string first @executable_path $corrected_path]
     if {$executablepath_idx != -1} {
         ui_debug "Ignoring loadcommand containing @executable_path in $fname"
-        error "@executable_path in loadcommand"
+        error {@executable_path in loadcommand}
     }
 
-    set rpath_idx [string first "@rpath" $corrected_path]
+    set rpath_idx [string first @rpath $corrected_path]
     if {$rpath_idx != -1} {
         ui_debug "Ignoring loadcommand containing @rpath in $fname"
-        error "@rpath in loadcommand"
+        error {@rpath in loadcommand}
     }
 
     return $corrected_path
@@ -4628,7 +4659,7 @@
             lappend adjlist($dep) [lindex $stack 0]
             # make this port the new last broken port by prepending it to the stack
             set stack [linsert $stack 0 $dep]
-            
+
             set is_broken_port true
         }
         if {![info exists visited($dep)]} {
@@ -4651,7 +4682,7 @@
         return 1
     } elseif {[info exists ping_cache($host)]} {
         # expire entries after 1 day
-        if {[expr [clock seconds] - [lindex $ping_cache($host) 1]] <= 86400} {
+        if {[clock seconds] - [lindex $ping_cache($host) 1] <= 86400} {
             return [lindex $ping_cache($host) 0]
         }
     }
@@ -4671,22 +4702,22 @@
         set archive_sites_conf_values {}
         set all_names {}
         array set defaults {applications_dir /Applications/MacPorts prefix /opt/local type tbz2}
-        set conf_file "${macports_conf_path}/archive_sites.conf"
+        set conf_file $macports_conf_path/archive_sites.conf
         set conf_options {applications_dir frameworks_dir name prefix type urls}
         if {[file isfile $conf_file]} {
             set fd [open $conf_file r]
             while {[gets $fd line] >= 0} {
                 if {[regexp {^(\w+)([ \t]+(.*))?$} $line match option ignore val] == 1} {
                     if {[lsearch -exact $conf_options $option] >= 0} {
-                        if {$option == "name"} {
+                        if {$option eq "name"} {
                             set cur_name $val
                             lappend all_names $val
                         } elseif {[info exists cur_name]} {
                             set trimmedval [string trim $val]
-                            if {$option == "urls"} {
+                            if {$option eq "urls"} {
                                 set processed_urls {}
                                 foreach url $trimmedval {
-                                    lappend processed_urls ${url}:nosubdir
+                                    lappend processed_urls $url:nosubdir
                                 }
                                 lappend archive_sites_conf_values portfetch::mirror_sites::sites($cur_name) $processed_urls
                                 set sites($cur_name) $processed_urls
@@ -4718,8 +4749,8 @@
                 }
                 if {![info exists sites($cur_name)]} {
                     ui_warn "archive_sites.conf: no urls set for $cur_name"
-                    set sites($cur_name) ""
-                    lappend archive_sites_conf_values portfetch::mirror_sites::sites($cur_name) ""
+                    set sites($cur_name) {}
+                    lappend archive_sites_conf_values portfetch::mirror_sites::sites($cur_name) {}
                 }
             }
         }


More information about the macports-dev mailing list