📄 c-shell2.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-shell1.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-shell3.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="84167">6.2 Using the Shell</a></i></h3></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="91169"> </a>The shell reads lines of input from an input stream, parses and evaluates each line, and writes the result of the evaluation to an output stream. With its default C-expression interpreter, the shell accepts the same expression syntax as a C compiler with only a few variations.</p><dd><p class="Body"><a name="91170"> </a>The following sections explain how to start and stop the shell and provide examples illustrating some typical uses of the shell's C interpreter. In the examples, the default shell prompt for interactive input in C is "->". User input is shown in <b>bold face</b> and shell responses are shown in a <tt class="output">plain roman face</tt>.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="91164">6.2.1 Starting and Stopping the Tornado Shell</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84169"> </a>There are three ways to start a Tornado shell: </p></dl><dl class="margin"><p class="listspace"><ul class="Bullet" type="disc"><li><a name="99638"> </a>From the <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Tornado Launch</font></b> toolbar: Click the <img class="figure" border="0" src="images/c-shella3.gif"> button. This launches a shell for the currently selected target server (see <a href="c-tools5.html#86881"><i class="title">Tornado Launch Toolbar</i></a>).</li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="99646"> </a>From the <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Tools</font></b> menu: Click on <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Shell</font></b>. The dialog box shown in <a href="c-shell2.html#99650">Figure 6-2</a> appears, which allows you to select a target server from the <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Targets</font></b> drop-down list. <div class="frame"><h4 class="EntityTitle"><a name="99650"><font face="Helvetica, sans-serif" size="-1" class="sans">Figure 6-2: Shell Target-Selection Dialog Box</font></a></h4><dl class="margin"><div class="Anchor"><a name="99655"> </a><img class="figure" border="0" src="images/c-shellb6.gif"></div></dl></div></li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="99616"> </a><b class="command"></b>From the Windows command prompt: Invoke <b class="command">windsh</b>, specifying the target-server name, as in the following example:<sup><a href="#foot"><b class="FootnoteMarker">1</b></a></sup></li></ul></p><dl class="margin"><dl class="margin"><dd><pre class="Code3"><b><a name="84201"></b><tt class="output">C:\> </tt><b>windsh phobos </a></b></pre></dl></dl></dl><dl class="margin"><dd><p class="Body"><a name="92243"> </a>If you start a Tornado shell from the IDE, a shell window like the one shown in <a href="c-shell2.html#84226">Figure 6-3</a> appears, with the arrow prompt (->). If you start a shell from the Windows command prompt, WindSh executes in the environment where you call it, using the command-prompt window. <div class="frame"><h4 class="EntityTitle"><a name="84226"><font face="Helvetica, sans-serif" size="-1" class="sans">Figure 6-3: Shell Initial Display</font></a></h4><dl class="margin"><div class="Anchor"><a name="84223"> </a><img class="figure" border="0" src="images/c-shella5.gif"></div></dl></div></p><dd><p class="Body"><a name="100524"> </a>Regardless of how you start it, you can terminate a Tornado shell session by executing the <b class="routine"><i class="routine">exit</i></b><b>( )</b> or the <b class="routine"><i class="routine">quit</i></b><b>( )</b> command or by typing <b class="symbol_UC">CTRL+D</b>. If the shell is not accepting input (for instance, if it loses the connection to the target server) you can use the interrupt key (<kbd>CTRL+BREAK</kbd>).</p><dd><p class="Body"><a name="100527"> </a>You may run as many different shells attached to the same target as you wish. All functions called from a shell have their output redirected to the WindSh window from which they received input unless you changed the shell defaults using <b class="tclProc">shConfig</b> (see <a href="c-shell2.html#94172"><i class="title">WindSh Environment Variables</i></a>). </p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84242">6.2.2 Shell Features</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="91785"> </a>The shell provides many features which simplify your development and testing activities. These include command name and path completion, command and function synopsis printing, automatic data conversion, calculation with most C operators and variables, and help on all shell and VxWorks functions.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="100760">I/O Redirection</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="100762"> </a>Developers often call routines that display data on standard output or accept data from standard input. By default the standard output and input streams are directed to the same window as the Tornado shell. For example, in a default configuration of Tornado, invoking <b class="routine"><i class="routine">printf</i></b><b>( )</b> from the shell window gives the following display:</p><dl class="margin"><dd><pre class="Code2"><b><a name="100763"></b><tt class="output">-></tt><b> printf("Hello World\n") </b><tt class="output">Hello World! value = 13 = 0xd -> </tt><b></a></b></pre></dl><dd><p class="Body"><a name="100764"> </a>This behavior can be dynamically modified using the Tcl procedure <b class="tclProc">shConfig</b> as follows:</p><dl class="margin"><dd><pre class="Code2"><b><a name="100765"></b><tt class="output">-></tt><b> ?shConfig SH_GET_TASK_IO off </b><tt class="output">-> -></tt><b> printf("Hello World!\n") </b><tt class="output">value = 13 = 0xd -></tt><b></a></b></pre></dl><dd><p class="Body"><a name="100766"> </a>The shell reports the <b class="routine"><i class="routine">printf</i></b><b>( )</b> result, indicating that 13 characters have been printed. The output, however, goes to the target's standard output, not to the shell. </p><dd><p class="Body"><a name="100767"> </a>To determine the current configuration, use <b class="tclProc">shConfig</b>. If you issue the command without an argument, all parameters are listed. Use an argument to list only one parameter. </p><dl class="margin"><dd><pre class="Code2"><b><a name="100768"></b><tt class="output">-></tt><b> ?shConfig SH_GET_TASK_IO </b><tt class="output">SH_GET_TASK_IO = off</tt><b></a></b></pre></dl><dd><p class="Body"><a name="100772"> </a>For more information on <b class="tclProc">shConfig</b>, see <a href="c-shell2.html#94172"><i class="title">WindSh Environment Variables</i></a>.</p><dd><p class="Body"><a name="100773"> </a>The standard input and output are only redirected for the function called from WindSh. If this function spawns other tasks, the input and output of the spawned tasks are not redirected to WindSh. To have all IO redirected to WindSh, you can start the target server with the options <b class="symbol_lc">-C -redirectShell</b>.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84246">Target Symbol and Path Completion</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="92103"> </a>Start to type any target symbol name or any existing directory name and then type <b class="symbol_UC">CTRL+D</b>. The shell automatically completes the command or directory name for you. If there are multiple options, it prints them for you and then reprints your entry. For example, entering an ambiguous request generates the following result:</p><dl class="margin"><dd><pre class="Code2"><b><a name="92105"></b><tt class="output">-></tt><b> C:\Tor [CTRL+D] </b><tt class="output">Tornado/ TorClass/ -> C:\Tor</tt><b></a></b></pre></dl><dd><p class="Body"><a name="94085"> </a>You can add one or more letters and then type <b class="symbol_UC">CTRL+D</b> again until the path or symbol is complete.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="92100">Synopsis Printing</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="92104"> </a>Once you have typed the complete function name, typing <b class="symbol_UC">CTRL+D</b> again prints the function synopsis and then reprints the function name ready for your input:</p><dl class="margin"><dd><pre class="Code2"><b><a name="92111"></b><tt class="output">-></tt><b> _taskIdDefault [CTRL+D] </b><tt class="output">taskIdDefault() - set the default task ID (WindSh) int taskIdDefault ( int tid /* user-supplied task ID; if 0, return default */ ) -> _taskIdDefault</tt><b></a></b></pre></dl><dd><p class="Body"><a name="92119"> </a>If the routine exists on both host and target, the WindSh synopsis is printed. To print the target synopsis of a function add the meta-character <b class="symbol_lc">@</b> before the function name. </p><dd><p class="Body"><a name="94088"> </a>You can extend the synopsis printing function to include your own routines. To do this, follow these steps:</p></dl><dl class="margin"><p><ol class="List"><li value="1."><a name="94091"> </a>Create the files that include the new routines following WRS Coding Conventions. (See the <i class="title">VxWorks Programmer's Guide: WRS Coding Conventions</i>.)</li></ol></p><p><ol class="List"><li value="2."><a name="94092"> </a>Include these files in your project. (See <a href="c-builder2.html#85173"><i class="title">Creating, Adding, and Removing Application Files</i></a>.)</li></ol></p><p><ol class="List"><li value="3."><a name="94093"> </a>Add the file names to the <b class="symbol_UC">DOC_FILES</b> macro in your makefile.</li></ol></p><p><ol class="List"><li value="4."><a name="94098"> </a>Go to the top of your project tree and run "make synopsis":</li></ol></p><dl class="margin"><dd><pre class="Code2"><b><a name="94099"></b><tt class="output">-></tt><b> cd $WIND_BASE/target/src/projectX </b><tt class="output">-></tt><b> make synopsis</a></b></pre></dl><dl class="margin"><dd><div class="Indent"><a name="94105"> </a>This adds a file <b class="file">projectX</b> to the <b class="file">host/resource/synopsis</b> directory.</div><br></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="99689">HTML Help</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="99691"> </a>Typing any function name, a space, and <b class="symbol_UC">CTRL+W</b> opens a browser and displays the HTML reference page for the function. Be sure to leave a space after the function name.</p><dl class="margin"><dd><pre class="Code2"><b><a name="98668"></b><tt class="output">-></tt><b> i [CTRL+W]</a></b></pre></dl><dd><p class="Body"><a name="98669"> </a>or</p><dl class="margin"><dd><pre class="Code2"><b><a name="98670"></b><tt class="output">-></tt><b> @i [CTRL+W]</a></b></pre></dl><dd><p class="Body"><a name="94115"> </a>Typing <b class="symbol_UC">CTRL+W</b> without any function name launches the HTML help tool in a new browser window. </p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="94124">Data Conversion </a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84247"> </a>The shell prints all integers and characters in both decimal and hexadecimal, and if possible, as a character constant or a symbolic address and offset.</p><dl class="margin"><dd><pre class="Code2"><b><a name="84248"></b><tt class="output">-></tt><b> 68 </b><tt class="output">value = 68 = 0x44 = 'D'</tt><b></a></b><dd> <b><a name="84249"></b><tt class="output">-></tt><b> 0xf5de </b><tt class="output">value = 62942 = 0xf5de = _init + 0x52</tt><b></a></b><dd> <b><a name="84250"></b><tt class="output">-></tt><b> 's' </b><tt class="output">value = 115 = 0x73 = 's'</tt><b></a></b></pre></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84251">Data Calculation</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84252"> </a>Almost all C operators can be used for data calculation. Use "<b class="operator">(</b>" and "<b class="operator">)</b>" to force order of precedence.</p><dl class="margin"><dd><pre class="Code2"><b><a name="84253"></b><tt class="output">-></tt><b> (14 * 9) / 3 </b><tt class="output">value = 42 = 0x2a = '*'</tt><b></a></b><dd> <b><a name="84254"></b><tt class="output">-></tt><b> (0x1355 << 3) & 0x0f0f </b><tt class="output">value = 2568 = 0xa08</tt><b></a></b><dd> <b><a name="84255"></b><tt class="output">-></tt><b> 4.3 * 5 </b><tt class="output">value = 21.5</tt><b></a></b></pre></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84256">Calculations With Variables</a></i></h4></font><dl class="margin"><dl class="margin"><dl class="margin"><dd><pre class="Code2"><b><a name="84257"></b><tt class="output">-></tt><b> (j + k) * 3 </b><tt class="output">value = ...</tt><b></a></b><dd> <b><a name="84258"></b><tt class="output">-></tt><b> *(j + 8 * k) </b><tt class="output">(</tt><b><i class="textVariable">address (j + 8 * k)</i></b><tt class="output">): value = </tt><b><i class="textVariable"></i></a></b><dd> <b><a name="84259"></b><tt class="output">-></tt><b> x = (val1 - val2) / val3 </b><tt class="output">new symbol "x" added to symbol table address = </tt><b><i class="textVariable"> </i></b><tt class="output">value = </tt><b><i class="textVariable"></i></a></b><dd> <b><a name="84260"></b><tt class="output">-></tt><b> f = 1.41 * 2 </b><tt class="output">new symbol "f" added to symbol table f = </tt><b><i class="textVariable">(address of f)</i></b><tt class="output">: value = 2.82</tt><b></a></b></pre></dl></dl><dl class="margin"><dd><p class="Body"><a name="84261"> </a>Variable <b class="symbol_lc">f</b> gets an 8-byte floating point value.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="94172">WindSh Environment Variables</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="94173"> </a>WindSh allows you to change the behavior of a particular shell session by setting the environment variables listed in <a href="c-shell2.html#94213">Table 6-1</a>. The Tcl procedure <b class="tclProc">shConfig</b> allows you to display and set how I/O redirection, C++ constructors and destructors, loading, and the load path are defined and handled by the shell. <p class="table"><h4 class="EntityTitle"><a name="94213"><font face="Helvetica, sans-serif" size="-1" class="sans">Table 6-1: WindSh Environment Variables</font></a></h4>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -