/* ******** 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; }
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); }