Exemple #1
0
/*
** ret is assumed to be allocated for biffMsgStrlen()+1, or is the
** the return from biffMsgStrAlloc
*/
void
biffMsgStrSet(char *ret, const biffMsg *msg) {
  static const char me[]="biffMsgStrSet";
  char *buff;
  unsigned int ii;

  if (biffMsgNoop == msg) {
    return;
  }
  if (!ret) {
    fprintf(stderr, "%s: PANIC got NULL ret", me);
    return;
  }
  buff = AIR_CALLOC(biffMsgLineLenMax(msg)+1, char);
  if (!buff) {
    fprintf(stderr, "%s: PANIC couldn't alloc buffer", me);
    return; /* exit(1); */
  }
  strcpy(ret, "");
  for (ii=msg->errNum; ii>0; ii--) {
    sprintf(buff, "[%s] %s\n", msg->key, msg->err[ii-1]);
    strcat(ret, buff);
  }
  free(buff);
}
Exemple #2
0
/*
******** 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;
}