In the standard DP4 C library sys_error() and sys_fail() are functions which call the terminal manager to do their work. On return from the terminal manager para.error is 2 as described earlier, so dp4_halt() will be called with parameter 3 or 4.
dp4_halt() calls the user supplied functions app_close() and finish(). These may themselves generate calls to sys_error() or sys_fail() resulting in a recursive call to dp4_halt(). This situation is guarded against by dp4_halt() which does nothing if it is invoked again before the first invocation has completed.
The DP4 termination functions such as trm_end_trm() and srv_disable() are supposed never to generate any errors. Their doing so has been a frequent source of recursive errors in older releases of DP4. Now errors from these functions have been disabled in the library itself. Previously it was up to the interface programs (SRVn TRMn NTBn ADCm etc) to do the right thing.
All the sys_() functions used to generate error messages and terminate a program abnormally make calls to the new dp4_error() function as follows:
void cdecl sys_error(int message_nr,...)
{
dp4_error(DP4ERR_REPORT|DP4ERR_HALT,3,message_nr,(&message_nr)[1],(&message_nr)[2]);
}
int pascal sys_fail(error_nr,os_error,extra_error)
{
dp4_error(DP4ERR_REPORT|DP4ERR_HALT,4,error_nr,os_error,extra_error);
return -error_nr; /*Only gets here if program prevents termination*/
}
void cdecl sys_message(int message_nr,...)
{
dp4_error(DP4ERR_REPORT,1,message_nr,(&message_nr)[1],(&message_nr)[2]);
}
void cdecl sys_request(int message_nr,...)
{
dp4_error(DP4ERR_REPORT,2,message_nr,(&message_nr)[1],(&message_nr)[2]);
}
|
The code of the dp4_error() function is as follows:
void pascal dp4_error(int flags,int type,int message_nr,int param1,int param2)
{
app_error(&flags,&type,&message_nr,¶m1,¶m2);
if (flags & DP4ERR_REPORT && type >= 0 && type <= 4)
{
/* Uses private functions from terminal manager to produce the error message */
}
if (flags & DP4ERR_HALT)
dp4_halt(type);
}
|
Note that before displaying an error message or terminating the program the programmer-supplied app_error() function is called. If a program wishes to modify the behaviour of dp4_error() it can do so by modifying the parameters in a custom app_error().
If the terminal manager causes a sys_error() or sys_fail() then unless the high order bit of libtype is set it will generate the error message itself immediately. In this case dp4_error() is called with the DPERR_REPORT flag unset. The error information relates to the error message which was produced.