<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[119632] trunk/base/src/macports1.0/macports_dlist.tcl</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="https://trac.macports.org/changeset/119632">119632</a></dd>
<dt>Author</dt> <dd>cal@macports.org</dd>
<dt>Date</dt> <dd>2014-05-02 15:10:47 -0700 (Fri, 02 May 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>base: macports_dlist.tcl: avoid eval</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbasesrcmacports10macports_dlisttcl">trunk/base/src/macports1.0/macports_dlist.tcl</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbasesrcmacports10macports_dlisttcl"></a>
<div class="modfile"><h4>Modified: trunk/base/src/macports1.0/macports_dlist.tcl (119631 => 119632)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/base/src/macports1.0/macports_dlist.tcl        2014-05-02 20:21:58 UTC (rev 119631)
+++ trunk/base/src/macports1.0/macports_dlist.tcl        2014-05-02 22:10:47 UTC (rev 119632)
</span><span class="lines">@@ -17,7 +17,7 @@
</span><span class="cx"> # 3. Neither the name of Apple Inc. nor the names of its contributors
</span><span class="cx"> #    may be used to endorse or promote products derived from this software
</span><span class="cx"> #    without specific prior written permission.
</span><del>-# 
</del><ins>+#
</ins><span class="cx"> # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot;
</span><span class="cx"> # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
</span><span class="cx"> # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
</span><span class="lines">@@ -55,21 +55,21 @@
</span><span class="cx"> 
</span><span class="cx"> # dlist_match_multi
</span><span class="cx"> # Returns all dependency entries for which the entry's value for 'key' exactly matches the given 'value'.
</span><del>-#        dlist - the dependency list to search
-#        criteria - the key/value pairs to compare
</del><ins>+#   dlist - the dependency list to search
+#   criteria - the key/value pairs to compare
</ins><span class="cx"> 
</span><span class="cx"> proc dlist_match_multi {dlist criteria} {
</span><span class="cx">         set result {}
</span><span class="cx">         foreach ditem $dlist {
</span><del>-            set match 1
-            foreach {key value} $criteria {
-                    if {[ditem_key $ditem $key] != $value} {
-                            set match 0
-                            break
-                    }
</del><ins>+                set match 1
+                foreach {key value} $criteria {
+                        if {[ditem_key $ditem $key] != $value} {
+                                set match 0
+                                break
+                        }
</ins><span class="cx">                 }
</span><span class="cx">                 if {$match} {
</span><del>-                    lappend result $ditem
</del><ins>+                        lappend result $ditem
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx">         return $result
</span><span class="lines">@@ -77,9 +77,9 @@
</span><span class="cx"> 
</span><span class="cx"> # dlist_search
</span><span class="cx"> # Returns all dependency entries whose 'key' contains 'value'.
</span><del>-#        dlist - the dependency list to search
-#        key   - the key to compare: Requires, Provides, et al.
-#        value - the value to compare
</del><ins>+#   dlist - the dependency list to search
+#   key   - the key to compare: Requires, Provides, et al.
+#   value - the value to compare
</ins><span class="cx"> 
</span><span class="cx"> proc dlist_search {dlist key value} {
</span><span class="cx">         set result {}
</span><span class="lines">@@ -93,22 +93,22 @@
</span><span class="cx"> 
</span><span class="cx"> # dlist_delete
</span><span class="cx"> # Deletes the specified ditem from the dlist.
</span><del>-#        dlist - the list to search
-#        ditem - the item to delete
</del><ins>+#   dlist - the list to search
+#   ditem - the item to delete
</ins><span class="cx"> proc dlist_delete {dlist ditem} {
</span><del>-    upvar $dlist uplist
-    set ix [lsearch -exact $uplist $ditem]
-    if {$ix &gt;= 0} {
</del><ins>+        upvar $dlist uplist
+        set ix [lsearch -exact $uplist $ditem]
+        if {$ix &gt;= 0} {
</ins><span class="cx">                 set uplist [lreplace $uplist $ix $ix]
</span><del>-    }
</del><ins>+        }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> # dlist_has_pending
</span><span class="cx"> # Returns true if the dlist contains ditems
</span><span class="cx"> # which will provide one of the specified names,
</span><span class="cx"> # and thus are still &quot;pending&quot;.
</span><del>-#        dlist  - the dependency list to search
-#        tokens - the list of pending tokens to check for
</del><ins>+#   dlist  - the dependency list to search
+#   tokens - the list of pending tokens to check for
</ins><span class="cx"> 
</span><span class="cx"> proc dlist_has_pending {dlist tokens} {
</span><span class="cx">         foreach token $tokens {
</span><span class="lines">@@ -153,9 +153,9 @@
</span><span class="cx"> 
</span><span class="cx"> # ditem_key
</span><span class="cx"> # Sets and returns the given key of the dependency item.
</span><del>-#        ditem - the dependency item to operate on
-#        key   - the key to set
-#        value - optional value to set the key to
</del><ins>+#   ditem - the dependency item to operate on
+#   key   - the key to set
+#   value - optional value to set the key to
</ins><span class="cx"> 
</span><span class="cx"> proc ditem_key {ditem args} {
</span><span class="cx">         set nbargs [llength $args]
</span><span class="lines">@@ -170,40 +170,40 @@
</span><span class="cx"> 
</span><span class="cx"> # ditem_append
</span><span class="cx"> # Appends the value to the given key of the dependency item.
</span><del>-#        ditem - the dependency item to operate on
-#        key   - the key to append to
-#        value - the value to append to the key
</del><ins>+#   ditem - the dependency item to operate on
+#   key   - the key to append to
+#   value - the value to append to the key
</ins><span class="cx"> 
</span><span class="cx"> proc ditem_append {ditem key args} {
</span><del>-        eval &quot;return \[macports_dlist::ditem_append $ditem $key $args\]&quot;
</del><ins>+        return [macports_dlist::ditem_append $ditem $key {*}$args]
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> # ditem_append_unique
</span><span class="cx"> # Appends the value to the given key of the dependency item if
</span><span class="cx"> # they were not there yet.
</span><del>-#        ditem - the dependency item to operate on
-#        key   - the key to append to
-#        value - the value to append to the key
</del><ins>+#   ditem - the dependency item to operate on
+#   key   - the key to append to
+#   value - the value to append to the key
</ins><span class="cx"> 
</span><span class="cx"> proc ditem_append_unique {ditem key args} {
</span><del>-        eval &quot;return \[macports_dlist::ditem_append_unique $ditem $key $args\]&quot;
</del><ins>+        return [macports_dlist::ditem_append_unique $ditem $key {*}$args]
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> # ditem_contains
</span><span class="cx"> # Tests whether the ditem key contains the specified value;
</span><span class="cx"> # or if the value is omitted, tests whether the key exists.
</span><del>-#        ditem - the dependency item to test
-#        key   - the key to examine
-#        value - optional value to search for in the key
</del><ins>+#   ditem - the dependency item to test
+#   key   - the key to examine
+#   value - optional value to search for in the key
</ins><span class="cx"> proc ditem_contains {ditem key args} {
</span><del>-        eval &quot;return \[macports_dlist::ditem_contains $ditem $key $args\]&quot;
</del><ins>+        return [macports_dlist::ditem_contains $ditem $key {*}$args]
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> # dlist_append_dependents
</span><span class="cx"> # Returns the ditems which are dependents of the ditem specified.
</span><del>-#        dlist - the dependency list to search
-#        ditem - the item which itself, and its dependents should be selected
-#        result - used for recursing, pass empty initially.
</del><ins>+#   dlist - the dependency list to search
+#   ditem - the item which itself, and its dependents should be selected
+#   result - used for recursing, pass empty initially.
</ins><span class="cx"> 
</span><span class="cx"> proc dlist_append_dependents {dlist ditem result} {
</span><span class="cx">         # Only append things if the root item is not in the list.
</span><span class="lines">@@ -233,9 +233,9 @@
</span><span class="cx"> # on unfulfilled tokens in the Uses key.  However these items
</span><span class="cx"> # will eventually be returned if there are no alternatives.
</span><span class="cx"> # Soft-dependencies can be implemented in this way.
</span><del>-#        dlist      - the dependency list to select from
-#        statusdict - the status dictionary describing the history
-#                     of the dependency list.
</del><ins>+#   dlist      - the dependency list to select from
+#   statusdict - the status dictionary describing the history
+#                of the dependency list.
</ins><span class="cx"> 
</span><span class="cx"> proc dlist_get_next {dlist statusdict} {
</span><span class="cx">         upvar $statusdict upstatus
</span><span class="lines">@@ -278,14 +278,14 @@
</span><span class="cx"> # ditems are eligible to run (the selector returns {}) then
</span><span class="cx"> # dlist_eval will exit with a list of the remaining ditems,
</span><span class="cx"> # or {} if all ditems were evaluated.
</span><del>-#        dlist    - the dependency list to evaluate
-#        testcond - test condition to populate the status dictionary
-#                   should return {-1, 0, 1}
-#        handler  - the handler to invoke on each ditem
-#        canfail  - If 1, then progress will not stop when a failure
-#                   occures; if 0, then dlist_eval will return on the
-#                   first failure
-#        selector - the selector for determining eligibility
</del><ins>+#   dlist    - the dependency list to evaluate
+#   testcond - test condition to populate the status dictionary
+#              should return {-1, 0, 1}
+#   handler  - the handler to invoke on each ditem
+#   canfail  - If 1, then progress will not stop when a failure
+#              occures; if 0, then dlist_eval will return on the
+#              first failure
+#   selector - the selector for determining eligibility
</ins><span class="cx"> 
</span><span class="cx"> proc dlist_eval {dlist testcond handler {canfail &quot;0&quot;} {selector &quot;dlist_get_next&quot;}} {
</span><span class="cx">         array set statusdict [list]
</span><span class="lines">@@ -294,7 +294,7 @@
</span><span class="cx">         # can evaluate to true.
</span><span class="cx">         if {$testcond ne &quot;&quot;} {
</span><span class="cx">                 foreach ditem $dlist {
</span><del>-                        if {[eval &quot;expr \[\$testcond \$ditem\] == 1&quot;]} {
</del><ins>+                        if {[expr [$testcond $ditem]]} {
</ins><span class="cx">                                 foreach token [ditem_key $ditem provides] {
</span><span class="cx">                                         set statusdict($token) 1
</span><span class="cx">                                 }
</span><span class="lines">@@ -308,14 +308,14 @@
</span><span class="cx">                 set ditem [$selector $dlist statusdict]
</span><span class="cx"> 
</span><span class="cx">                 if {$ditem == {}} {
</span><del>-                    if {[llength $dlist] &gt; 0} {
-                        ui_debug &quot;dlist_eval: all entries in dependency list have unsatisfied dependencies; can't process&quot;
-                    }
</del><ins>+                        if {[llength $dlist] &gt; 0} {
+                                ui_debug &quot;dlist_eval: all entries in dependency list have unsatisfied dependencies; can't process&quot;
+                        }
</ins><span class="cx">                         break
</span><span class="cx">                 } else {
</span><span class="cx">                         # $handler should return a unix status code, 0 for success.
</span><span class="cx">                         # statusdict notation is 1 for success
</span><del>-                        if {[catch {eval &quot;$handler $ditem&quot;} result]} {
</del><ins>+                        if {[catch {$handler $ditem} result]} {
</ins><span class="cx">                                 puts $result
</span><span class="cx">                                 return $dlist
</span><span class="cx">                         }
</span><span class="lines">@@ -388,7 +388,7 @@
</span><span class="cx">         variable $ditem
</span><span class="cx">         set x [lindex [array get $ditem $key] 1]
</span><span class="cx">         if {$x != {}} {
</span><del>-                eval &quot;lappend x $args&quot;
</del><ins>+                lappend x {*}$args
</ins><span class="cx">         } else {
</span><span class="cx">                 set x $args
</span><span class="cx">         }
</span><span class="lines">@@ -400,7 +400,7 @@
</span><span class="cx">         variable $ditem
</span><span class="cx">         set x [lindex [array get $ditem $key] 1]
</span><span class="cx">         if {$x != {}} {
</span><del>-                eval &quot;lappend x $args&quot;
</del><ins>+                lappend x {*}$args
</ins><span class="cx">                 set x [lsort -unique $x]
</span><span class="cx">         } else {
</span><span class="cx">                 set x $args
</span><span class="lines">@@ -412,7 +412,7 @@
</span><span class="cx"> proc ditem_contains {ditem key args} {
</span><span class="cx">         variable $ditem
</span><span class="cx">         if {[llength $args] == 0} {
</span><del>-                eval &quot;return \[info exists ${ditem}($key)\]&quot;
</del><ins>+                return [info exists [subst $ditem]($key)]
</ins><span class="cx">         } else {
</span><span class="cx">                 set x [lindex [array get $ditem $key] 1]
</span><span class="cx">                 if {[llength $x] &gt; 0 &amp;&amp; [lsearch -exact $x [lindex $args 0]] != -1} {
</span><span class="lines">@@ -425,4 +425,3 @@
</span><span class="cx"> 
</span><span class="cx"> # End of macports_dlist namespace
</span><span class="cx"> }
</span><del>-
</del></span></pre>
</div>
</div>

</body>
</html>