Annotation of OpenXM/src/kan96xx/plugin/junk.c, Revision 1.1
1.1 ! maekawa 1: /* size : success, -1: error , -2 : do not use size field. */
! 2: int cmoFindHeader(struct cmoBuffer *cb)
! 3: {
! 4: char data[4];
! 5: int c;
! 6: int mtag;
! 7: int size;
! 8: int count=0;
! 9: data[0] = data[1] = data[2] = data[3] = 0xff;
! 10: while (1) {
! 11: if ((c = cmoGetIntFromBuf(CMOGETBYTE,cb)) < 0) {
! 12: fprintf(stderr,"cmoFindHeader: unexpected EOF.\n");
! 13: fprintf(stderr,"data=%2x,%2x,%2x,%2x\n",data[0],data[1],data[2],data[3]);
! 14: /* errorCmo("cmoFindHeader: unexpected end of file."); */
! 15: return(-1);
! 16: }
! 17: count++;
! 18: data[0] = data[1];
! 19: data[1] = data[2];
! 20: data[2] = data[3];
! 21: data[3] = (char)c;
! 22: mtag = ntohl(*((int *)(data)));
! 23: if (mtag == CMO_DATUM) {
! 24: size = cmoGetIntFromBuf(CMOGET,cb);
! 25: if (size == -1) {
! 26: return(-2);
! 27: }else if (size >= 0) {
! 28: return(size);
! 29: }else {
! 30: return(-1); /* Invalid size field. */
! 31: }
! 32: }else{
! 33: if ((count>4) && (count <20)) {
! 34: printf("cmoFindHeader: Warning: Illegal cmo format. Looking for a header.");
! 35: printf(" %2x.\n",c);
! 36: if (count == 19) printf("Too many warnings. They are suppressed.\n");
! 37: }else if (count >= 20) {
! 38: count--;
! 39: }
! 40: }
! 41: }
! 42: }
! 43:
! 44: int cmoOutHeader(int size) {
! 45: cmoOutRawInt(CMO_DATUM);
! 46: if (size < 0) {
! 47: size = -1;
! 48: }
! 49: cmoOutRawInt(size);
! 50: }
! 51:
! 52: int cmoFindTail(struct cmoBuffer *cb)
! 53: {
! 54: char data[4];
! 55: int c;
! 56: int mtag;
! 57: int size;
! 58: int count=0;
! 59: data[0] = data[1] = data[2] = data[3] = 0xff;
! 60: while (1) {
! 61: if ((c = cmoGetIntFromBuf(CMOGETBYTE,cb)) < 0) {
! 62: fprintf(stderr,"cmoFindHeader: unexpected EOF.\n");
! 63: fprintf(stderr,"data=%2x,%2x,%2x,%2x\n",data[0],data[1],data[2],data[3]);
! 64: /* errorCmo("cmoFindHeader: unexpected end of file."); */
! 65: return(-1);
! 66: }
! 67: data[0] = data[1];
! 68: data[1] = data[2];
! 69: data[2] = data[3];
! 70: data[3] = (char)c;
! 71: count++;
! 72: mtag = ntohl(*((int *)(data)));
! 73: if (mtag == CMO_TAIL) {
! 74: size = cmoGetIntFromBuf(CMOGET,cb);
! 75: break;
! 76: }else{
! 77: if ((count > 4) && (count < 20)) {
! 78: printf("cmoFindTail: Warning: Illegal cmo format. Looking for a tail.");
! 79: printf(" %2x.\n",c);
! 80: if (count == 19) printf("Too many warnings. They are suppressed.\n");
! 81: }else if (count >= 20){
! 82: count--;
! 83: }
! 84: }
! 85: }
! 86: /* read size signatures. */
! 87: if (size > 0) {
! 88: errorCmo("cmoFindTail: digital signature has not been supported in this implementation.");
! 89: }
! 90: return(0);
! 91: }
! 92:
! 93: int cmoOutTail(int size, void *signature)
! 94: {
! 95: cmoOutRawInt(CMO_TAIL);
! 96: if (size > 0) {
! 97: cmoOutputToBuf(CMOPUT,signature,size);
! 98: }else{
! 99: cmoOutRawInt(0);
! 100: }
! 101: return(0);
! 102: }
! 103:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>