Annotation of 42BSD/ingres/source/dbu/rdwrbatch.c, revision 1.1

1.1     ! root        1: # include      <ingres.h>
        !             2: # include      <aux.h>
        !             3: # include      <symbol.h>
        !             4: # include      <access.h>
        !             5: # include      <batch.h>
        !             6: # include      <sccs.h>
        !             7: 
        !             8: SCCSID(@(#)rdwrbatch.c 7.1     2/5/81)
        !             9: 
        !            10: getbatch(loc, count)
        !            11: char   *loc;
        !            12: int    count;
        !            13: {
        !            14:        register char   *c;
        !            15:        register int    cnt, size;
        !            16:        int             i;
        !            17: 
        !            18:        cnt = count;
        !            19: #      ifdef xZTR1
        !            20:        if (tTf(42, 15))
        !            21:                printf("getbatch:%d (%d)\n", cnt, Batch_cnt);
        !            22: #      endif
        !            23:        c = loc;
        !            24: 
        !            25:        while (cnt)
        !            26:        {
        !            27:                /* see if there is anything in the buffer */
        !            28:                if (Batch_cnt == BATCHSIZE)
        !            29:                        if ((i = readbatch()) < cnt)
        !            30:                                syserr("getbatch:can't read enough %d %d", i, cnt);
        !            31:                if (cnt <= BATCHSIZE - Batch_cnt)
        !            32:                        size = cnt;
        !            33:                else
        !            34:                        size = BATCHSIZE - Batch_cnt;
        !            35:                bmove(&Batchbuf.bbuf[Batch_cnt], c, size);
        !            36:                Batch_cnt += size;
        !            37:                cnt -= size;
        !            38:                c += size;
        !            39:                /* flush the buffer if full */
        !            40:                if (Batch_cnt == BATCHSIZE)
        !            41:                        batchflush();   /* re-write buffer if necessary */
        !            42:        }
        !            43:        return (0);
        !            44: }
        !            45: /*
        !            46: **  PUTBATCH
        !            47: */
        !            48: 
        !            49: putbatch(cp, count)
        !            50: char   *cp;
        !            51: int    count;
        !            52: {
        !            53:        register char   *c;
        !            54:        register int    size, cnt;
        !            55:        int             i;
        !            56: 
        !            57:        cnt = count;
        !            58:        c = cp;
        !            59: #      ifdef xZTR1
        !            60:        if (tTf(42, 2))
        !            61:                printf("putbatch:%d\n", cnt);
        !            62: #      endif
        !            63: 
        !            64:        while (cnt)
        !            65:        {
        !            66:                Batch_dirty = TRUE;     /* mark this buffer as dirty */
        !            67:                if (cnt + Batch_cnt > BATCHSIZE)
        !            68:                        size = BATCHSIZE - Batch_cnt;
        !            69:                else
        !            70:                        size = cnt;
        !            71:                bmove(c, &Batchbuf.bbuf[Batch_cnt], size);
        !            72:                c += size;
        !            73:                Batch_cnt += size;
        !            74:                cnt -= size;
        !            75:                if (Batch_cnt == BATCHSIZE)
        !            76:                {
        !            77:                        batchflush();
        !            78:                        /* is there is more to write, must read ahead first */
        !            79:                        if (cnt)
        !            80:                                if ((i = readbatch()) < cnt)
        !            81:                                        syserr("putbatch:rd too small %d", i);
        !            82:                }
        !            83:        }
        !            84: }
        !            85: /*
        !            86: **  READBATCH
        !            87: */
        !            88: 
        !            89: readbatch()
        !            90: {
        !            91: 
        !            92:        if ((Batch_lread = read(Batch_fp, &Batchbuf, BATCHSIZE+IDSIZE)) < 0)
        !            93:                syserr("readbatch:can't read %d %d", Batch_lread, Batch_fp);
        !            94:        Batch_cnt = 0;
        !            95: #      ifdef xZTR1
        !            96:        if (tTf(42, 10))
        !            97:                printf("read %d bytes from batch\n", Batch_lread);
        !            98: #      endif
        !            99:        /* check file-id */
        !           100:        if (!sequal(Fileset, Batchbuf.file_id))
        !           101:                syserr("readbatch:bad id '%s' '%.20s' %d", Fileset, Batchbuf.file_id, Batch_lread);
        !           102:        return (Batch_lread);
        !           103: }
        !           104: /*
        !           105: **  BATCHFLUSH
        !           106: */
        !           107: 
        !           108: batchflush()
        !           109: {
        !           110:        register int    i;
        !           111:        if (Batch_cnt && Batch_dirty)
        !           112:        {
        !           113: #              ifdef xZTR1
        !           114:                if (tTf(42, 5))
        !           115:                        printf("flush:backing up %d\n", Batch_lread);
        !           116: #              endif
        !           117:                if ((i = lseek(Batch_fp, (long) -Batch_lread, 1)) < 0)
        !           118:                        syserr("batchflush:can't seek %d", Batch_lread);
        !           119: #              ifdef xZTR1
        !           120:                if (tTf(42, 4))
        !           121:                        printf("flushing %d\n", Batch_cnt + IDSIZE);
        !           122: #              endif
        !           123:                if ((i = write(Batch_fp, &Batchbuf, Batch_cnt + IDSIZE)) != Batch_cnt + IDSIZE)
        !           124:                        syserr("batchflush:can't write %d", i);
        !           125:                Batch_dirty = FALSE;
        !           126:        }
        !           127: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.