define_proc_attributes和parse_proc_arguments的原理分析,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。
define_proc_attributes
和parse_proc_arguments命令能够扩展tcl语言中proc的功能,创建和Synopsys命令一样具有help和属性的命令。•可以使用info body命令查看proc的内容•被放置在Procedures 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]
-info info_text
指定与help命令或者-help选项一起使用的help文本-define_args arg_defs
指定proc参数的help文本及其属性-dont_abbrev
无论sh_command_abbrev_mode变量设置什么,都防止使用proc的名称缩写可以使用-define_args选项为该proc的参数指定help文本,并定义参数的数据类型和属性。-define_args的参数是列表的列表。
每个列表元素指定proc参数的属性arg_name 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 -verbose plus Usage: plus # Add two numbersa (first addend)b (second addend)
parse_proc_arguments命令可解析传递给proc的使用define_proc_attributes命令定义的参数。通常,parse_proc_arguments是proc中第一个调用的命令来验证参数。
不能在proc外使用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接受各种类型的参数,然后打印出来。info body procedure_nameinfo args procedure_nameproc_body procedure_nameproc_args procedure_name
如果不使用parse_proc_arguments命令,则proc将无法响应-help选项。
但是,始终可以使用help命令。关于define_proc_attributes和parse_proc_arguments的原理分析问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注天达云行业资讯频道了解更多相关知识。