<pre style='margin:0'>
Joshua Root (jmroot) pushed a commit to branch master
in repository macports-base.
</pre>
<p><a href="https://github.com/macports/macports-base/commit/76e414b156a2d26d5a601ca4be7e1df49850bbdb">https://github.com/macports/macports-base/commit/76e414b156a2d26d5a601ca4be7e1df49850bbdb</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit 76e414b156a2d26d5a601ca4be7e1df49850bbdb
</span>Author: Joshua Root <jmr@macports.org>
AuthorDate: Tue Feb 6 15:36:50 2024 +1100
<span style='display:block; white-space:pre;color:#404040;'> Use dict for action_array and cmd_opts_array
</span>---
src/port/port.tcl | 88 +++++++++++++++++++++----------------------------------
1 file changed, 34 insertions(+), 54 deletions(-)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/port/port.tcl b/src/port/port.tcl
</span><span style='display:block; white-space:pre;color:#808080;'>index 9940533cf..3871a08af 100755
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/port/port.tcl
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/port/port.tcl
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1464,18 +1464,15 @@ proc parsePortSpec { vername varname optname {remainder ""} } {
</span> ##########################################
proc action_get_usage { action } {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- global action_array cmd_opts_array
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if {[info exists action_array($action)]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {[dict exists $::action_array $action]} {
</span> set cmds ""
<span style='display:block; white-space:pre;background:#ffe0e0;'>- if {[info exists cmd_opts_array($action)]} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- foreach opt $cmd_opts_array($action) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {[dict exists $::cmd_opts_array $action]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ foreach opt [dict get $::cmd_opts_array $action] {
</span> if {[llength $opt] == 1} {
set name $opt
set optc 0
} else {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set name [lindex $opt 0]
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- set optc [lindex $opt 1]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ lassign $opt name optc
</span> }
append cmds " --$name"
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -3926,15 +3923,13 @@ proc action_exit { action portlist opts } {
</span> # Command Parsing
##########################################
proc moreargs {} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- global cmd_argn cmd_argc
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- return [expr {$cmd_argn < $cmd_argc}]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return [expr {$::cmd_argn < $::cmd_argc}]
</span> }
proc lookahead {} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- global cmd_argn cmd_argc cmd_argv
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if {$cmd_argn < $cmd_argc} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- return [lindex $cmd_argv $cmd_argn]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {$::cmd_argn < $::cmd_argc} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return [lindex $::cmd_argv $::cmd_argn]
</span> } else {
return _EOF_
}
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -3942,8 +3937,7 @@ proc lookahead {} {
</span>
proc advance {} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- global cmd_argn
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- incr cmd_argn
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ incr ::cmd_argn
</span> }
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -3968,7 +3962,7 @@ const ACTION_ARGS_NONE 0
</span> const ACTION_ARGS_STRINGS 1
const ACTION_ARGS_PORTS 2
<span style='display:block; white-space:pre;background:#ffe0e0;'>-array set action_array [list \
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+set action_array [dict create \
</span> usage [list action_usage [ACTION_ARGS_STRINGS]] \
help [list action_help [ACTION_ARGS_STRINGS]] \
\
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -4064,31 +4058,25 @@ set shellmode_action_list [list cd exit quit]
</span> # Expand "action".
# Returns a list of matching actions.
proc find_action { action } {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- global action_array
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if {![info exists action_array($action)]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {![dict exists $::action_array $action]} {
</span> # list of actions that are valid for this mode
<span style='display:block; white-space:pre;background:#ffe0e0;'>- global action_list
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if {![info exists action_list]} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- global ui_options shellmode_action_list
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if {![info exists ui_options(ports_commandfiles)]} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- set action_list [lsearch -regexp -all -inline -not [array names action_array] ^[join $shellmode_action_list {$|^}]$]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {![info exists ::action_list]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {![info exists ::ui_options(ports_commandfiles)]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set ::action_list [lsearch -regexp -all -inline -not [dict keys $::action_array] ^[join $::shellmode_action_list {$|^}]$]
</span> } else {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set action_list [array names action_array]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set ::action_list [dict keys $::action_array]
</span> }
}
<span style='display:block; white-space:pre;background:#ffe0e0;'>- return [lsearch -glob -inline -all $action_list [string tolower $action]*]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return [lsearch -glob -inline -all $::action_list [string tolower $action]*]
</span> }
return $action
}
proc get_action_proc { action } {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- global action_array
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span> set action_proc ""
<span style='display:block; white-space:pre;background:#ffe0e0;'>- if { [info exists action_array($action)] } {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- set action_proc [lindex $action_array($action) 0]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {[dict exists $::action_array $action]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set action_proc [lindex [dict get $::action_array $action] 0]
</span> }
return $action_proc
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -4101,11 +4089,9 @@ proc get_action_proc { action } {
</span> # [ACTION_ARGS_STRINGS] Expects some strings as text argument
# [ACTION_ARGS_PORTS] Wants an expanded list of ports as text argument
proc action_needs_portlist { action } {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- global action_array
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span> set ret 0
<span style='display:block; white-space:pre;background:#ffe0e0;'>- if {[info exists action_array($action)]} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- set ret [lindex $action_array($action) 1]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {[dict exists $::action_array $action]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set ret [lindex [dict get $::action_array $action] 1]
</span> }
return $ret
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -4113,10 +4099,10 @@ proc action_needs_portlist { action } {
</span>
# cmd_opts_array specifies which arguments the commands accept
# Commands not listed here do not accept any arguments
<span style='display:block; white-space:pre;background:#ffe0e0;'>-# Syntax if {option argn}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+# Syntax is {option argn}
</span> # Where option is the name of the option and argn specifies how many arguments
# this argument takes
<span style='display:block; white-space:pre;background:#ffe0e0;'>-array set cmd_opts_array {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+set cmd_opts_array [dict create {*}{
</span> edit {{editor 1}}
info {category categories conflicts depends_fetch depends_extract
depends_patch
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -4153,7 +4139,7 @@ array set cmd_opts_array {
</span> reclaim {enable-reminders disable-reminders}
fetch {no-mirrors}
bump {patch}
<span style='display:block; white-space:pre;background:#ffe0e0;'>-}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}]
</span>
##
# Checks whether the given option is valid
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -4162,18 +4148,16 @@ array set cmd_opts_array {
</span> # @param option the prefix of the option to check
# @return list of pairs {name argc} for all matching options
proc cmd_option_matches {action option} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- global cmd_opts_array
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span> # This could be so easy with lsearch -index,
# but that's only available as of Tcl 8.5
<span style='display:block; white-space:pre;background:#ffe0e0;'>- if {![info exists cmd_opts_array($action)]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {![dict exists $::cmd_opts_array $action]} {
</span> return [list]
}
set result [list]
<span style='display:block; white-space:pre;background:#ffe0e0;'>- foreach item $cmd_opts_array($action) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ foreach item [dict get $::cmd_opts_array $action] {
</span> if {[llength $item] == 1} {
set name $item
set argc 0
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -4503,24 +4487,22 @@ proc process_cmd { argv } {
</span>
proc complete_portname { text state } {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- global complete_choices complete_position
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span> if {$state == 0} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set complete_position 0
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- set complete_choices [list]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set ::complete_position 0
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set ::complete_choices [list]
</span>
# Build a list of ports with text as their prefix
if {[catch {set res [mportsearch "${text}*" false glob]} result]} {
ui_debug $::errorInfo
<span style='display:block; white-space:pre;background:#ffe0e0;'>- fatal "search for portname $pattern failed: $result"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ fatal "search for portname $text failed: $result"
</span> }
foreach {name info} $res {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- lappend complete_choices $name
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ lappend ::complete_choices $name
</span> }
}
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set word [lindex $complete_choices $complete_position]
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- incr complete_position
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set word [lindex $::complete_choices $::complete_position]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ incr ::complete_position
</span>
return $word
}
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -4528,15 +4510,13 @@ proc complete_portname { text state } {
</span>
# return text action beginning with $text
proc complete_action { text state } {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- global action_array complete_choices complete_position
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span> if {$state == 0} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set complete_position 0
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- set complete_choices [array names action_array "[string tolower $text]*"]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set ::complete_position 0
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set ::complete_choices [dict keys $::action_array [string tolower $text]*]
</span> }
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set word [lindex $complete_choices $complete_position]
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- incr complete_position
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set word [lindex $::complete_choices $::complete_position]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ incr ::complete_position
</span>
return $word
}
</pre><pre style='margin:0'>
</pre>