[119177] trunk/base/src

cal at macports.org cal at macports.org
Fri Apr 18 15:35:29 PDT 2014


Revision: 119177
          https://trac.macports.org/changeset/119177
Author:   cal at macports.org
Date:     2014-04-18 15:35:29 -0700 (Fri, 18 Apr 2014)
Log Message:
-----------
base: validate ui_message args, add quoting, simplify const proc in port client, patch by Gustaf Neumann

See https://lists.macosforge.org/pipermail/macports-dev/2014-April/026527.html.

Modified Paths:
--------------
    trunk/base/src/macports1.0/macports.tcl
    trunk/base/src/port/port.tcl

Modified: trunk/base/src/macports1.0/macports.tcl
===================================================================
--- trunk/base/src/macports1.0/macports.tcl	2014-04-18 22:29:55 UTC (rev 119176)
+++ trunk/base/src/macports1.0/macports.tcl	2014-04-18 22:35:29 UTC (rev 119177)
@@ -205,6 +205,24 @@
 
 proc ui_message {priority prefix phase args} {
     global macports::channels ::debuglog macports::current_phase
+
+    # 
+    # validate $args
+    #
+    switch [llength $args] {
+       0 - 1 {}
+       2 {
+           if {[lindex $args 0] ne {-nonewline}} {
+               set hint "error: when 5 arguments are given, 2nd last must be \"-newnewline\""
+               error "$hint\nusage: ui_message priority prefix phase ?-nonewline? string"
+           }
+       }
+       default {
+           set hint "error: too many arguments specified"
+           error "$hint\nusage: ui_message priority prefix phase ?-nonewline? string"
+       }
+    } 
+
     foreach chan $macports::channels($priority) {
         if {[info exists ::debuglog] && ($chan eq {debuglog})} {
             set chan $::debuglog
@@ -2669,7 +2687,7 @@
 
                     switch -- $matchstyle {
                         exact {
-                            if {$case_sensitive eq yes} {
+                            if {$case_sensitive eq "yes"} {
                                 set compres [string compare $pattern $target]
                             } else {
                                 set compres [string compare -nocase $pattern $target]
@@ -2677,14 +2695,14 @@
                             set matchres [expr {0 == $compres}]
                         }
                         glob {
-                            if {$case_sensitive eq yes} {
+                            if {$case_sensitive eq "yes"} {
                                 set matchres [string match $pattern $target]
                             } else {
                                 set matchres [string match -nocase $pattern $target]
                             }
                         }
                         regexp {
-                            if {$case_sensitive eq yes} {
+                            if {$case_sensitive eq "yes"} {
                                 set matchres [regexp -- $pattern $target]
                             } else {
                                 set matchres [regexp -nocase -- $pattern $target]
@@ -4111,7 +4129,7 @@
         }
     }
 
-    if {[info exists uninstall_later] && $uninstall_later eq yes} {
+    if {[info exists uninstall_later] && $uninstall_later eq "yes"} {
         foreach i $ilist {
             set version [lindex $i 1]
             set revision [lindex $i 2]
@@ -4556,7 +4574,7 @@
                         break;
                     }
 
-                    if {$libarch_found eq 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"

Modified: trunk/base/src/port/port.tcl
===================================================================
--- trunk/base/src/port/port.tcl	2014-04-18 22:29:55 UTC (rev 119176)
+++ trunk/base/src/port/port.tcl	2014-04-18 22:35:29 UTC (rev 119177)
@@ -149,18 +149,9 @@
 # @param name variable name
 # @param value constant variable value
 proc const {name args} {
-    interp alias {} $name {} _const [expr $args]
+    proc $name {} [list return [expr $args]]
 }
 
-##
-# Helper function to define constants
-#
-# @see const
-proc _const value {
-    return $value
-}
-
-
 # Format an integer representing bytes using given units
 proc bytesize {siz {unit {}} {format {%.3f}}} {
     if {$unit == {}} {
@@ -4909,7 +4900,7 @@
         variable showTimeThreshold
         variable showPercentageThreshold
 
-        if {$show eq yes} {
+        if {$show eq "yes"} {
             return yes
         } else {
             if {[expr {[clock milliseconds] - $startTime}] > $showTimeThreshold &&
@@ -4946,7 +4937,7 @@
                 # the for loop is a simple hack because Tcl 8.4 doesn't have
                 # lassign
                 foreach {now total} $args {
-                    if {[showProgress $now $total] eq yes} {
+                    if {[showProgress $now $total] eq "yes"} {
                         set barPrefix "      "
                         set barPrefixLen [string length $barPrefix]
                         if {$total != 0} {
@@ -4998,7 +4989,7 @@
                 # the for loop is a simple hack because Tcl 8.4 doesn't have
                 # lassign
                 foreach {type total now speed} $args {
-                    if {[showProgress $now $total] eq yes} {
+                    if {[showProgress $now $total] eq "yes"} {
                         set barPrefix "      "
                         set barPrefixLen [string length $barPrefix]
                         if {$total != 0} {
@@ -5047,7 +5038,7 @@
         # Subtract the width of the percentage output, also subtract the two
         # characters [ and ] bounding the progress bar.
         set percentageWidth 8
-        set barWidth      [expr entier($width) - $percentageWidth - 2]
+        set barWidth      [expr {entier($width) - $percentageWidth - 2}]
 
         # Map the range (0, $total) to (0, 4 * $width) where $width is the maximum
         # numebr of characters to be printed for the progress bar. Multiply the
@@ -5120,7 +5111,7 @@
         }
 
         # Format the percentage using the space that has been reserved for it
-        set percentagesuffix [format " %[expr $percentageWidth - 3].1f %%" $percentage]
+        set percentagesuffix [format " %[expr {$percentageWidth - 3}].1f %%" $percentage]
 
         puts -nonewline "\r${prefix}\[${progressbar}\]${percentagesuffix}${suffix}"
         flush stdout
@@ -5286,7 +5277,7 @@
 }
 
 if {[isatty stdout]
-    && $portclient::progress::hasTermAnsiSend eq yes
+    && $portclient::progress::hasTermAnsiSend eq "yes"
     && (![info exists ui_options(ports_quiet)] || $ui_options(ports_quiet) ne "yes")} {
     set ui_options(progress_download) portclient::progress::download
     set ui_options(progress_generic)  portclient::progress::generic
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20140418/e2147110/attachment.html>


More information about the macports-changes mailing list