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
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
There is also a convenience function that writes a meta chunks header <strong>and</strong><br />
footer as well as the actual data:<br />
23a 〈chunkwm 23a〉≡ (15c)<br />
int chunkwm(unsigned char id, unsigned char *data, int count) {<br />
int ret;<br />
if (!chunkwh(id))<br />
return -11;<br />
if ((ret = chunkwd(data, count)) < 0)<br />
return ret;<br />
if (!chunkwf())<br />
return -12;<br />
return 1;<br />
}<br />
Defines:<br />
chunkwm, used in chunks 17, 18, <strong>and</strong> 20b.<br />
Uses chunkwd 21, chunkwf 22d, <strong>and</strong> chunkwh 22d.<br />
A.6 Error H<strong>and</strong>ling<br />
If the program has to terminate abnormally, the function die() will be called.<br />
After resetting the terminal attributes <strong>and</strong> telling a possible child process to<br />
exit, it will output an error message <strong>and</strong> exit the s<strong>of</strong>tware.<br />
23b 〈die 23b〉≡ (15c)<br />
void die(char *message, int chunk) {<br />
if (TTSET)<br />
tcsetattr(STDERR_FILENO, TCSADRAIN, &TT);<br />
if (CHILD > 0)<br />
kill(CHILD, SIGTERM);<br />
fprintf(stderr, "%s: ", MYNAME);<br />
if (chunk != 0) {<br />
fprintf(stderr, "metadata chunk %02x failed", chunk);<br />
if (message != NULL)<br />
fprintf(stderr, ": ");<br />
} else {<br />
if (message == NULL)<br />
fprintf(stderr, "unknown error");<br />
}<br />
if (message != NULL)<br />
fprintf(stderr, "%s", message);<br />
fprintf(stderr, "; exiting.\n");<br />
exit(EXIT_FAILURE);<br />
}<br />
Defines:<br />
die, used in chunks 8c, 24b, 27–34, 36b, <strong>and</strong> 38d.<br />
Uses CHILD 8d, MYNAME 24a, <strong>and</strong> TTSET 28d.<br />
exit() requires stdlib.h:<br />
23c 〈includes 8b〉+≡ (15b) ⊳ 22c 25c ⊲<br />
#include <br />
23