tcl使用笔记

tcl语法网站:http://www.tcl.tk/man/tcl8.5/TclCmd/contents.htm

1)拷贝文件

 set PRJ_HDL_DIR "../prj/hdl"
foreach filename [glob "../tsbs/smii_mtip/rtl/include/{*.verilog,*.v}"] {
    file copy $filename $PRJ_HDL_DIR
}

2)如何获取当前脚本文件的名称?

由于有时需要获得当前运行脚本的名称,可以参考 如下

http://blog.csdn.net/gllg1314/article/details/7695746

http://wiki.tcl.tk/1384

http://stackoverflow.com/questions/23285360/how-to-get-path-of-current-script

 While a script is being evaluated (but not necessarily while its procedures are being called) the current script name (strictly, whatever was passed to source or the C API equivalent, Tcl_EvalFile() and related) is the result of info script; it's highly advisable to normalise that to an absolute pathname so that any calls to cd don't change the interpretation.

Scripts that need the information tend to put something like this inside themselves:

# This is a *good* use of [variable]…
variable myLocation [file normalize [info script]]

They can then retrieve the value (or things derived from it) easily:

proc getResourceDirectory {} {
    variable myLocation
    return [file dirname $myLocation]

依据参考得到的代码:

set print echo
$print "----------------------------------------"
$print "  rs                                 - Re-Source startup file "
$print "  comp_afu_textswap       - Compile memcopy example "
$print "  sim                               - Start vsim"
$print "----------------------------------------"

variable My_File [file normalize [info script]]
# the above line can't be put in the rs{} procedure.

proc rs {} {
    variable My_File
    set filename [file tail $My_File]
    echo "current file is $filename"
    source $filename
}
 

需要指出的是

a.variable My_File [file normalize [info script]] 这句话不能放在rs procedure中,否则得到空字符

b.rs函数中的variable My_File就是全局变量的My_File的值

 

===========================

1)
#set PRJ_HDL_DIR {$PRJ_ROOT_DIR}/prj/hdl    则[ Line 3: extra characters after close-brace ]
#set PRJ_HDL_DIR "{$PRJ_ROOT_DIR}/prj/hdl"  则{}会被当成字符,当成了 {..}/prj/hdl"
#set PRJ_HDL_DIR ${PRJ_ROOT_DIR}/prj/hdl  correct!!!
#set PRJ_HDL_DIR "${PRJ_ROOT_DIR}/prj/hdl"  correct!!

2)
  {}里面不能有注释?

foreach pathname {1 2 3} ${
#    foreach filename [glob "../tsbs/smii_mtip/rtl/include/{*.verilog,*.v}"] {
    puts "pathname = $pathname"
#    foreach filename [glob "${pathname}{*.verilog,*.v}"] {
#    file copy $filename $PRJ_HDL_DIR
#    }
}  

Error: Failure when executing Tcl script. [ Line 10: can't read "
# foreach filename [glob "../tsbs/smii_mtip/rtl/include/{*.verilog,*.v": no such variable ]
Error: The Execute Script command failed.

3)

pathname = ${PRJ_ROOT_DIR}/tsbs/smii_mtip/rtl/include/
pathname = $PRJ_ROOT_DIR/tsbs/sgmii_mtip/rtl/include/
The Execute Script command succeeded.


{} 中间不能替换,但是foreach需要列表,其实是不需要,如下就能正确工作

set INCLUDE_PATH_ARRAY  "${PRJ_ROOT_DIR}/tsbs/smii_mtip/rtl/include/ $PRJ_ROOT_DIR/tsbs/sgmii_mtip/rtl/include/"
foreach pathname $INCLUDE_PATH_ARRAY {
    puts "pathname = $pathname"
}

 

转载于:https://www.cnblogs.com/e-shannon/p/5820993.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值