Exemplo n.º 1
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;
}
/*
******** 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) {
  _biffEntry *ent;

  _biffInit();
  _biffCheckKey(key);
  
  ent = _biffFindKey(key);
  if (!ent) {
    ent = _biffAddKey(key);
  }

  /* add the new message */
  _biffAddErr(ent, err);
  return;
}