溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

define_proc_attributes和parse_proc_arguments的原理分析

發(fā)布時(shí)間:2022-01-06 17:01:00 來(lái)源:億速云 閱讀:2516 作者:柒染 欄目:互聯(lián)網(wǎng)科技

define_proc_attributes和parse_proc_arguments的原理分析,針對(duì)這個(gè)問(wèn)題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問(wèn)題的小伙伴找到更簡(jiǎn)單易行的方法。

define_proc_attributes  和parse_proc_arguments命令能夠擴(kuò)展tcl語(yǔ)言中proc的功能,創(chuàng)建和Synopsys命令一樣具有help和屬性的命令。
創(chuàng)建一個(gè)新的proc時(shí),它具有以下固有屬性:

?可以使用info body命令查看proc的內(nèi)容
?proc可以被修改
?可以使用proc名稱(chēng)的縮寫(xiě)
?被放置在Procedures command group
 
通過(guò)使用define_proc_attributes命令, 可以

?指定命令的help文本
?指定參數(shù)規(guī)則
?是否禁止查看和修改
?是否禁止名稱(chēng)縮寫(xiě)
?指定command group
 
define_proc_attributes
 
使用define_proc_attributes命令來(lái)定義和更改proc的屬性。  其語(yǔ)法如下:
define_proc_attributes proc_name    [-info info_text][-define_args arg_defs][-command_group group_name][-hide_body][-hidden][-permanent][-dont_abbrev]
proc_name      指定proc的名稱(chēng)

-info info_text    指定與help命令或者-help選項(xiàng)一起使用的help文本

-define_args arg_defs  指定proc參數(shù)的help文本及其屬性

-permanent   防止修改proc

-dont_abbrev    無(wú)論sh_command_abbrev_mode變量設(shè)置什么,都防止使用proc的名稱(chēng)縮寫(xiě)
 

可以使用-define_args選項(xiàng)為該proc的參數(shù)指定help文本,并定義參數(shù)的數(shù)據(jù)類(lèi)型和屬性。

-define_args的參數(shù)是列表的列表。  每個(gè)列表元素指定proc參數(shù)的屬性
 
每個(gè)列表元素具有以下格式:
arg_name option_help value_help data_type attributes
arg_name  指定proc參數(shù)的名稱(chēng)  
option_help     參數(shù)的簡(jiǎn)短描述
value_help      參數(shù)值的簡(jiǎn)短描述
data_type     指定參數(shù)的數(shù)據(jù)類(lèi)型  
attributes    指定參數(shù)的其他屬性  
 
define_proc_attributes Command Example  
proc plus {a b} { return [expr $a + $b] }  define_proc_attributes plus \  -info "Add two numbers" \  -define_args { {a "first addend" a stringrequired} \  {b "second addend" b stringrequired} }

dc_shell> help  plus
plus                 # Add two numbers
  
dc_shell> help -verbose plus    
Usage: plus # Add two numbersa (first addend)b (second addend)

dc_shell > plus 5 6    
11
   
 
parse_proc_arguments  
 
parse_proc_arguments命令可解析傳遞給proc的使用define_proc_attributes命令定義的參數(shù)。
   define_proc_attributes和parse_proc_arguments的原理分析
通常,parse_proc_arguments是proc中第一個(gè)調(diào)用的命令來(lái)驗(yàn)證參數(shù)。  不能在proc外使用parse_proc_arguments命令。
 
parse_proc_arguments的語(yǔ)法是

parse_proc_arguments -args arg_list result_array
   
-args arg_list    指定傳遞給proc的參數(shù)列表。
result_array    指定數(shù)組存儲(chǔ)解析的參數(shù)。

proc plus { args }  ## 關(guān)鍵字 args 表示可變個(gè)數(shù)的參數(shù){parse_proc_arguments -args $args results    ## 將參數(shù)保存到數(shù)組中,數(shù)組名為 results,數(shù)組元素名字是參數(shù)名,元素值是參數(shù)值 foreach argname [array names results] {echo " $results($argname)"}} define_proc_attributes plus \-info "echo two numbers" \-define_args {{a "first addend" a string required} \{b "second addend" b string required} }
   
plus顯示了parse_proc_arguments的使用。  plus接受各種類(lèi)型的參數(shù),然后打印出來(lái)。
 
dc_shell> plus  a b
 a  b
 
另外可以通過(guò)
info body procedure_nameinfo args procedure_nameproc_body procedure_nameproc_args procedure_name

分別打印出proc的主體和參數(shù)
 
如果不使用parse_proc_arguments命令,則proc將無(wú)法響應(yīng)-help選項(xiàng)。  但是,始終可以使用help命令。

關(guān)于define_proc_attributes和parse_proc_arguments的原理分析問(wèn)題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒(méi)有解開(kāi),可以關(guān)注億速云行業(yè)資訊頻道了解更多相關(guān)知識(shí)。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI