示例#1
0
文件: biffbiff.c 项目: CapeDrew/DITK
void
biffSetStrDone(char *str, const char *key) {

  _bmsgStart();

  biffSetStr(str, key);
  biffDone(key);  /* will call _bmsgFinish if this is the last key */

  return;
}
示例#2
0
文件: biffbiff.c 项目: CapeDrew/DITK
char *
biffGetDone(const char *key) {
  char *ret;

  _bmsgStart();

  ret = biffGet(key);
  biffDone(key);  /* will call _bmsgFinish if this is the last key */

  return ret;
}
void
biffSetStrDone(char *str, const char *key) {

  _biffInit();
  _biffCheckKey(key);

  biffSetStr(str, key);
  biffDone(key);
  _biffNuke();

  return;
}
示例#4
0
void
biffMove(const char *destKey, const char *err, const char *srcKey) {
  unsigned int ii; 
  size_t len;        // to match signature of strlen() on 64 bits
  size_t max;
  char me[] = "biffMove", *buf;
  _biffEntry *dest, *src;

  _biffInit();
  _biffCheckKey(destKey);
  _biffCheckKey(srcKey);

  /* if srcKey and destKey are the same, this degenerates to biffAdd() */
  if (!strcmp(destKey, srcKey)) {
    biffAdd(srcKey, err);
    return;
  }

  dest = _biffFindKey(destKey);
  if (!dest) {
    dest = _biffAddKey(destKey);
  }
  src = _biffFindKey(srcKey);
  if (!src) {
    fprintf(stderr, "%s: WARNING: key \"%s\" unknown\n", me, srcKey);
    return;
  }

  max = 0;
  for (ii=0; ii<src->num; ii++) {
    len = strlen(src->err[ii]) + strlen(src->key) + 4;
    max = AIR_MAX(max, len);
  }
  buf = (char*)calloc(max+1, sizeof(char));
  if (!buf) {
    fprintf(stderr, "%s: PANIC: can't allocate buffer\n", me);
    exit(1);
  }

  for (ii=0; ii<src->num; ii++) {
    sprintf(buf, "[%s] %s", srcKey, src->err[ii]);
    /* printf("%s: HEY: moving \"%s\" to %s\n", me, buf, destKey); */
    _biffAddErr(dest, buf);
  }
  if (err) {
    _biffAddErr(dest, err);
  }
  biffDone(srcKey);
  free(buf);

  return;
}
char *
biffGetDone(const char *key) {
  char *ret;

  _biffInit();
  _biffCheckKey(key);

  ret = biffGet(key);
  biffDone(key);
  _biffNuke();

  return ret;
}
示例#6
0
int
main() {
  char *tmp;

  /*
  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\n", (tmp = biffGet("axis")));
  free(tmp);
  biffDone("axis");

  exit(0);
}
示例#7
0
文件: test.c 项目: CIBC-Internal/teem
int
main(int argc, const char *argv[]) {
    const char *me;
    char *tmp;
    airArray *mop;

    AIR_UNUSED(argc);
    me = argv[0];
    mop = airMopNew();

    /* HEY: the creation and comparison of these strings is not very
       flexible, especially the hard-coded "good[]" strings */
    biffAdd("axis", "the first error axis");
    biffAdd("chard", "the first error chard");
    biffAdd("chard", "the second error chard");
    biffAdd("axis", "the second error axis");
    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");
    biffAdd("axis", "the third error axis");
    {
        char good[] = ("[bingo] the third error bingo\n"
                       "[bingo] the second bll boo boo boo error bingo\n"
                       "[bingo] the first error bingo\n"
                       "[bingo] [chard] the third error chard\n"
                       "[bingo] [chard] the second error chard\n"
                       "[bingo] [chard] the first error chard\n"
                       "[bingo] zero-eth bingo message\n");
        tmp = biffGet("bingo");
        airMopAdd(mop, tmp, airFree, airMopAlways);

        /* an ugly macro */
#define COMPARE(N)                                                 \
    airMopAdd(mop, tmp, airFree, airMopAlways);                    \
    if (strcmp(tmp, good)) {                                       \
      fprintf(stderr, "%s: %d: #%s# != #%s#\n", me, N, tmp, good); \
      airMopError(mop);                                            \
      exit(1);                                                     \
    }

        COMPARE(1);
    }

    {
        char good[] = "";
        tmp = biffGet("chard");
        COMPARE(2);
    }

    {
        char good[] = ("[axis] the third error axis\n"
                       "[axis] the second error axis\n"
                       "[axis] the first error axis\n");
        tmp = biffGet("axis");
        COMPARE(3);
    }

    biffAdd("harold", "the first error harold");
    biffAdd("harold", "the second error harold");
    biffAdd("harold", "the third error harold");
    {
        char good[] = ("[harold] the third error harold\n"
                       "[harold] the second error harold\n"
                       "[harold] the first error harold\n");
        tmp = biffGetDone("harold");
        COMPARE(4);
    }

    biffDone("bingo");
    biffDone("axis");
    biffDone("chard");

    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");
    {
        char good[] = ("[axis] the fifth error axis\n"
                       "[axis] the fourth error axis\n"
                       "[axis] the third error axis\n"
                       "[axis] the second error axis\n"
                       "[axis] the first error axis\n");
        tmp = biffGetDone("axis");
        COMPARE(5);
    }

    biffAddf("test", "%s: this is a test of biffAddf %d %g", "me", 1, 4.2);
    {
        char good[] = "[test] me: this is a test of biffAddf 1 4.2\n";
        tmp = biffGetDone("test");
        COMPARE(6);
    }

    biffAddf("test2", "%s: this is a test of biffAddf %d %g", "me", 1, 4.2);
    biffMovef("test3", "test2", "%s: testing biffMove %d.", "me", 1729);
    {
        char good[] = ("[test3] me: testing biffMove 1729.\n"
                       "[test3] [test2] me: this is a test of biffAddf 1 4.2\n");
        tmp = biffGet("test3");
        COMPARE(7);
    }

    airMopOkay(mop);
    exit(0);
}
示例#8
0
文件: test.c 项目: CIBC-Internal/teem
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);
}