The B library defines a zero word called .WRAP, indicating that no special wrapup actions are to be taken when a B program finishes execution. If you want your program to perform any special wrapup operations, you may define a function called .WRAP which will be invoked by EXIT or GOTOSS just before your files are automatically closed. If EXIT is called with a status argument, this will be passed to .WRAP; otherwise, .WRAP will be called with an argument of zero.
The value of .WRAP may be changed by a running program if it wants to add special wrapup operations dynamically; you must be careful when doing this, since some library functions set special wrapup routines of their own at run-time. If your program changes the value of .WRAP and .WRAP was previously non-zero, you must assume that one of the library functions has set its own .WRAP routine. Thus you must save this previous value of .WRAP and invoke it as a function with no arguments during your own .WRAP routine.
Because .WRAP can be changed dynamically, you must not clear .WRAP once wrapup has been established. If your program reaches a state where it no longer needs wrapup, you must arrange that your wrapup function does nothing except call the previous .WRAP routine. You cannot clear .WRAP since that could result in other dynamically established wrapup routines not being called.
As with any other case where you define an external or function to replace a library routine that you do not call directly, if you define you own .WRAP, you must force it to be loaded before the B library is searched. If you have compiled your own .WRAP into your own library, you may need to specify "USe=.wrap" on the command line when you load your program.
expl b lib exit
Copyright © 1996, Thinkage Ltd.