📄 c-wtx3.html
字号:
<dd><pre class="Code2"><b><a name="85081">* {@@ 0}</a></b></pre></dl><dd><p class="Body"><a name="85082"> </a>The first <b class="symbol_lc">*</b> replaces the pointer with the value of <b class="symbol_lc">pOther</b>; the fragment in braces executes only if the pointer is not <b class="symbol_lc">NULL</b>. The <b>@@</b> fragment writes <b class="symbol_lc">x1</b> and <b class="symbol_lc">x2</b> to the tape, and the final <b>0</b> sets the pointer to <b class="symbol_UC">NULL</b> so that the <b>{...}</b> loop exits. Guarding this fragment in angle brackets (so that it executes with a local copy of the pointer), adding <b class="symbol_lc">+4</b> to move the pointer to <b class="symbol_lc">pOther</b>, and inserting this fragment into the example string, you have:</p><dl class="margin"><dd><pre class="Code2"><b><a name="90847"><i class="textVariable">nodeAddr</i> * { @ < +8 *$ > < +4 * {@@ 0} > * }</a></b></pre></dl></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/note.gif"></td><td><hr><div class="CalloutCell"><a name="90857"><b class="symbol_UC"><font face="Helvetica, sans-serif" size="-1" class="sans">NOTE: </font></b></a>Wind River Systems has developed a "Gopher generator" tool which generates gopher scripts from a C structure. This tool is not supported, but is available free of charge. It can be downloaded from the Wind River System WEB server (www.wrs.com).</div></td></tr><tr valign="top"><td></td><td><hr></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p callout></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="90849">The Gopher Result Tape</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85095"> </a>The Gopher result tape is a byte-packed data stream. The data is a series of pairs, each consisting of a type code and its associated data. The type codes are defined in the file <i class="textVariable">installDir</i><b class="file">/share/src/agents/wdb/wdb.h</b> as follows:<p class="table"><table border="0" cellpadding="0" cellspacing="0"><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="85098"> </a>GOPHER_UINT32</div></td><td width="10"> </td><td colspan=1 rowspan=1><div class="CellBody"><a name="85100"> </a>0</div></td><td width="10"> </td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="85102"> </a>GOPHER_STRING</div></td><td width="10"> </td><td colspan=1 rowspan=1><div class="CellBody"><a name="85104"> </a>1</div></td><td width="10"> </td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="85106"> </a>GOPHER_UINT16</div></td><td width="10"> </td><td colspan=1 rowspan=1><div class="CellBody"><a name="85108"> </a>2</div></td><td width="10"> </td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="85110"> </a>GOPHER_UINT8</div></td><td width="10"> </td><td colspan=1 rowspan=1><div class="CellBody"><a name="85112"> </a>3</div></td><td width="10"> </td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="85114"> </a>GOPHER_FLOAT32</div></td><td width="10"> </td><td colspan=1 rowspan=1><div class="CellBody"><a name="85116"> </a>4</div></td><td width="10"> </td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="85118"> </a>GOPHER_FLOAT64</div></td><td width="10"> </td><td colspan=1 rowspan=1><div class="CellBody"><a name="85120"> </a>5</div></td><td width="10"> </td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="85122"> </a>GOPHER_FLOAT80</div></td><td width="10"> </td><td colspan=1 rowspan=1><div class="CellBody"><a name="85124"> </a>6</div></td><td width="10"> </td></tr><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p></p><dd><p class="Body"><a name="85191"> </a>The tape is formatted as shown in <a href="c-wtx3.html#85131">Figure 4-5</a>.<div class="frame"><h4 class="EntityTitle"><a name="85131"><font face="Helvetica, sans-serif" size="-1" class="sans">Figure 4-5: Gopher Result Tape</font></a></h4><dl class="margin"><div class="CellBody"><a name="85190"> </a><img class="figure" border="0" src="images/c-wtxa4.gif"></div></dl></div></p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="85192">Sending the Gopher Script to the Target Agent</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85194"> </a>The Gopher interpreter on the target agent interprets and executes the Gopher script. Any tool or application can send a Gopher script to the target agent by using the appropriate WTX command. Both Tcl and C language APIs provide commands for this purpose.</p></dl><dl class="margin"><b class="HU-bullet"><li><a name="85196"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Tcl</font></li></b></dl><dl class="margin"><dd><p class="Body"><a name="85197"> </a>Our Gopher script assumes that <i class="textVariable">nodeAddr</i> is a pointer to the first node. To establish this pointer using Tcl, query the symbol table for the value of <b class="symbol_lc">nodeList</b>, and then send the Gopher script to the target agent using the Tcl procedure <b class="tclProc">wtxGopherEval</b>:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85198">set nodeList [lindex [wtxSymFind -name nodeList] 1] wtxGopherEval $nodeList * { @ < +8 *$ > < +4 * {@@ 0} > * }</a></b></pre></dl><dd><p class="Body"><a name="85200"> </a>Tcl interprets the Gopher result tape and returns a Tcl list consisting of just the data values. For our example, the Tcl API returns the following list:</p></dl><dl class="margin"><dd><pre class="Code"><b><a name="85201"> { <i class="textVariable">name1 value1 x11 x21 name2 value2 ... x1n x2n</i> )</a></b></pre></dl><dl class="margin"><dd><p class="Body"><a name="85202"> </a>For further information, see the online reference material under <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Tornado API Guide>WTX Tcl Library</font></b>.</p></dl><dl class="margin"><b class="HU-bullet"><li><a name="85204"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">C</font></li></b></dl><dl class="margin"><dd><p class="Body"><a name="85205"> </a>The procedure for sending the Gopher script using C involves a similar process. First use the C routine <b class="routine"><i class="routine">wtxSymFind</i></b><b>( )</b> to query the symbol table for the value of <b class="symbol_lc">nodeList</b>. Convert the value to a string, and then send this string, concatenated with the Gopher script, to the target agent using <b class="routine"><i class="routine">wtxGopherEval</i></b><b>( )</b>. C returns the byte-packed data stream without formatting it. <a href="c-wtx3.html#85212">Example 4-1</a> shows how to submit the Gopher script and format the result tape. For further information, see the online reference material under <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Tornado API Guide>WTX Tcl Library</font></b>.</p></dl></dl><h4 class="EntityTitle"><a name="85212"><font face="Helvetica, sans-serif" size="-1" class="sans">Example 4-1: Evaluating a Gopher Script Using the C API</font></a></h4><dl class="margin"><dl class="margin"><dd><pre class="Code"><b><a name="85213">/* find the starting address */ if ((pSymbol = wtxSymFind (hWtx, "nodeList", NULL, 0, 0, 0)) == NULL) { printf ("Could not find symbol\n"); return; } /* convert this value to a string */ sprintf (startAddress, "0x%p", pSymbol->value); /* free the symbol room */ wtxResultFree (hWtx, pSymbol); /* integrate this string into the Gopher script and execute it*/ sprintf (gopherCmd, "%s * { @ < +8 *$ > < +4 * {@@ 0} > * }", startAddress); if ((pResult = wtxGopherEval (hWtx, gopherCmd)) == NULL) { printf ("gopher error: %s\n", wtxErrToMsg (hWtx, wtxErrGet(hWtx))); return; } /* format the result tape */ STATUS formatResult ( WTX_GOPHER_TAPE pTapeResult, char * pFinalResult ) { int targetByteOrder = wtxTargetEndianGet (hWtx); int needSwap = targetByteOrder != HOST_BYTE_ORDER; int bufIx; bufIx = 0; while (bufIx < pTapeResult->len) { char valbuf [20]; UINT8 type = pTapeResult->data [bufIx++]; unsigned char *bufp = pTapeResult->data + bufIx; switch (type) { case GOPHER_UINT32: { UINT32 rawVal = UNPACK_32 (bufp); sprintf (valbuf, "%#x", SWAB_32_IF (needSwap, rawVal)); strcat (pFinalResult, valbuf); bufIx += sizeof (UINT32); break; } case GOPHER_UINT16: { UINT16 rawVal = UNPACK_16 (bufp); sprintf (valbuf, "%#x", SWAB_16_IF (needSwap, rawVal)); strcat (pFinalResult, valbuf); bufIx += sizeof (UINT16); break; } case GOPHER_UINT8: { UINT8 rawVal = *bufp; sprintf (valbuf, "%#x", rawVal); strcat (pFinalResult, valbuf); bufIx += sizeof (UINT8); break; } case GOPHER_FLOAT32: { union { UINT32 i; float f; } u; UINT32 rawVal = UNPACK_32 (bufp); u.i = SWAB_32_IF (needSwap, rawVal); sprintf (valbuf, "%.8g", u.f); strcat (pFinalResult, valbuf); bufIx += sizeof (float); break; } case GOPHER_FLOAT80: /* * This one is trouble. We aren't able to represent * 80-bit floats on the host, so we just take the * upper 64 bits and convert to double. */ if (targetByteOrder == LITTLE_ENDIAN) { /* skip over least significant 16 bits. */ bufIx += 2; bufp += 2; } /* FALL THROUGH */ case GOPHER_FLOAT64: { union { UINT32 i [2]; double d; } u; if (needSwap) { u.i [1] = SWAB_32 (UNPACK_32 (bufp)); u.i [0] = SWAB_32 (UNPACK_32 (bufp+4)); } else { u.i [0] = UNPACK_32 (bufp); u.i [1] = UNPACK_32 (bufp+4); } sprintf (valbuf, "%.16g", u.d); strcat (pFinalResult, valbuf); bufIx += sizeof (double); /* * If target is big endian and we fell through the 80-bit * case, we need to advance over the least-significant * 16 bits which we have no way of converting. */ if (type == GOPHER_FLOAT80 && targetByteOrder == BIG_ENDIAN) bufIx += 2; break; } case GOPHER_STRING: { strcat (pFinalResult, pTapeResult->data + bufIx); bufIx += strlen (pTapeResult->data + bufIx) + 1; } } } return OK; }</a></b></pre></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-wtx.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="c-wtx.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-wtx2.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-wtx4.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 + -