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

📄 c-extend4.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>    Extending Tornado Tools   </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="c-extend.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="c-extend.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-extend3.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-extend5.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="84638">5.4  &nbsp;&nbsp;The Shell Presentation</a></i></h3></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84640"> </a>At this point, you have extracted all the information needed to write your own WindSh version of <b class="routine"><i class="routine">ifShow</i></b><b>(&nbsp;)</b>. The remaining task is to format the <b class="routine"><i class="routine">ifShow</i></b><b>(&nbsp;)</b> output. The first two formatting routines are general and should be placed in <i class="textVariable">installDir</i><b class="file">/host/resource/tcl/net-core.tcl</b>. Place the final procedure in <i class="textVariable">installDir</i><b class="file">/host/resource/tcl/app-config/WindSh/01NetShow.tcl</b> because it is shell specific.</p><dd><p class="Body"><a name="84641"> </a>The first formatting routine, <b class="tclProc">ifFlagsFormat</b>, converts the <b class="symbol_lc">if_flags</b> field to a list of bit names by checking each flag bit (see the include file <i class="textVariable">installDir</i><b class="file">/target/h/net/if.h</b>):</p><dl class="margin"><dd><pre class="Code2"><b><a name="85535">proc ifFlagsFormat {flags} {     set result ""      if {$flags &amp; 0x1}       {append result "UP "}     if {$flags &amp; 0x2}       {append result "BROADCAST "}     if {$flags &amp; 0x4}       {append result "DEBUG "}     if {$flags &amp; 0x8}       {append result "LOOPBACK "}     if {$flags &amp; 0x10}      {append result "POINT-TO-POINT "}     if {!($flags &amp; 0x20)}   {append result "TRAILERS "}     if {$flags &amp; 0x40}      {append result "RUNNING "}     if {!($flags &amp; 0x80)}   {append result "ARP "}     if {$flags &amp; 0x100}     {append result "PROMISC "}     if {$flags &amp; 0x200}     {append result "ALLMULTI "}  return $result }</a></b></pre></dl><dd><p class="Body"><a name="84658"> </a>The second formatting routine, <b class="tclProc">ifAddrFormat</b>, prints an Internet address in the standard dotted-decimal form. </p><dl class="margin"><dd><pre class="Code2"><b><a name="84659">proc ifAddrFormat {octetList} {     return [format "%d.%d.%d.%d" \         [lindex $octetList 0] [lindex $octetList 1] \         [lindex $octetList 2] [lindex $octetList 3]] }</a></b></pre></dl><dd><p class="Body"><a name="84664"> </a>All these routines are combined in a single file, which is stored in the<b class="file"> </b><i class="textVariable">installDir</i><b class="symbol_UC">/</b><b class="file">host/resource/tcl</b> directory.</p></dl></dl><h4 class="EntityTitle"><a name="84665"><font face="Helvetica, sans-serif" size="-1" class="sans">Example 5-1:&nbsp;&nbsp;<b class="file">net-core.tcl</b> </font></a></h4><dl class="margin"><dl class="margin"><dd><pre class="Code"><b><a name="84667">proc netIfList {} {     set block [wtxMemRead [lindex [wtxSymFind -name ifnet] 1] 4]     set ifnet [memBlockGet -l $block]     return [wtxGopherEval "$ifnet {! +4 *}"]     }</a></b><dd> <b><a name="84673">proc netIfInfo {netIf} {     return [wtxGopherEval "$netIf &lt;*$&gt; +22 @w +2 @w +4 @@ +4 @@@@@"]     } proc netIfAddrList {netIf} { return [wtxGopherEval "$netIf +8 * {+16 * {&lt;*{+4 @b@b@b@b 0}&gt; +4              &lt;*{+4 @b@b@b@b 0}&gt;+12 *}0}"] }</a></b><dd> <b><a name="84682">proc ifFlagsFormat {flags} {     set result ""</a></b><dd> <b><a name="84684">    if {$flags &amp; 0x1}       {append result "UP "}     if {$flags &amp; 0x2}       {append result "BROADCAST "}     if {$flags &amp; 0x4}       {append result "DEBUG "}     if {$flags &amp; 0x8}       {append result "LOOPBACK "}     if {$flags &amp; 0x10}      {append result "POINT-TO-POINT "}     if {!($flags &amp; 0x20)}   {append result "TRAILERS "}     if {$flags &amp; 0x40}      {append result "RUNNING "}     if {!($flags &amp; 0x80)}   {append result "ARP "}     if {$flags &amp; 0x100}     {append result "PROMISC "}     if {$flags &amp; 0x200} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{append result "ALLMULTI "}</a></b><dd> <b><a name="85222">    return $result     }</a></b><dd> <b><a name="84688">proc ifAddrFormat {octetList} {     return [format "%d.%d.%d.%d" \         [lindex $octetList 0] [lindex $octetList 1] \         [lindex $octetList 2] [lindex $octetList 3]]          }</a></b></pre></dl><dl class="margin"><dd><p class="Body"><a name="84689"> </a>To complete the new version of the shell routine <b class="tclProc">ifShowSh</b>, call the procedures you created in the proper sequence and format the output. This final routine, <b class="tclProc">ifShowSh</b>, is declared as a <b class="keyword">shellproc</b> rather than a <b class="keyword">proc</b>. WindSh makes a Tcl procedure declared as a <b class="keyword">shellproc</b> available to the C-expression-interpreter prompt of the shell. It does this by defining the procedure under another name and recording the original name of the procedure in a list of functions that may be called from the C shell prompt. Such functions must take a variable argument list, indicated in Tcl by the word <i class="term">args</i>, because such functions are invoked by the C-expression interpreter with ten integer arguments, just as built-in shell routines are. Store this file in the<b class="file"> </b><i class="textVariable">installDir</i><b class="file">/host/resource/tcl/app-config/WindSh</b> directory. </p></dl></dl><h4 class="EntityTitle"><a name="84690"><font face="Helvetica, sans-serif" size="-1" class="sans">Example 5-2:&nbsp;&nbsp;<b class="file">01NetShow.tcl</b> </font></a></h4><dl class="margin"><dl class="margin"><dd><pre class="Code"><b><a name="84692"># source the data extraction and formatting routines  source [wtxPath host resource tcl]net-core.tcl</a></b><dd> <b><a name="84696"># extract the data and display it in the shell  shellproc ifShowSh {args} {     foreach netIf [netIfList] {     set ifInfo [netIfInfo $netIf]     puts stdout [format "%s (unit number %d):" \         [lindex $ifInfo 0] [lindex $ifInfo 1]]     puts stdout [format "    Flags: (%#x) %s" \         [lindex $ifInfo 2] \         [ifFlagsFormat [lindex $ifInfo 2]]]     set ifAddrList [netIfAddrList $netIf]     while {[llength $ifAddrList] &gt;= 8} {         set iAddr [lrange $ifAddrList 0 3]         set dAddr [lrange $ifAddrList 4 7]         set ifAddrList [lrange $ifAddrList 12 end]         puts stdout "    Internet address: [ifAddrFormat $iAddr] "         puts stdout "    Destination/Broadcast address: \             [ifAddrFormat $dAddr]"     }</a></b><dd> <b><a name="84700">    puts stdout [format "    Metric is %d" \         [lindex $ifInfo 4]]     puts stdout [format "    Maximum Transfer Unit size is %d" \         [lindex $ifInfo 3]]      puts stdout [format "    %d packets received; %d packets sent" \         [lindex $ifInfo 5] [lindex $ifInfo 7]]     puts stdout [format "    %d input errors; %d output errors" \         [lindex $ifInfo 6] [lindex $ifInfo 8]]     puts stdout [format "    %d collisions" \         [lindex $ifInfo 9]]     } }</a></b></pre></dl><dl class="margin"><dd><p class="Body"><a name="84704"> </a>A side effect of installing a shell extension as a <b class="tclProc">shellproc </b>is that it becomes available at the CrossWind prompt. When CrossWind starts, it reads the WindSh Tcl files and makes new procedures that invoke the shell functions available. These procedures are automatically renamed to be consistent with GDB naming conventions; for example, you can invoke <b class="routine"><i class="routine">ifShow</i></b><b>(&nbsp;)</b> by typing <b class="command">wind-if-show</b> at the GDB prompt. This can be done any time after GDB is attached to a WTX target:</p><dl class="margin"><dd><pre class="Code2"><b><a name="84705"></b><tt class="output">(gdb)</tt><b> tar wtx mv147 </b><tt class="output">Connecting to target server...  Connected to mv147@aven.         Attached to target server mv147@aven, CPU is MC68020. Looking for all loaded modules:         vxWorks: (no debugging symbols found)...ok Done. (gdb)</tt><b> wind-if-show </b><tt class="output">ln (unit number 0):         Flags: (0x63) UP BROADCAST RUNNING ARP          Internet address: 147.11.80.39         Destination/Broadcast address: 147.11.255.255...</tt><b></a></b></pre></dl><dd><p class="Body"><a name="84717"> </a>The shell extension <b class="routine"><i class="routine">ifShow</i></b><b>(&nbsp;)</b> does not take any parameters, but it could easily be modified to do so. Shellprocs (that is, Tcl routines designed to be invoked by the WindSh C interpreter) are always invoked with ten integer arguments. If a string is given as a parameter at the shell's C prompt, that string is stored on the target and the address is substituted as the parameter. This allows shellprocs to simulate target routines; for example, if a shellproc were to spawn a task whose name was given as one of the parameters of the shellproc, it would be possible to supply that string address directly to the <b class="routine"><i class="routine">taskSpawn</i></b><b>(&nbsp;)</b> call.</p></dl></dl><a name="foot"><hr></a><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a><a href="c-extend.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="c-extend.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-extend3.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-extend5.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 + -