Annotation of xinu/sys/ttyiin.c, revision 1.1

1.1     ! root        1: /* ttyiin.c ttyiin, erase1, eputc, echoch */
        !             2: 
        !             3: #include <conf.h>
        !             4: #include <kernel.h>
        !             5: #include <tty.h>
        !             6: #include <io.h>
        !             7: #include <slu.h>
        !             8: 
        !             9: /*------------------------------------------------------------------------
        !            10:  *  ttyiin  --  lower-half tty device driver for input interrupts
        !            11:  *------------------------------------------------------------------------
        !            12:  */
        !            13: INTPROC        ttyiin(iptr)
        !            14:        register struct tty     *iptr;  /* pointer to tty block         */
        !            15: {
        !            16:        register struct csr *cptr;
        !            17:        register int    ch, ct;
        !            18:        
        !            19:        cptr = iptr->ioaddr;
        !            20:        ch=cptr->crbuf;
        !            21:        if (ch & SLUERMASK)
        !            22:                return;                         /* discard if error     */
        !            23:        ch &= SLUCHMASK;
        !            24:        if (iptr->imode == IMRAW) {
        !            25:                if (scount(iptr->isem) >= IBUFLEN) {
        !            26:                        return;                 /* discard if no space  */
        !            27:                }
        !            28:                iptr->ibuff[iptr->ihead++] = ch;
        !            29:                if (iptr->ihead >= IBUFLEN)     /* wrap buffer pointer  */
        !            30:                        iptr->ihead = 0;
        !            31:                signal(iptr->isem);
        !            32:        } else {                                /* cbreak | cooked mode */
        !            33:                if ( ch == RETURN && iptr->icrlf )
        !            34:                        ch = NEWLINE;
        !            35:                if (iptr->iintr && ch == iptr->iintrc) {
        !            36:                        send(iptr->iintpid, INTRMSG);
        !            37:                        eputc(ch, iptr, cptr);
        !            38:                        return;
        !            39:                }
        !            40:                if (iptr->oflow) {
        !            41:                        if (ch == iptr->ostart) {
        !            42:                                iptr->oheld = FALSE;
        !            43:                                cptr->ctstat = SLUENABLE;
        !            44:                                return;
        !            45:                        }
        !            46:                        if (ch == iptr->ostop) {
        !            47:                                iptr->oheld = TRUE;
        !            48:                                return;
        !            49:                        }
        !            50:                }
        !            51:                iptr->oheld = FALSE;
        !            52:                if (iptr->imode == IMCBREAK) {          /* cbreak mode  */
        !            53:                        if (scount(iptr->isem) >= IBUFLEN) {
        !            54:                                eputc(iptr->ifullc,iptr,cptr);
        !            55:                                return;
        !            56:                        }
        !            57:                        iptr->ibuff[iptr->ihead++] = ch;
        !            58:                        if (iptr->ihead >= IBUFLEN)
        !            59:                                iptr->ihead = 0;
        !            60:                        if (iptr->iecho)
        !            61:                                echoch(ch,iptr,cptr);
        !            62:                        if (scount(iptr->isem) < IBUFLEN)
        !            63:                                signal(iptr->isem);
        !            64:                } else {                                /* cooked mode  */
        !            65:                        if (ch == iptr->ikillc && iptr->ikill) {
        !            66:                                iptr->ihead -= iptr->icursor;
        !            67:                                if (iptr->ihead < 0)
        !            68:                                        iptr->ihead += IBUFLEN;
        !            69:                                iptr->icursor = 0;
        !            70:                                eputc(RETURN,iptr,cptr);
        !            71:                                eputc(NEWLINE,iptr,cptr);
        !            72:                                return;
        !            73:                        }
        !            74:                        if (ch == iptr->ierasec && iptr->ierase) {
        !            75:                                if (iptr->icursor > 0) {
        !            76:                                        iptr->icursor--;
        !            77:                                        erase1(iptr,cptr);
        !            78:                                }
        !            79:                                return;
        !            80:                        }
        !            81:                        if (ch == NEWLINE || ch == RETURN ||
        !            82:                                (iptr->ieof && ch == iptr->ieofc)) {
        !            83:                                if (iptr->iecho) {
        !            84:                                        echoch(ch,iptr,cptr);
        !            85:                                        if (ch == iptr->ieofc)
        !            86:                                                echoch(NEWLINE,iptr,cptr);
        !            87:                                }
        !            88:                                iptr->ibuff[iptr->ihead++] = ch;
        !            89:                                if (iptr->ihead >= IBUFLEN)
        !            90:                                        iptr->ihead = 0;
        !            91:                                ct = iptr->icursor+1; /* +1 for \n or \r*/
        !            92:                                iptr->icursor = 0;
        !            93:                                signaln(iptr->isem,ct);
        !            94:                                return;
        !            95:                        }
        !            96:                        ct = scount(iptr->isem);
        !            97:                        ct = ct < 0 ? 0 : ct;
        !            98:                        if ((ct + iptr->icursor) >= IBUFLEN-1) {
        !            99:                                eputc(iptr->ifullc,iptr,cptr);
        !           100:                                return;
        !           101:                        }
        !           102:                        if (iptr->iecho)
        !           103:                                echoch(ch,iptr,cptr);
        !           104:                        iptr->icursor++;
        !           105:                        iptr->ibuff[iptr->ihead++] = ch;
        !           106:                        if (iptr->ihead >= IBUFLEN)
        !           107:                                iptr->ihead = 0;
        !           108:                }
        !           109:        }
        !           110: }
        !           111: 
        !           112: /*------------------------------------------------------------------------
        !           113:  *  erase1  --  erase one character honoring erasing backspace
        !           114:  *------------------------------------------------------------------------
        !           115:  */
        !           116: LOCAL erase1(iptr,cptr)
        !           117:        struct  tty     *iptr;
        !           118:        register struct csr     *cptr;
        !           119: {
        !           120:        char    ch;
        !           121: 
        !           122:        if (--(iptr->ihead) < 0)
        !           123:                iptr->ihead += IBUFLEN;
        !           124:        ch = iptr->ibuff[iptr->ihead];
        !           125:        if (iptr->iecho) {
        !           126:                if (ch < BLANK || ch == 0177) {
        !           127:                        if (iptr->evis) {
        !           128:                                eputc(BACKSP,iptr,cptr);
        !           129:                                if (iptr->ieback) {
        !           130:                                        eputc(BLANK,iptr,cptr);
        !           131:                                        eputc(BACKSP,iptr,cptr);
        !           132:                                }
        !           133:                        }
        !           134:                        eputc(BACKSP,iptr,cptr);
        !           135:                        if (iptr->ieback) {
        !           136:                                eputc(BLANK,iptr,cptr);
        !           137:                                eputc(BACKSP,iptr,cptr);
        !           138:                        }
        !           139:                } else {
        !           140:                        eputc(BACKSP,iptr,cptr);
        !           141:                        if (iptr->ieback) {
        !           142:                                eputc(BLANK,iptr,cptr);
        !           143:                                eputc(BACKSP,iptr,cptr);
        !           144:                        }
        !           145:                }
        !           146:        } else
        !           147:                cptr->ctstat = SLUENABLE;
        !           148: }
        !           149: 
        !           150: /*------------------------------------------------------------------------
        !           151:  *  echoch  --  echo a character with visual and ocrlf options
        !           152:  *------------------------------------------------------------------------
        !           153:  */
        !           154: LOCAL echoch(ch, iptr, cptr)
        !           155:        char    ch;                     /* character to echo            */
        !           156:        register struct tty     *iptr;  /* ptr to I/O block for this dev*/
        !           157:        register struct csr     *cptr;  /* csr address for this devptr  */
        !           158: {
        !           159:        if ((ch==NEWLINE||ch==RETURN)&&iptr->ecrlf) {
        !           160:                eputc(RETURN,iptr,cptr);
        !           161:                eputc(NEWLINE,iptr,cptr);
        !           162:        } else if ((ch<BLANK||ch==0177) && iptr->evis) {
        !           163:                eputc(UPARROW,iptr,cptr);
        !           164:                eputc(ch+0100,iptr,cptr);       /* make it printable    */
        !           165:        } else {
        !           166:                eputc(ch,iptr,cptr);
        !           167:        }
        !           168: }
        !           169: 
        !           170: /*------------------------------------------------------------------------
        !           171:  *  eputc - put one character in the echo queue
        !           172:  *------------------------------------------------------------------------
        !           173:  */
        !           174: LOCAL eputc(ch,iptr,cptr)
        !           175:        char    ch;
        !           176:        register struct tty     *iptr;
        !           177:        register struct csr     *cptr;
        !           178: {
        !           179:        iptr->ebuff[iptr->ehead++] = ch;
        !           180:        if (iptr->ehead >= EBUFLEN)
        !           181:                iptr->ehead = 0;
        !           182:        cptr->ctstat = SLUENABLE;
        !           183: }

unix.superglobalmegacorp.com

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