/* ******** biffDone() ** ** frees everything associated with given key, and shrinks list of keys, ** and calls _bmsgFinish() if there are no keys left */ void biffDone(const char *key) { static const char me[]="biffDone"; unsigned int idx; biffMsg *msg; _bmsgStart(); msg = _bmsgFind(key); if (!msg) { fprintf(stderr, "%s: WARNING: no information for key \"%s\"\n", me, key); return; } idx = _bmsgFindIdx(msg); biffMsgNix(msg); if (_bmsgNum > 1) { /* if we have more than one key in action, move the last biffMsg to the position that was just cleared up */ _bmsg[idx] = _bmsg[_bmsgNum-1]; } airArrayLenIncr(_bmsgArr, -1); /* if that was the last key, close shop */ if (!_bmsgArr->len) { _bmsgFinish(); } return; }
/* ******** biffGet() ** ** creates a string which records all the errors at given key and ** returns it. Returns NULL in case of error. This function should ** be considered a glorified strdup(): it is the callers responsibility ** to free() this string later */ char * biffGet(const char *key) { static const char me[]="biffGet"; char *ret; biffMsg *msg; _bmsgStart(); msg = _bmsgFind(key); if (!msg) { static const char err[]="[%s] No information for this key!"; size_t errlen; fprintf(stderr, "%s: WARNING: no information for key \"%s\"\n", me, key); errlen = strlen(err)+strlen(key)+1; ret = AIR_CALLOC(errlen, char); if (!ret) { fprintf(stderr, "%s: PANIC: unable to allocate buffer\n", me); exit(1); } #if defined(WIN32) || defined(_WIN32) _snprintf(ret, errlen, err, key); #else snprintf(ret, errlen, err, key); #endif return ret; } ret = AIR_CALLOC(biffMsgStrlen(msg)+1, char); if (!ret) { fprintf(stderr, "%s: PANIC: unable to allocate buffer\n", me); exit(1); } biffMsgStrSet(ret, msg); return ret; }
/* ******** biffGet() ** ** creates a string which records all the errors at given key and ** returns it. Returns NULL in case of error. This function should ** be considered a glorified strdup(): it is the callers responsibility ** to free() this string later */ char * /*Teem: allocates char* */ /* this comment is an experiment */ biffGet(const char *key) { static const char me[]="biffGet"; char *ret; biffMsg *msg; _bmsgStart(); msg = _bmsgFind(key); if (!msg) { static const char err[]="[%s] No information for this key!"; size_t errlen; fprintf(stderr, "%s: WARNING: no information for key \"%s\"\n", me, key); errlen = strlen(err)+strlen(key)+1; ret = AIR_CALLOC(errlen, char); if (!ret) { fprintf(stderr, "%s: PANIC: unable to allocate buffer\n", me); return NULL; /* exit(1); */ } snprintf(ret, errlen, err, key); return ret; } ret = AIR_CALLOC(biffMsgStrlen(msg)+1, char); if (!ret) { fprintf(stderr, "%s: PANIC: unable to allocate buffer\n", me); return NULL; /* exit(1); */ } biffMsgStrSet(ret, msg); return ret; }
void biffAddVL(const char *key, const char *errfmt, va_list args) { biffMsg *msg; _bmsgStart(); msg = _bmsgAdd(key); biffMsgAddVL(msg, errfmt, args); return; }
/* ******** biffAdd() ** ** Adds string "err" at key "key", whether or not there are any ** existing messages there. Since biffSet() was killed ** Wed Apr 20 11:11:51 EDT 2005, this has become the main biff ** function. */ void biffAdd(const char *key, const char *err) { biffMsg *msg; _bmsgStart(); msg = _bmsgAdd(key); biffMsgAdd(msg, err); return; }
void biffSetStrDone(char *str, const char *key) { _bmsgStart(); biffSetStr(str, key); biffDone(key); /* will call _bmsgFinish if this is the last key */ return; }
char * biffGetDone(const char *key) { char *ret; _bmsgStart(); ret = biffGet(key); biffDone(key); /* will call _bmsgFinish if this is the last key */ return ret; }
/* ******** biffCheck() ** ** sees how many messages there are for a given key ** returns 0 if the key doesn't exist. */ size_t biffCheck(const char *key) { biffMsg *msg; _bmsgStart(); msg = _bmsgFind(key); if (!msg) { return 0; } return msg->errNum; }
void biffMove(const char *destKey, const char *err, const char *srcKey) { static const char me[]="biffMove"; biffMsg *dest, *src; _bmsgStart(); dest = _bmsgAdd(destKey); src = _bmsgFind(srcKey); if (!src) { fprintf(stderr, "%s: WARNING: key \"%s\" unknown\n", me, srcKey); return; } biffMsgMove(dest, src, err); return; }
static void _biffMoveVL(const char *destKey, const char *srcKey, const char *errfmt, va_list args) { static const char me[]="biffMovev"; biffMsg *dest, *src; _bmsgStart(); dest = _bmsgAdd(destKey); src = _bmsgFind(srcKey); if (!src) { fprintf(stderr, "%s: WARNING: key \"%s\" unknown\n", me, srcKey); return; } _biffMsgMoveVL(dest, src, errfmt, args); return; }
/* ******** biffGetStrlen() ** ** for when you want to allocate the buffer for the biff string, this is ** how you learn its length */ int biffGetStrlen(const char *key) { static const char me[]="biffGetStrlen"; biffMsg *msg; unsigned int len; _bmsgStart(); msg = _bmsgFind(key); if (!msg) { fprintf(stderr, "%s: WARNING: no information for key \"%s\"\n", me, key); return 0; } len = biffMsgStrlen(msg); len += 1; /* GLK forgets if the convention is that the caller allocates for one more to include '\0'; this is safer */ return len; }
/* ******** biffSetStr() ** ** for when you want to allocate the buffer for the biff string, this is ** how you get the error message itself */ void biffSetStr(char *str, const char *key) { static const char me[]="biffSetStr"; biffMsg *msg; if (!str) { fprintf(stderr, "%s: ERROR: got NULL buffer for \"%s\"\n", me, key); return; } _bmsgStart(); msg = _bmsgFind(key); if (!msg) { fprintf(stderr, "%s: WARNING: no information for key \"%s\"\n", me, key); return; } biffMsgStrSet(str, msg); return; }
/* ******** biffCheck() ** ** sees how many messages there are for a given key; ** Note that this is just a simple wrapper around biffMsgErrNum */ unsigned int biffCheck(const char *key) { _bmsgStart(); return biffMsgErrNum(_bmsgFind(key)); }