Annotation of xinu/sys/ttywrite.c, revision 1.1.1.1

1.1       root        1: /* ttywrite.c - ttywrite, writcopy */
                      2: 
                      3: #include <conf.h>
                      4: #include <kernel.h>
                      5: #include <tty.h>
                      6: #include <io.h>
                      7: #include <slu.h>
                      8: 
                      9: /*------------------------------------------------------------------------
                     10:  *  ttywrite - write one or more characters to a tty device
                     11:  *------------------------------------------------------------------------
                     12:  */
                     13: ttywrite(devptr, buff, count)
                     14: struct devsw   *devptr;
                     15: char   *buff;
                     16: int    count;
                     17: {
                     18:        register struct tty *ttyp;
                     19:        int ncopied;
                     20:        PStype ps;
                     21: 
                     22:        if (count < 0)
                     23:                return(SYSERR);
                     24:        if (count == 0)
                     25:                return(OK);
                     26:        disable(ps);
                     27:        ttyp = &tty[devptr->dvminor];
                     28:        count -= (ncopied = writcopy(buff, ttyp, count));
                     29:        buff += ncopied;
                     30:        for ( ; count>0 ; count--)
                     31:                ttyputc(devptr, *buff++);
                     32:        restore(ps);
                     33:        return(OK);
                     34: }
                     35: 
                     36: /*------------------------------------------------------------------------
                     37:  *  writcopy - high-speed copy from user's buffer into system buffer
                     38:  *------------------------------------------------------------------------
                     39:  */
                     40: LOCAL writcopy(buff, ttyp, count)
                     41: char   *buff;
                     42: struct tty *ttyp;
                     43: int    count;
                     44: {
                     45:        register int    avail;
                     46:        register char   *cp, *qhead, *qend, *uend;
                     47: 
                     48:        avail = scount(ttyp->osem);
                     49:        qhead = &ttyp->obuff[ttyp->ohead];
                     50:        qend  = &ttyp->obuff[OBUFLEN];
                     51:        cp    = buff;
                     52:        uend  = buff + count;
                     53:        while (avail-- > 1 && cp < uend) {
                     54:                if (*cp == NEWLINE && ttyp->ocrlf) {
                     55:                        *qhead++ = RETURN;
                     56:                        --avail;
                     57:                        if ( qhead >= qend )
                     58:                                qhead = ttyp->obuff;
                     59:                }
                     60:                *qhead++ = *cp++;
                     61:                if ( qhead >= qend )
                     62:                        qhead = ttyp->obuff;
                     63:        }                                       /* avail decremented one*/
                     64:        ttyp->ohead = qhead - ttyp->obuff;      /* extra time when loop */
                     65:        sreset(ttyp->osem, ++avail);            /* condition fails.     */
                     66:        (ttyp->ioaddr)->ctstat = SLUENABLE;
                     67:        return(cp - buff);
                     68: }

unix.superglobalmegacorp.com

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