⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c-shell7.html

📁 vxworks相关论文
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><link rel="STYLESHEET" type="text/css" href="wrs.css"><title>    Shell   </title></head><body bgcolor="FFFFFF"><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a><a href="GuideIX.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="c-shell.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-shell6.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-shell8.html"><img border="0" alt="[Next]" src="icons/next.gif"></a></p><font face="Helvetica, sans-serif" class="sans"><h3 class="H2"><i><a name="86665">6.7  &nbsp;&nbsp;Tcl: Shell Interpretation</a></i></h3></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="86667"> </a>The shell has a Tcl interpreter interface as well as the C interpreter interface. This section illustrates some uses of the shell Tcl interpreter. If you are not familiar with Tcl, we suggest you skip this section and return to it after you have gotten acquainted with Tcl. (For an outline of Tcl, see <a href="x-tclsumm.html#84659"><i class="title">B.&nbsp;Tcl</i></a>.) In the interim, you can do a great deal of development work with the shell C interpreter alone. </p><dd><p class="Body"><a name="86672"> </a>To toggle between the Tcl interpreter and the C interpreter in the shell, type the single character<b> </b><b>?</b>. The shell prompt changes to remind you of the interpreter state: the prompt <b>-&gt;</b> indicates the C interpreter is listening, and the prompt <b>tcl&gt;</b> indicates the Tcl interpreter is listening.<sup><a href="#foot"><b class="FootnoteMarker">1</b></a></sup> For example, in the following interaction we use the C interpreter to define a variable in the symbol table, then switch into the Tcl interpreter to define a similar Tcl variable in the shell itself, and finally switch back to the C interpreter:</p><dl class="margin"><dd><pre class="Code2"><b><a name="86678"></b><tt class="output">-&gt; </tt><b>hello="hi there" </b><tt class="output">new symbol "hello" added to symbol table. hello = 0x3616e8: value = 3544824 = 0x3616f8 = hello + 0x10 -&gt; </tt><b>? </b><tt class="output">tcl&gt; </tt><b>set hello {hi there} </b><tt class="output">hi there tcl&gt; </tt><b>? </b><tt class="output">-&gt; </tt><b></a></b></pre></dl><dd><p class="Body"><a name="86681"> </a><b class="command"></b>If you start <b class="command">windsh</b> from the Windows command line, you can also use the option <b class="command">-Tclmode</b> (or <b class="command">-T</b>) to start with the Tcl interpreter rather than the C interpreter.</p><dd><p class="Body"><a name="86682"> </a>Using the shell's Tcl interface allows you to extend the shell with your own procedures, and also provides a set of control structures which you can use interactively. The Tcl interpreter also acts as a host shell, giving you access to Windows command-line utilities on your development host.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="86685">6.7.1  &nbsp;&nbsp;Tcl: Controlling the Target</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="86687"> </a>In the Tcl interpreter, you can create custom commands, or use Tcl control structures for repetitive tasks, while using the building blocks that allow the C interpreter and the WindSh commands to control the target remotely. These building blocks as a whole are called the <b class="command">wtxtcl</b> procedures. </p><dd><p class="Body"><a name="86689"> </a>For example, <b class="tclProc">wtxMemRead</b> returns the contents of a block of target memory (given its starting address and length). That command in turn uses a special memory-block datatype designed to permit memory transfers without unnecessary Tcl data conversions. The following example uses <b class="tclProc">wtxMemRead</b>, together with the memory-block routine <b class="tclProc">memBlockWriteFile</b>, to write a Tcl procedure that dumps target memory to a host file. Because almost all the work is done on the host, this procedure works whether or not the target run-time environment contains I/O libraries or any networked access to the host file system.</p><dl class="margin"><dd><pre class="Code2"><b><a name="86690"># tgtMemDump - copy target memory to host file # # SYNOPSIS: #  tgtMemDump hostfile start nbytes</a></b><dd> <b><a name="86692">proc tgtMemDump {fname start nbytes} {     set memHandle [wtxMemRead $start $nbytes]     memBlockWriteFile $memHandle $fname }</a></b></pre></dl><dd><p class="Body"><a name="86693"> </a>For reference information on the <b class="command">wtxtcl</b> routines available in the Tornado shell, see the <i class="title">Tornado API Guide</i> (or the <i class="title">Tornado API</i> entry in the <i class="title">Tornado Online Manuals</i>).</p><dd><p class="Body"><a name="86697"> </a>All of the commands defined for the C interpreter (<a href="c-shell2.html#99723"><i class="title">6.2.3&nbsp;Invoking Built-In Shell Routines</i></a>) are also available, with a double-underscore prefix, from the Tcl level; for example, to call <b class="routine"><i class="routine">i</i></b><b>(&nbsp;)</b>from the Tcl interpreter, run the Tcl procedure <b class="tclProc">__i</b>. However, in many cases, it is more convenient to call a <b class="command">wtxtcl</b> routine instead, because the WindSh commands are designed to operate in the C-interpreter context. For example, you can call the dynamic linker using <b class="tclProc">ld</b> from the Tcl interpreter, but the argument that names the object module may not seem intuitive: it is the address of a string stored on the target. It is more convenient to call the underlying <b class="command">wtxtcl</b> command. In the case of the dynamic linker, the underlying <b class="command">wtxtcl</b> command is <b class="tclProc">wtxObjModuleLoad</b>, which takes an ordinary Tcl string as its argument, as described in <i class="title">Tornado API Guide: WTX Tcl API</i>.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="86698">Tcl: Calling Target Routines</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="86700"> </a>The <b class="tclProc">shParse</b> utility allows you to embed calls to the C interpreter in Tcl expressions; the most frequent application is to call a single target routine, with the arguments specified (and perhaps capture the result). For example, the following sends a logging message to your VxWorks target console:</p><dl class="margin"><dd><pre class="Code2"><b><a name="86701"></b><tt class="output">tcl&gt; </tt><b>shParse {logMsg("Greetings from Tcl!\n")}  </b><tt class="output">32</tt><b></a></b></pre></dl><dd><p class="Body"><a name="86702"> </a>You can also use <b class="tclProc">shParse</b> to call WindSh commands more conveniently from the Tcl interpreter, rather than using their <b class="command">wtxtcl </b>building blocks. For example, the following is a convenient way to spawn a task from Tcl, using the C-interpreter command <b class="routine"><i class="routine">sp</i></b><b>(&nbsp;)</b>, if you do not remember the underlying <b class="command">wtxtcl</b> command:</p><dl class="margin"><dd><pre class="Code2"><b><a name="86704"></b><tt class="output">tcl&gt; </tt><b>shParse {sp appTaskBegin} </b><tt class="output">task spawned: id = 25e388, name = u1 0</tt><b></a></b></pre></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="86706">Tcl: Passing Values to Target Routines</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="86707"> </a>Because <b class="tclProc">shParse</b> accepts a single, ordinary Tcl string as its argument, you can pass values from the Tcl interpreter to C subroutine calls simply by using Tcl facilities to concatenate the appropriate values into a C expression. </p><dd><p class="Body"><a name="86709"> </a>For example, a more realistic way of calling <b class="routine"><i class="routine">logMsg</i></b><b>(&nbsp;)</b>from the Tcl interpreter would be to pass as its argument the value of a Tcl variable rather than a literal string. The following example evaluates a Tcl variable <b class="symbol_lc">tclLog</b> and inserts its value (with a newline appended) as the <b class="routine"><i class="routine">logMsg</i></b><b>(&nbsp;)</b> argument:</p><dl class="margin"><dd><pre class="Code2"><b><a name="86711"></b><tt class="output">tcl&gt; </tt><b>shParse "logMsg(\"$tclLog\\n\")" </b><tt class="output">32</tt><b></a></b></pre></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="86713">6.7.2  &nbsp;&nbsp;Tcl: Calling under C Control</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="86715"> </a><b></b>To dip quickly into Tcl and return immediately to the C interpreter, you can type a single line of Tcl prefixed with the <b>?</b> character (rather than using <b>?</b> by itself to toggle into Tcl mode). For example:</p><dl class="margin"><dd><pre class="Code2"><b><a name="86716"></b><tt class="output">-&gt; </tt><b>?set test wonder; puts "This is a $test." </b><tt class="output">This is a wonder.  -&gt; </tt><b></a></b></pre></dl><dd><p class="Body"><a name="86717"> </a>Notice that the <b>-&gt;</b> prompt indicates we are still in the C interpreter, even though we just executed a line of Tcl.</p></dl></dl><dl class="margin"><dd><p class="table" callout><table border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td valign="top" width="40"><br><img border="0" alt="*" src="icons/caution.gif"></td><td><hr><div class="CalloutCell"><a name="99400"><b class="symbol_UC"><font face="Helvetica, sans-serif" size="-1" class="sans">CAUTION:  </font></b></a>You may not embed Tcl evaluation inside a C expression; the<b> ?</b> prefix works only as the first nonblank character on a line, and passes the entire line following it to the Tcl interpreter.</div></td></tr><tr valign="top"><td></td><td><hr></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p callout><dl class="margin"><dd><p class="Body"><a name="86719"> </a>For example, you may occasionally want to use Tcl control structures to supplement the facilities of the C interpreter. Suppose you have an application under development that involves several collaborating tasks; in an interactive development session, you may need to restart the whole group of tasks repeatedly. You can define a Tcl variable with a list of all the task entry points, as follows:</p><dl class="margin"><dd><pre class="Code2"><b><a name="86720"></b><tt class="output">-&gt; </tt><b>? set appTasks {appFrobStart appGetStart appPutStart } </b><tt class="output">appFrobStart appGetStart appPutStart </tt><b></a></b></pre></dl><dd><p class="Body"><a name="86721"> </a>Then whenever you need to restart the whole list of tasks, you can use something like the following:</p><dl class="margin"><dd><pre class="Code2"><b><a name="86722"></b><tt class="output">-&gt; </tt><b>? foreach it $appTasks {shParse "sp($it)"} </b><tt class="output">task spawned: id = 25e388, name = u0 task spawned: id = 259368, name = u1 task spawned: id = 254348, name = u2 task spawned: id = 24f328, name = u3</tt><b></a></b></pre></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="86725">6.7.3  &nbsp;&nbsp;Tcl: Tornado Shell lnitialization</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="86727"> </a>When you execute an instance of the Tornado shell, it begins by looking for a file called <b class="file">.wind\windsh.tcl</b> in two places: first under <b class="file">c:\tornado</b>, and then in the directory specified by the <b class="symbol_UC">HOME</b> environment variable (if that environment variable is defined).  In each of these directories, if the file exists, the shell reads and executes its contents as Tcl expressions before beginning to interact. You can use this file to automate any initialization steps you perform repeatedly.</p><dd><p class="Body"><a name="86731"> </a>You can also specify a Tcl expression to execute initially on the <b class="command">windsh</b> command line, with the option <b class="command">-e </b><i class="textVariable">tclExpr</i>. For example, you can test an initialization file before saving it as <b class="file">.wind\windsh.tcl</b> using this option, as follows:</p><dl class="margin"><dd><pre class="Code2"><b><a name="86732">C:\&gt; windsh phobos -e "source c:\\fred\\tcltest" </a></b></pre></dl></dl></dl><h4 class="EntityTitle"><a name="94324"><font face="Helvetica, sans-serif" size="-1" class="sans">Example 6-4:&nbsp;&nbsp;Shell Initialization File</font></a></h4><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="97711"> </a>This file causes I/O for target routines called in WindSh to be directed to the target's standard I/O rather than to WindSh. It changes the default C++ strategy to automatic for this shell, sets a path for locating load modules, and causes modules not to be copied to the target server.</p></dl><dl class="margin"><dd><pre class="Code"><b><a name="94325"># Redirect Task I/O to WindSh  shConfig SH_GET_TASK_IO off  # Set C++ strategy  shConfig LD_CALL_XTORS on  # Set Load Path  shConfig LD_PATH "/folk/jmichel/project/app;/folk/jmichel/project/test"  # Let the Target Server directly access the module  shConfig LD_SEND_MODULES off </a></b></pre></dl></dl><a name="foot"><hr></a><p class="FootnoteNumberMarker">1:&nbsp;<span class="Footnote"><a name="86676"> </a>The examples in this book assume you are using the default shell prompts, but you can change the C interpreter prompt to whatever string you like using <b class="routine"><i class="routine">shellPromptSet</i></b><b>(&nbsp;)</b>. </span><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a><a href="GuideIX.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="c-shell.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-shell6.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-shell8.html"><img border="0" alt="[Next]" src="icons/next.gif"></a></p></body></html><!---by WRS Documentation (), Wind River Systems, Inc.    conversion tool:  Quadralay WebWorks Publisher 4.0.11    template:         CSS Template, Jan 1998 - Jefro --->

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -