123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- #include "cmPrefix.h"
- #include "cmGlobal.h"
- #include "cmRpt.h"
- #include "cmErr.h"
-
- void cmErrSetup( cmErr_t* err, cmRpt_t* rpt, const cmChar_t* label )
- {
- err->rpt = rpt;
- err->label = label;
- err->rc = cmOkRC;
- }
-
- void cmErrClone( cmErr_t* dstErr, const cmErr_t* srcErr )
- { memcpy(dstErr,srcErr,sizeof(*dstErr)); }
-
- void _cmErrVMsg(cmErr_t* err, bool warnFl, cmRC_t rc, const cmChar_t* fmt, va_list vl )
- {
- if( err->rpt == NULL )
- return;
-
- const cmChar_t* hdrFmt = warnFl ? "%s warning: " : "%s error: ";
- const cmChar_t* codeFmt = " (RC:%i)";
-
- int n0 = snprintf( NULL,0,hdrFmt,cmStringNullGuard(err->label));
- int n1 = vsnprintf(NULL,0,fmt,vl);
- int n2 = snprintf( NULL,0,codeFmt,rc);
- int n = n0+n1+n2+1;
- cmChar_t s[n];
- n0 = snprintf(s,n,hdrFmt,cmStringNullGuard(err->label));
- n0 += vsnprintf(s+n0,n-n0,fmt,vl);
- n0 += snprintf(s+n0,n-n0,codeFmt,rc);
- assert(n0 <= n );
- cmRptErrorf(err->rpt,"%s\n",s);
- }
-
- void _cmErrMsg( cmErr_t* err, bool warnFl, cmRC_t rc, const cmChar_t* fmt, ... )
- {
- va_list vl;
- va_start(vl,fmt);
- _cmErrVMsg(err,warnFl,rc,fmt,vl);
- va_end(vl);
- }
-
- cmRC_t cmErrVMsg(cmErr_t* err, cmRC_t rc, const cmChar_t* fmt, va_list vl )
- {
- cmErrSetRC(err,rc);
- _cmErrVMsg(err,false,rc,fmt,vl);
- return rc;
- }
-
-
- cmRC_t cmErrMsg( cmErr_t* err, cmRC_t rc, const cmChar_t* fmt, ... )
- {
- va_list vl;
- va_start(vl,fmt);
- rc = cmErrVMsg(err,rc,fmt,vl);
- va_end(vl);
- return rc;
- }
-
-
- void _cmErrSysVMsg(cmErr_t* err, bool warnFl, cmRC_t rc, cmSysErrCode_t sysErrCode, const cmChar_t* fmt, va_list vl )
- {
- const char* sysFmt = "\n System Error: (code:%i) %s.";
- int n0 = snprintf(NULL,0,sysFmt,sysErrCode,strerror(sysErrCode));
- int n1 = vsnprintf(NULL,0,fmt,vl);
- int n = n0 + n1 + 1;
- cmChar_t s[n0+n1+1];
-
- n0 = snprintf(s,n,sysFmt,sysErrCode,strerror(sysErrCode));
- n0 += vsnprintf(s+n0,n-n0,fmt,vl);
- assert( n0 <= n );
- _cmErrMsg(err,warnFl,rc,s);
- }
-
- cmRC_t cmErrVSysMsg(cmErr_t* err, cmRC_t rc, cmSysErrCode_t sysErrCode, const cmChar_t* fmt, va_list vl )
- {
- cmErrSetRC(err,rc);
- _cmErrSysVMsg(err,false,rc,sysErrCode,fmt,vl);
- return rc;
- }
-
- cmRC_t cmErrSysMsg( cmErr_t* err, cmRC_t rc, cmSysErrCode_t sysErrCode, const cmChar_t* fmt, ... )
- {
- va_list vl;
- va_start(vl,fmt);
- rc = cmErrVSysMsg(err,rc,sysErrCode,fmt,vl);
- va_end(vl);
- return rc;
- }
-
- cmRC_t cmErrWarnVMsg(cmErr_t* err, cmRC_t rc, const cmChar_t* fmt, va_list vl )
- {
- _cmErrVMsg(err,true,rc,fmt,vl);
- err->warnRC = rc;
- return rc;
- }
-
- cmRC_t cmErrWarnMsg( cmErr_t* err, cmRC_t rc, const cmChar_t* fmt, ... )
- {
- va_list vl;
- va_start(vl,fmt);
- rc = cmErrWarnVMsg(err,rc,fmt,vl);
- va_end(vl);
- return rc;
- }
-
- cmRC_t cmErrWarnVSysMsg(cmErr_t* err, cmRC_t rc, cmSysErrCode_t sysErrCode, const cmChar_t* fmt, va_list vl )
- {
- _cmErrSysVMsg(err,true,rc,sysErrCode,fmt,vl);
- err->warnRC = rc;
- return rc;
- }
-
-
- cmRC_t cmErrWarnSysMsg( cmErr_t* err, cmRC_t rc, cmSysErrCode_t sysErrCode, const cmChar_t* fmt, ... )
- {
- va_list vl;
- va_start(vl,fmt);
- rc = cmErrWarnVSysMsg(err,rc,sysErrCode,fmt,vl);
- va_end(vl);
- return rc;
- }
-
-
- cmRC_t cmErrLastRC( cmErr_t* err )
- { return err->rc; }
-
- cmRC_t cmErrSetRC( cmErr_t* err, cmRC_t rc )
- {
- cmRC_t retVal = err->rc;
- err->rc = rc;
- return retVal;
- }
-
- cmRC_t cmErrClearRC( cmErr_t* err )
- { return cmErrSetRC(err,cmOkRC); }
|