HP MLIB User's Guide Vol. 2 7th Ed.

1096 HP MLIB User’s Guide
Error handling
Supplying your own signal handler
After calling initMLIB to specify which signal VECLIB’s standard error
handlers are to use, you can set up your own signal handler for that signal via
the C function signal(3c). This is demonstrated by the program in Figure A-6.
Figure A-6 Changing the error handling signal handler
% cat vsig3.c
#include <signal.h>
#include <veclib.h>
static void veclib_sig (sig, code, scp)
int sig, code;
struct sigcontext *scp;
{
printf("SIGUSR2 has occurred... exiting
exit(123);
}
main ()
{
int n = 1;
float alpha = 0.0;
float x[10];
int incx = 0;
int oldsig;
initMLIB (SIGUSR2);
oldsig = (int)signal (SIGUSR2, veclib_sig);
sflr1c_ (&n, &alpha, x, &incx);
}% cc vsig3.c -lveclib
% a.out
****************************************************************************
* XERVEC: subprogram SFLR1C called with invalid value of argument number 4 *
****************************************************************************
SIGUSR2 has occurred... exiting.
% echo $status
123
In Figure A-6, the call to initMLIB changes VECLIB’s error handling signal to
SIGUSR2 and enables VECLIB’s simple signal handler for this signal.
Subsequently, the signal handler veclib_sig is enabled by the call to signal.
When VECLIB subprogram SFLR1C detects the error in arguments, it calls
error handler XERVEC, which writes the error message and raises signal
SIGUSR2. Finally, the system executes veclib_sig.