#ifndef envelope #ifdef __cplusplus extern "C" { #endif #include #include #ifndef MORE #include #endif extern struct JMP_BUF { jmp_buf buf; } *errenv; extern const char *bmsprog; extern GOTO errpost(int); extern GOTO errdesc(const char *, int); extern GOTO errvdesc(int,const char *,MORE); extern void syserr(int,char *,MORE); #define errwhat(e,s) errvdesc(e,"%s %s line %d",s,what,__LINE__) /* weird things happen if you combine the setjmp with the 'if' in 'catch' */ #define catch(rc) { \ struct JMP_BUF env, *envsav = errenv; \ rc = setjmp(env.buf); \ if (!rc && (errenv = &env)) { /* normal processing goes here */ #define enverr \ } \ else { \ errenv = envsav; /* Optional error cleanup processing goes here. If there is an error during cleanup, another error is signalled triggering the next level */ #define envend \ } \ errenv = envsav; \ } #define envelope catch(errno) #ifdef __cplusplus } #endif #endif