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.
• Converting a <strong>for</strong>script file to a script file is basically as easy as removing<br />
everything between shift out <strong>and</strong> shift in bytes (while respecting<br />
escaping rules, <strong>of</strong> course).<br />
4 <strong>Implementation</strong> Oveview<br />
We give a brief insight into the code <strong>of</strong> <strong>for</strong>script that is assembled within a<br />
single C source file <strong>and</strong> written as a literate program [4] using the tool noweb [5].<br />
The noweb tool automatically introduces cross-references between code chunks<br />
so that readers can quickly find the corresponsing code. We only show the most<br />
interesting code chunks here. The full details can be found in the appendix.<br />
7a 〈<strong>for</strong>script.c 7a〉≡<br />
〈declarations <strong>and</strong> definitions 15b〉<br />
〈functions 15c〉<br />
〈main 7b〉<br />
4.1 The Main Program<br />
Here is the main() function. We first determine the program’s name (as called<br />
on the comm<strong>and</strong> line), then we process the comm<strong>and</strong> line options. Afterwards<br />
we open the output file <strong>and</strong> a new pseudo terminal. The original script uses<br />
one process to listen <strong>for</strong> input, one to listen <strong>for</strong> output <strong>and</strong> one to initialize<br />
<strong>and</strong> execl() the comm<strong>and</strong> to be recorded. <strong>for</strong>script in contrast uses only<br />
the select() function to be notified <strong>of</strong> pending input <strong>and</strong> output <strong>and</strong> there<strong>for</strong>e<br />
only needs two processes: itself <strong>and</strong> the subcomm<strong>and</strong>. These two processes<br />
are <strong>for</strong>ked after registering the appropriate signal h<strong>and</strong>lers. Since neither the<br />
parent nor the child process should ever reach the end <strong>of</strong> main(), it returns<br />
EXIT FAILURE.<br />
7b 〈main 7b〉≡ (7a)<br />
int main(int argc, char *argv[]) {<br />
〈set my name 24c〉<br />
〈process comm<strong>and</strong> line options 25b〉<br />
〈open output file 26c〉<br />
〈open new pseudo terminal 28e〉<br />
〈register signal h<strong>and</strong>lers 8a〉<br />
〈<strong>for</strong>k subprocesses 8c〉<br />
return EXIT_FAILURE;<br />
}<br />
Defines:<br />
main, never used.<br />
4.2 Registering Signal H<strong>and</strong>lers<br />
To be notified <strong>of</strong> an exiting subprocess, a h<strong>and</strong>ler <strong>for</strong> the SIGCHLD signal needs<br />
to be defined. This signal is usually sent by the operating system if any child<br />
7