New Ticket     Tickets     Wiki     Browse Source     Timeline     Roadmap     Ticket Reports     Search

Changeset 79259


Ignore:
Timestamp:
06/07/11 02:38:40 (4 years ago)
Author:
jmr@…
Message:

allow abbreviation of actions (#27242)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/base/src/port/port.tcl

    r79167 r79259  
    38343834] 
    38353835 
     3836# Expand "action". 
     3837# Returns an action proc, or a list of matching action procs, or the action passed in 
     3838proc find_action { action } { 
     3839    global action_array 
     3840     
     3841    if { ! [info exists action_array($action)] } { 
     3842        set guess [guess_action $action] 
     3843        if { [info exists action_array($guess)] } { 
     3844            return $guess 
     3845        } 
     3846        return $guess 
     3847    } 
     3848     
     3849    return $action 
     3850} 
     3851 
     3852# Expand action 
     3853# If there's more than one match, return the next possibility 
    38363854proc find_action_proc { action } { 
     3855    global action_array 
     3856     
     3857    set action_proc "" 
     3858    if { [info exists action_array($action)] } { 
     3859        set action_proc [lindex $action_array($action) 0] 
     3860    } else { 
     3861        set action [complete_action $action] 
     3862        if { [info exists action_array($action)] } { 
     3863            set action_proc [lindex $action_array($action) 0] 
     3864        } 
     3865    } 
     3866     
     3867    return $action_proc 
     3868} 
     3869 
     3870proc get_action_proc { action } { 
    38373871    global action_array 
    38383872     
     
    41214155         
    41224156        # Find an action to execute 
    4123         set action_proc [find_action_proc $action] 
    4124         if { $action_proc == "" } { 
    4125             puts "Unrecognized action \"$action\"" 
     4157        set actions [find_action $action] 
     4158        if {[llength $actions] == 1} { 
     4159            set action [lindex $actions 0] 
     4160            set action_proc [get_action_proc $action] 
     4161        } else { 
     4162            if {[llength $actions] > 1} { 
     4163                puts "Ambiguous action \"$action\": could be any of {$actions}." 
     4164            } else { 
     4165                puts "Unrecognized action \"$action\"" 
     4166            } 
    41264167            set action_status 1 
    41274168            break 
     
    42134254 
    42144255 
     4256# return text action beginning with $text 
    42154257proc complete_action { text state } {    
    42164258    global action_array 
     
    42284270} 
    42294271 
     4272# return all actions beginning with $text 
     4273proc guess_action { text } {    
     4274    global action_array 
     4275 
     4276    return [array names action_array "[string tolower $text]*"] 
     4277 
     4278    if { [llength $complete_choices ] == 1 } { 
     4279        return [lindex $complete_choices 0] 
     4280    } 
     4281 
     4282    return {} 
     4283} 
    42304284 
    42314285proc attempt_completion { text word start end } { 
Note: See TracChangeset for help on using the changeset viewer.