Annotation of researchv10no/cmd/spitbol/oswrite.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *     oswrite( mode,recsiz,ioptr,scptr ) writes the record in scblk to
        !             3:  *     the designated output file.  there are two types of transfers:
        !             4:  *
        !             5:  *     unbuffered      write is done immediately
        !             6:  *
        !             7:  *     buffered        write is done into buffer
        !             8:  *
        !             9:  *     in either case, a new-line is appended to the record if in
        !            10:  *     line mode (mode > 0)
        !            11:  */
        !            12: 
        !            13: #include "spitblks.h"
        !            14: #include "spitio.h"
        !            15: 
        !            16: int
        !            17: oswrite( mode, recsiz, ioptr, scptr )
        !            18: 
        !            19: int    mode;
        !            20: register int   recsiz;
        !            21: struct ioblk   *ioptr;
        !            22: struct scblk   *scptr;
        !            23: 
        !            24: {
        !            25:        char    *saveloc, savech;
        !            26:        register char   *cp = scptr -> str;
        !            27:        register int    fdn = ioptr -> fdn;
        !            28:        int     ioerrcnt = 0;
        !            29: 
        !            30:        /*
        !            31:         *      if in line mode, save the character after the string
        !            32:         *      requested to be written and insert a new-line
        !            33:         */
        !            34:        if ( mode > 0 ) {
        !            35:                saveloc = cp + recsiz;
        !            36:                savech = *saveloc;
        !            37:                *saveloc = '\n';
        !            38:                recsiz++;
        !            39:        }
        !            40: 
        !            41:        /* if unbuffered, write the string directly to the output */
        !            42:        if ( ioptr -> flg & IO_WRC ) {
        !            43:                if ( write( fdn, cp, recsiz ) != recsiz)
        !            44:                        ioerrcnt++;
        !            45: 
        !            46:        } else {        /* buffered */
        !            47:                register struct bfblk   *bfptr = ioptr -> buf;
        !            48: 
        !            49:                while (recsiz > 0) {
        !            50:                        register int n = recsiz;
        !            51: 
        !            52:                        if ( n > bfptr -> rem )
        !            53:                                n = bfptr -> rem;
        !            54: 
        !            55:                        recsiz -= n;
        !            56:                        
        !            57:                        if ( n == bfptr -> siz ) {
        !            58:                                if ( write ( fdn, cp, n ) != n)
        !            59:                                        ioerrcnt++;
        !            60:                                cp += n;
        !            61:                        } else {
        !            62:                                register char *r = bfptr -> buf + bfptr -> off;
        !            63:                                bfptr -> off += n;
        !            64:                                bfptr -> rem -= n;
        !            65: 
        !            66:                                /* copy n characters from *cp to *r */
        !            67:                                if ( n & 1 )
        !            68:                                        *r++ = *cp++;
        !            69:                                n >>= 1;
        !            70:                                while (--n >= 0) {
        !            71:                                        *r++ = *cp++;
        !            72:                                        *r++ = *cp++;
        !            73:                                }
        !            74: 
        !            75:                                if ( bfptr -> rem == 0 ) 
        !            76:                                        ioerrcnt += flush( ioptr );
        !            77:                        }
        !            78:                }
        !            79:                        
        !            80:        }
        !            81: 
        !            82:        /* if line mode, restore the previously saved character */
        !            83:        if ( mode > 0 )
        !            84:                *saveloc = savech;
        !            85: 
        !            86:        return ioerrcnt;
        !            87: }

unix.superglobalmegacorp.com

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