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

Annotation of OpenXM/src/kan96xx/plugin/junk.c, Revision 1.2

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>