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"
    }

  • 相关阅读:
    stdin和STDIN_FILENO的区别
    运算放大器和仪表放大器有哪些区别?
    仪表放大器与运算放大器的区别是什么?
    如何将库文件移到另一个库
    altium designer 中器件原理图库中,将一个器件分成几部分是如何操作的?就是如何用part表示?
    linux串口基本编程
    WCF寄宿(Host)之自我寄宿(Self-Hosting)简单实例【Windows应用程序宿主】
    WCF寄宿(Host)之自我寄宿(Self-Hosting)简单实例【Console应用为宿主】
    GUI创建各常用控件(二)
    GUI创建各常用控件(一)
  • 原文地址:https://www.cnblogs.com/e-shannon/p/5820993.html
Copyright © 2011-2022 走看看