温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

define_proc_attributes和parse_proc_arguments的原理分析

发布时间:2022-01-06 17:01:00 来源:亿速云 阅读:2222 作者:柒染 栏目:互联网科技

define_proc_attributes和parse_proc_arguments的原理分析,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

define_proc_attributes  和parse_proc_arguments命令能够扩展tcl语言中proc的功能,创建和Synopsys命令一样具有help和属性的命令。
创建一个新的proc时,它具有以下固有属性:

•可以使用info body命令查看proc的内容
•proc可以被修改
•可以使用proc名称的缩写
•被放置在Procedures command group
 
通过使用define_proc_attributes命令, 可以

•指定命令的help文本
•指定参数规则
•是否禁止查看和修改
•是否禁止名称缩写
•指定command group
 
define_proc_attributes
 
使用define_proc_attributes命令来定义和更改proc的属性。  其语法如下:
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的名称

-info info_text    指定与help命令或者-help选项一起使用的help文本

-define_args arg_defs  指定proc参数的help文本及其属性

-permanent   防止修改proc

-dont_abbrev    无论sh_command_abbrev_mode变量设置什么,都防止使用proc的名称缩写
 

可以使用-define_args选项为该proc的参数指定help文本,并定义参数的数据类型和属性。

-define_args的参数是列表的列表。  每个列表元素指定proc参数的属性
 
每个列表元素具有以下格式:
arg_name option_help value_help data_type attributes
arg_name  指定proc参数的名称  
option_help     参数的简短描述
value_help      参数值的简短描述
data_type     指定参数的数据类型  
attributes    指定参数的其他属性  
 
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命令定义的参数。
   define_proc_attributes和parse_proc_arguments的原理分析
通常,parse_proc_arguments是proc中第一个调用的命令来验证参数。  不能在proc外使用parse_proc_arguments命令。
 
parse_proc_arguments的语法是

parse_proc_arguments -args arg_list result_array
   
-args arg_list    指定传递给proc的参数列表。
result_array    指定数组存储解析的参数。

proc plus { args }  ## 关键字 args 表示可变个数的参数{parse_proc_arguments -args $args results    ## 将参数保存到数组中,数组名为 results,数组元素名字是参数名,元素值是参数值 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接受各种类型的参数,然后打印出来。
 
dc_shell> plus  a b
 a  b
 
另外可以通过
info body procedure_nameinfo args procedure_nameproc_body procedure_nameproc_args procedure_name

分别打印出proc的主体和参数
 
如果不使用parse_proc_arguments命令,则proc将无法响应-help选项。  但是,始终可以使用help命令。

关于define_proc_attributes和parse_proc_arguments的原理分析问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注亿速云行业资讯频道了解更多相关知识。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI