02.03.2014 Views

Tornado

Tornado

Tornado

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

5<br />

Shell<br />

Notice that the -> prompt indicates we are still in the C interpreter, even though<br />

we just executed a line of Tcl.<br />

! CAUTION: You may not embed Tcl evaluation inside a C expression; the ? prefix<br />

works only as the first nonblank character on a line, and passes the entire line<br />

following it to the Tcl interpreter.<br />

For example, you may occasionally want to use Tcl control structures to<br />

supplement the facilities of the C interpreter. Suppose you have an application<br />

under development that involves several collaborating tasks; in an interactive<br />

development session, you may need to restart the whole group of tasks repeatedly.<br />

You can define a Tcl variable with a list of all the task entry points, as follows:<br />

5<br />

-> ? set appTasks {appFrobStart appGetStart appPutStart …}<br />

appFrobStart appGetStart appPutStart …<br />

Then whenever you need to restart the whole list of tasks, you can use something<br />

like the following:<br />

-> ? foreach it $appTasks {shParse "sp($it)"}<br />

task spawned: id = 25e388, name = u0<br />

task spawned: id = 259368, name = u1<br />

task spawned: id = 254348, name = u2<br />

task spawned: id = 24f328, name = u3<br />

5.7.3 Tcl: <strong>Tornado</strong> Shell lnitialization<br />

When you execute an instance of the <strong>Tornado</strong> shell, it begins by looking for a file<br />

called .wind/windsh.tcl in two places: first under wind, and then in the directory<br />

specified by the HOME environment variable (if that environment variable is<br />

defined). In each of these directories, if the file exists, the shell reads and executes<br />

its contents as Tcl expressions before beginning to interact. You can use this file to<br />

automate any initialization steps you perform repeatedly.<br />

You can also specify a Tcl expression to execute initially on the windsh command<br />

line, with the option -e tclExpr. For example, you can test an initialization file before<br />

saving it as .wind/windsh.tcl using this option, as follows:<br />

% windsh phobos -e "source ./tcltest" &<br />

Example 5-4<br />

Shell Initialization File<br />

This file causes I/O for target routines called in WindSh to be directed to the<br />

target’s standard I/O rather than to WindSh. It changes the default C++ strategy<br />

201

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

Saved successfully!

Ooh no, something went wrong!