zoukankan      html  css  js  c++  java
  • 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"
    }

  • 相关阅读:
    [rrdtool]监控和自己主动绘图,简单的监控.md
    64位Windows操作系统中的注冊表
    (转载)正向代理与反向代理的区别
    (转载)数据库表分割技术浅析(水平分割/垂直分割/库表散列)
    JavaWeb学习总结(四十九)——简单模拟Sping MVC
    JNDI学习总结(三)——Tomcat下使用Druid配置JNDI数据源
    JNDI学习总结(二)——Tomcat下使用C3P0配置JNDI数据源
    JNDI学习总结(一)——JNDI数据源的配置
    哈佛图书馆墙上的训言
    少走弯路的10条忠告
  • 原文地址:https://www.cnblogs.com/e-shannon/p/5820993.html
Copyright © 2011-2022 走看看