Annotation of researchv10no/cmd/basic/bite/src/bseek.c, revision 1.1

1.1     ! root        1: /* Copyright Bell Telephone Laboratories Whippany, N.J.
        !             2: 
        !             3:  *     /////////////////////////////////////
        !             4:  *     /////////////////////////////////////
        !             5:  *     ////////////// bseek.c //////////////
        !             6:  *     /// J. P. Hawkins HL X2268 2D-227 ///
        !             7:  *     ///// Sun Nov 29 09:55:00 1981 //////
        !             8:  *     /////////////////////////////////////
        !             9:  *     /////////////////////////////////////
        !            10:  *
        !            11:  * BASIC SEEK routine
        !            12:  * PART OF BITE
        !            13:  * For random file access
        !            14:  */
        !            15: /*   "@(#) bseek.c:  V 1.1  11/29/81" */
        !            16: #include       "bas.h"
        !            17: __seek()
        !            18: {
        !            19:        register char *ptr;     /* pointer to program string */
        !            20:        char    *prncpy();
        !            21:        int     fd;             /* file descriptor */
        !            22:        int     fildes;         /* file designator for BASIC */
        !            23:        extern struct FILTBL filtbl[];
        !            24:        double  evalx();
        !            25:        long    offset;
        !            26:        int     mode;
        !            27:        char    field[20];
        !            28: 
        !            29:        ptr = expr;     /* point to command operand string */
        !            30: 
        !            31:        if(*ptr == '_' && (*(ptr+1) >= '0' && *(ptr+1) <= '8'))
        !            32:        {
        !            33:                ptr++;
        !            34:                fildes = *ptr - '1';    /* get BASIC file desig */
        !            35:                fd = filtbl[fildes].fildes; /* get file descriptor */
        !            36:        }
        !            37:        else
        !            38:        {
        !            39:                error(inst.thing.linno, 57);
        !            40:                return(-1);
        !            41:        }
        !            42:        ptr++;
        !            43:        if(*ptr++ != ',')       /* else it better be a , */
        !            44:        {
        !            45:                error(inst.thing.linno, 13); /* delimiter error */
        !            46:                return(-1);
        !            47:        }
        !            48:        ptr=prncpy(field,ptr);          /* get field betw. ',' */
        !            49:        offset = (long)evalx(field);
        !            50:        if(*ptr++ != ',')       /* else it better be a , */
        !            51:        {
        !            52:                error(inst.thing.linno, 13); /* delimiter error */
        !            53:                return(-1);
        !            54:        }
        !            55:        ptr=prncpy(field,ptr);          /* get field betw. ',' */
        !            56:        mode = (int)evalx(field);
        !            57:        if(offset > 0L)
        !            58:                offset--;
        !            59: 
        !            60:        if(lineseek(fd, offset, mode) < 0)
        !            61:        {
        !            62:                error(inst.thing.linno, 58);
        !            63:                return(-1);
        !            64:        }
        !            65:        return(0);
        !            66: }
        !            67: 
        !            68: /*
        !            69:  * Seek to the specified line in the file.
        !            70:  */
        !            71: lineseek(fd, offset, mode)
        !            72: long offset;
        !            73: {
        !            74:        register long o;
        !            75: 
        !            76:        switch(mode)
        !            77:        {
        !            78:        case 0: /* ABSOLUTE SEEK */
        !            79:                bof(fd);                /* rewind first */
        !            80:        case 1: /* RELATIVE SEEK */
        !            81:                for(o=0; o<offset; o++) /* seek from there */
        !            82:                        skipline(fd);
        !            83:                break;
        !            84:        default:
        !            85:                error(inst.thing.linno, 59);
        !            86:                return -1;
        !            87:                break;
        !            88:        }
        !            89:        return 0;
        !            90: }
        !            91: 
        !            92: /*
        !            93:  * Skip read to the next line in file
        !            94:  */
        !            95: skipline(fd)
        !            96: {
        !            97:        char c;
        !            98: 
        !            99:        while(read(fd, &c, 1) != 0)
        !           100:        {
        !           101:                if(c == '\n')
        !           102:                        break;
        !           103:        }
        !           104: }
        !           105: 
        !           106: /*
        !           107:  * rewind to Beginning Of File
        !           108:  */
        !           109: bof(fd)
        !           110: {
        !           111:        lseek(fd, 0L, 0);
        !           112: }
        !           113: /*
        !           114:  *
        !           115:  * BASIC "rewind" command
        !           116:  */
        !           117: rewin()
        !           118: {
        !           119:        char *ptr;
        !           120:        int     fd;             /* file descriptor */
        !           121:        int     fildes;         /* file designator for BASIC */
        !           122: 
        !           123:        ptr = expr;
        !           124:        if(*ptr == '_' && (*(ptr+1) >= '0' && *(ptr+1) <= '8'))
        !           125:        {
        !           126:                ptr++;
        !           127:                fildes = *ptr - '1';    /* get BASIC file desig */
        !           128:                fd = filtbl[fildes].fildes; /* get file descriptor */
        !           129:        }
        !           130:        else
        !           131:        {
        !           132:                error(inst.thing.linno, 60);
        !           133:                return(-1);
        !           134:        }
        !           135:        bof(fd);
        !           136:        return(0);
        !           137: }

unix.superglobalmegacorp.com

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