ere N is the # number of tokens in expanded. # # Example: # Given : # $line: sh ev man po test key # $expanded: show event manager policy # Execute: # parse_remove_expanded_tokens($line $expanded) # Result: # Return string: test key # proc ::cisco::lib::parse_remove_expanded_tokens { line expanded } { set num_line [llength $line] set num_expanded [llength $expanded] set add_space 0 if {[string index $line end] == " "} { set add_space 1 } if { $num_expanded >= $num_line } { set newstring "" } else { set newstring [lreplace $line 0 [expr $num_expanded - 1]] } return "tokens {$newstring} end_space $add_space" } # parse_check_token_in_help { token help } # Return 1 if the token already exists as an entry in the # passed in help buffer, else return 0. # Example: # Given : # help buffer $help: # newtoken newtoken help info. # pending pending help info # # $token: newtoken # Execute: # parse_check_token_in_help($token, $help) # Result: # 1 # proc ::cisco::lib::parse_check_token_in_help { token help } { foreach line [split $help '\n'] { if {$line == ""} { continue } if {[lindex $line 0] == $token} { return 1; } } return 0 } # parse_replace_token_help { token token_help help } # Given a help buffer, if token exists in the help buffer replace # token's help information with passed in token_help. # Send new help buffer to parser. # # Example: # Given : # help buffer ($help): # one help one # two help two # # $token: two # $token_help: new help two # Execute: # parse_replace_token_help($token, $token_help, $help) # Result: # Will result in a new help buffer: # one help one # two new help two # proc ::cisco::lib::parse_replace_token_help { tty token token_help help } { set newhelp "" foreach line [split $help '\n'] { if {$line == ""} { continue } if {[lindex $line 0] == $token} { append newhelp " $token\t$token_help\n" } else { append newhelp "$line\n" } } action_help_buffer_set tty $tty help $newhelp } # parse_insert_token_into_help_list { token help } # This routine handles token help where ONLY tokens are currently # listed in the help buffer. If the token already exists the # new token will not be added. # Send new help buffer to parser. # # Example: # Given : # help buffer ($help): # available registered pending # # $token: newtoken # Execute: # parse_insert_token_into_help_list($token, $help) # Result: # Will result in a new help buffer: # available newtoken registered pending # proc ::cisco::lib::parse_insert_token_into_help_list { tty token help } { set newhelp "" set found 0 foreach help_entry [split $help '\n\t'] { if {$token == $help_entry} { set found 1 } } if {$found == 0} { set newhelp $help append newhelp "$token\t" action_help_buffer_set tty $tty help $newhelp } } # parse_check_token_match { token line_entry } # Return 1 if token exactly matches line_entry # else return 0 # Example: # Given : # $line_entry: newtoken # $token: newtoken # Execute: # parse_check_token_match($token, $line_entry) # Result: # 1 # proc ::cisco::lib::parse_check_token_match { token line_entry } { set line_entry_len [string length $line_entry] set token_len [string length $token] if { $line_entry_len == 0 } { return 0 } if { $line_entry_len > $token_len } { return 0 } if { [string compare -length $line_entry_len $line_entry $token] == 0 } { return 1 } return 0 }