void _biffMsgAddVL(biffMsg *msg, const char *errfmt, va_list args) { char errstr[_HACK_STRLEN]; vsprintf(errstr, errfmt, args); biffMsgAdd(msg, errstr); 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; }
/* ******** biffMsgMove ** ** "src" is not const because we clear it after moving things out */ void biffMsgMove(biffMsg *dest, biffMsg *src, const char *err) { static const char me[]="biffMsgMove"; unsigned int ii; char *buff; if (biffMsgNoop == dest || biffMsgNoop == src) { return; } if (!( dest && src )) { fprintf(stderr, "%s: PANIC got NULL msg (%p %p)\n", me, AIR_VOIDP(dest), AIR_VOIDP(src)); /* exit(1); */ } /* if src and dest are same, this degenerates to biffMsgAdd */ if (dest == src && airStrlen(err)) { biffMsgAdd(dest, err); return; } buff = AIR_CALLOC(biffMsgLineLenMax(src)+1, char); if (!buff) { fprintf(stderr, "%s: PANIC: can't allocate buffer\n", me); /* exit(1); */ } for (ii=0; ii<src->errNum; ii++) { sprintf(buff, "[%s] %s", src->key, src->err[ii]); biffMsgAdd(dest, buff); } free(buff); biffMsgClear(src); if (airStrlen(err)) { biffMsgAdd(dest, err); } return; }
int main() { char *tmp, *s1, *s2; biffMsg *msg1, *msg2; /* biffAdd("axis", "the first error axis"); biffAdd("axis", "the second error axis"); biffAdd("axis", "the third error axis"); biffAdd("chard", "the first error chard"); biffAdd("chard", "the second error chard"); biffAdd("chard", "the third error chard"); biffAdd("bingo", "zero-eth bingo message"); biffMove("bingo", NULL, "chard"); biffAdd("bingo", "the first error bingo"); biffAdd("bingo", "the second bll boo boo boo error bingo"); biffAdd("bingo", "the third error bingo"); printf("%s\n", (tmp = biffGet("bingo"))); free(tmp); biffDone("bingo"); printf("%s\n", (tmp = biffGet("chard"))); free(tmp); biffDone("chard"); printf("%s\n", (tmp = biffGet("axis"))); free(tmp); biffDone("axis"); biffAdd("harold", "the first error harold"); biffAdd("harold", "the second error harold"); biffAdd("harold", "the third error harold"); printf("%s\n", (tmp = biffGet("harold"))); free(tmp); */ biffAdd("axis", "the first error axis"); biffAdd("axis", "the second error axis"); biffAdd("axis", "the third error axis"); biffAdd("axis", "the fourth error axis"); biffAdd("axis", "the fifth error axis"); printf("%s", (tmp = biffGet("axis"))); free(tmp); biffDone("axis"); biffAdd("axo", "the first error axis"); biffAdd("axo", "the second error axis"); biffAdd("axo", "the third error axis"); biffAdd("axo", "the fourth error axis"); biffAdd("axo", "the fifth error axis"); printf("%s", (tmp = biffGetDone("axo"))); free(tmp); printf("=================================\n"); msg1 = biffMsgNew("roberts"); biffMsgAdd(msg1, "biffMsgAdd hello, said roberts"); biffMsgAddf(msg1, "biffMsgAddf: there's an int %d and a float %g", 42, AIR_PI); s1 = biffMsgStrGet(msg1); printf("from msg1:\n%s", s1); s1 = airFree(s1); msg2 = biffMsgNew("sue"); biffMsgAdd(msg2, "biffMsgAdd hi from sue"); biffMsgAddf(msg2, "biffMsgAddf: another float %g", AIR_PI*AIR_PI); s2 = biffMsgStrGet(msg2); printf("from msg2:\n%s", s2); s2 = airFree(s2); biffMsgMovef(msg1, msg2, "biffMsgMovef: good int %d", 10); s1 = biffMsgStrGet(msg1); printf("from msg1:\n%s", s1); s1 = airFree(s1); printf("=================================\n"); msg1 = biffMsgNix(msg1); msg2 = biffMsgNix(msg2); /* biffAddf("test", "%s: this is a test %d %f", "me", 1, 2.0); printf("%s\n", (tmp = biffGet("test"))); free(tmp); biffDone("test"); */ exit(0); }