Exemple #1
0
/*
** _bmsgAdd()
**
** if given key already has a biffMsg in _bmsg, returns that.
** otherise, adds a new biffMsg for given key to _bmsg, and returns it
** panics and exit(1)s if there is a problem
*/
biffMsg *
_bmsgAdd(const char *key) {
  static const char me[]="[biff] _bmsgAdd";
  size_t ii;
  biffMsg *msg;

  msg = NULL;
  /* find if key exists already */
  for (ii=0; ii<_bmsgNum; ii++) {
    if (!strcmp(key, _bmsg[ii]->key)) {
      msg = _bmsg[ii];
      break;
    }
  }
  if (!msg) {
    /* have to add new biffMsg */
    ii = airArrayLenIncr(_bmsgArr, 1);
    if (!_bmsg) {
      fprintf(stderr, "%s: PANIC: couldn't accomodate one more key\n", me);
      exit(1);
    }
    msg = _bmsg[ii] = biffMsgNew(key);
  }
  return msg;
}
Exemple #2
0
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);
}