02.03.2014 Views

Tornado

Tornado

Tornado

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Tornado</strong> 2.0<br />

User’s Guide<br />

5.7 Tcl: Shell Interpretation<br />

The shell has a Tcl interpreter interface as well as the C interpreter interface. This<br />

section illustrates some uses of the shell Tcl interpreter. If you are not familiar with<br />

Tcl, we suggest you skip this section and return to it after you have gotten<br />

acquainted with Tcl. (For an outline of Tcl, see B. Tcl.) In the interim, you can do a<br />

great deal of development work with the shell C interpreter alone.<br />

To toggle between the Tcl interpreter and the C interpreter in the shell, type the<br />

single character ?. The shell prompt changes to remind you of the interpreter state:<br />

the prompt -> indicates the C interpreter is listening, and the prompt tcl> indicates<br />

the Tcl interpreter is listening. 7 For example, in the following interaction we use the<br />

C interpreter to define a variable in the symbol table, then switch into the Tcl<br />

interpreter to define a similar Tcl variable in the shell itself, and finally switch back<br />

to the C interpreter:<br />

-> hello="hi there"<br />

new symbol "hello" added to symbol table.<br />

hello = 0x3616e8: value = 3544824 = 0x3616f8 = hello + 0x10<br />

-> ?<br />

tcl> set hello {hi there}<br />

hi there<br />

tcl> ?<br />

-><br />

If you start windsh from the Windows command line, you can also use the option<br />

-Tclmode (or -T) to start with the Tcl interpreter rather than the C interpreter.<br />

Using the shell’s Tcl interface allows you to extend the shell with your own<br />

procedures, and also provides a set of control structures which you can use<br />

interactively. The Tcl interpreter also acts as a host shell, giving you access to UNIX<br />

command-line utilities on your development host.<br />

For example, you can call stty from the Tcl interpreter to change the special<br />

characters in use—in the following, to specify the quit character as CTRL+B and<br />

verify the new setting (the quit character is normally CTRL+X; when you type it in<br />

the shell, it reboots the target, restarts the target server, and resets all attached<br />

tools):<br />

tcl> stty quit \002<br />

tcl> stty<br />

speed 9600 baud; line = 0;<br />

quit = ^B; eof = ^A; status = ; min = 1; time = 0;<br />

-icanon -echo<br />

7. The examples in this book assume you are using the default shell prompts, but you can<br />

change the C interpreter prompt to whatever string you like using shellPromptSet( ).<br />

198

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!