Design and Implementation of a Documentation Tool for ... - MADOC
Design and Implementation of a Documentation Tool for ... - MADOC
Design and Implementation of a Documentation Tool for ... - MADOC
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
output. <strong>for</strong>script, however, has no such limitation <strong>and</strong> will not write the<br />
startup line to the transcript if the -q flag is set.<br />
35a 〈preparations <strong>of</strong> main loop 34a〉+≡ (33c) ⊳ 34d<br />
if (!qflg)<br />
statusmsg(STARTMSG);<br />
Uses STARTMSG 35b <strong>and</strong> statusmsg 24b.<br />
35b 〈constants 16a〉+≡ (15b) ⊳ 16b 38c ⊲<br />
const char *STARTMSG = "<strong>for</strong>script started on %s, "<br />
"file is %s\r\n";<br />
Defines:<br />
STARTMSG, used in chunk 35a.<br />
The Main Loop<br />
The main loop, which h<strong>and</strong>les input <strong>and</strong> output, will run until the child process<br />
exits.<br />
35c 〈the main loop 35c〉≡ (33c)<br />
while ((CHILD > 0) || drain) {<br />
〈main loop body 35d〉<br />
}<br />
Uses CHILD 8d.<br />
Since select() manipulates the value <strong>of</strong> fds, it has to be initialized again<br />
in each iteration. First its value is cleared, then the file descriptors <strong>for</strong> st<strong>and</strong>ard<br />
input <strong>and</strong> the PTYs master are added to the set, then select() is called to<br />
wait until one <strong>of</strong> the file descriptors has data to read available. When in drain<br />
mode, select() may not be called to avoid blocking.<br />
35d 〈main loop body 35d〉≡ (35c) 36d ⊲<br />
if (!drain) {<br />
FD_ZERO(&fds);<br />
FD_SET(STDIN_FILENO, &fds);<br />
FD_SET(PTM, &fds);<br />
sr = select(highest, &fds, NULL, NULL, NULL);<br />
〈further st<strong>and</strong>ard input processing 35e〉<br />
}<br />
Uses PTM 28c.<br />
If the child process has terminated, there may still be data left in the buffers,<br />
there<strong>for</strong>e the terminals file descriptor is set to non-blocking mode. Reading will<br />
then continue until no more data can be retrieved. If drain mode is already<br />
active, this code will not be executed.<br />
35e 〈further st<strong>and</strong>ard input processing 35e〉≡ (35d) 36a ⊲<br />
if (CHILD < 0) {<br />
int flags = fcntl(PTM, F_GETFL);<br />
if (fcntl(PTM, F_SETFL, (flags | O_NONBLOCK)) == 0) {<br />
drain = 1;<br />
35