[BACK]Return to junk.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / kan96xx / plugin

File: [local] / OpenXM / src / kan96xx / plugin / junk.c (download)

Revision 1.2, Sun Jan 16 07:55:47 2000 UTC (24 years, 4 months ago) by takayama
Branch: MAIN
CVS Tags: maekawa-ipv6, R_1_3_1-2, RELEASE_20000124, RELEASE_1_3_1_13b, RELEASE_1_2_3_12, RELEASE_1_2_3, RELEASE_1_2_2_KNOPPIX_b, RELEASE_1_2_2_KNOPPIX, RELEASE_1_2_2, RELEASE_1_2_1, RELEASE_1_1_3, RELEASE_1_1_2, KNOPPIX_2006, HEAD, DEB_REL_1_2_3-9
Changes since 1.1: +1 -0 lines

Congratulation of sm1 version 3.* !

/* $OpenXM: OpenXM/src/kan96xx/plugin/junk.c,v 1.2 2000/01/16 07:55:47 takayama Exp $ */
/* size : success,  -1: error , -2 : do not use size field. */
int cmoFindHeader(struct cmoBuffer *cb)
{
  char data[4];
  int c;
  int mtag;
  int size;
  int count=0;
  data[0] = data[1] = data[2] = data[3] = 0xff;
  while (1) {
    if ((c = cmoGetIntFromBuf(CMOGETBYTE,cb)) < 0) {
      fprintf(stderr,"cmoFindHeader: unexpected EOF.\n");
      fprintf(stderr,"data=%2x,%2x,%2x,%2x\n",data[0],data[1],data[2],data[3]);
      /* errorCmo("cmoFindHeader: unexpected end of file."); */
      return(-1);
    }
    count++;
    data[0] = data[1];
    data[1] = data[2];
    data[2] = data[3];
    data[3] = (char)c;
    mtag = ntohl(*((int *)(data)));
    if (mtag == CMO_DATUM) {
      size = cmoGetIntFromBuf(CMOGET,cb);
      if (size == -1) {
	return(-2);
      }else if (size >= 0) {
	return(size);
      }else {
	return(-1);  /* Invalid size field. */
      }
    }else{
      if ((count>4) && (count <20)) {
	printf("cmoFindHeader: Warning: Illegal cmo format. Looking for a header.");
	printf(" %2x.\n",c); 
	if (count == 19) printf("Too many warnings. They are suppressed.\n");
      }else if (count >= 20) {
	count--;
      }
    }
  }
}

int cmoOutHeader(int size) {
  cmoOutRawInt(CMO_DATUM);
  if (size < 0) {
    size = -1;
  }
  cmoOutRawInt(size);
}

int cmoFindTail(struct cmoBuffer *cb)
{
  char data[4];
  int c;
  int mtag;
  int size;
  int count=0;
  data[0] = data[1] = data[2] = data[3] = 0xff;
  while (1) {
    if ((c = cmoGetIntFromBuf(CMOGETBYTE,cb)) < 0) {
      fprintf(stderr,"cmoFindHeader: unexpected EOF.\n");
      fprintf(stderr,"data=%2x,%2x,%2x,%2x\n",data[0],data[1],data[2],data[3]);
      /* errorCmo("cmoFindHeader: unexpected end of file."); */
      return(-1);
    }
    data[0] = data[1];
    data[1] = data[2];
    data[2] = data[3];
    data[3] = (char)c;
    count++;
    mtag = ntohl(*((int *)(data)));
    if (mtag == CMO_TAIL) {
      size = cmoGetIntFromBuf(CMOGET,cb);
      break;
    }else{
      if ((count > 4) && (count < 20)) {
	printf("cmoFindTail: Warning: Illegal cmo format. Looking for a tail.");
	printf(" %2x.\n",c);
	if (count == 19) printf("Too many warnings. They are suppressed.\n");
      }else if (count >= 20){
	count--;
      }
    }
  }
  /* read size signatures. */
  if (size > 0) {
    errorCmo("cmoFindTail:  digital signature has not been supported in this implementation.");
  }
  return(0);
}

int cmoOutTail(int size, void *signature)
{
  cmoOutRawInt(CMO_TAIL);
  if (size > 0) {
    cmoOutputToBuf(CMOPUT,signature,size);
  }else{
    cmoOutRawInt(0);
  }
  return(0);
}