/* need to include STDIO.H for FPRINTF() */ #define SUCCESS 0 #define FAILURE 1 static int ans; /* CHK() fails if (a != SUCCESS) */ #define CHK(a) \ do { \ if( (ans = (a)) != SUCCESS ) { \ fprintf(stderr,"FAILURE: %s . %d\n",__FILE__,__LINE__); \ return ans; \ } \ } while (0) /* AST() fails if (a == 0) */ #define AST(a) \ do { \ if((a) == 0) { \ fprintf(stderr, "ASSERT FAILED: %s . %d\n",__FILE__,__LINE__); \ return FAILURE; \ } \ } while(0) /* like AST(), but return E_CODE instead of the default FAILURE */ #define E_AST(a,e_code) \ do { \ if((a) == 0) { \ fprintf(stderr,"ASSERT FAILED: %s . %d\n",__FILE__,__LINE__); \ return (e_code); \ } \ } while(0) /* like E_AST(), but also fprintfs __VA_ARGS__ */ #define M_AST(a,e_code,...) \ do { \ if((a) == 0) { \ fprintf(stderr,"ASSERT FAILED: %s . %d\n",__FILE__,__LINE__); \ fprintf(stderr, __VA_ARGS__); \ return (e_code); \ } \ } while(0) /* print a message and return E_CODE */ #define M_EXIT(e_code, ... ) \ do { \ fprintf(stderr,"EXIT: %s . %d\n",__FILE__,__LINE__);\ fprintf(stderr, __VA_ARGS__ );\ return (e_code); \ } while(0)