#include "sys/param.h" #include "sys/tty.h" getc(p) register struct clist *p; { register struct cblock *bp; register int c, s; s = spl6(); if (p->c_cc > 0) { p->c_cc--; bp = p->c_cf; c = bp->c_data[bp->c_first++]&0377; if (bp->c_first == bp->c_last) { if ((p->c_cf = bp->c_next) == NULL) p->c_cl = NULL; bp->c_next = cfreelist.c_next; cfreelist.c_next = bp; } } else c = -1; splx(s); return(c); } putc(c, p) register struct clist *p; { register struct cblock *bp, *obp; register s; s = spl6(); if ((bp = p->c_cl) == NULL || bp->c_last == cfreelist.c_size) { obp = bp; if ((bp = cfreelist.c_next) == NULL) { splx(s); return(-1); } cfreelist.c_next = bp->c_next; bp->c_next = NULL; bp->c_first = bp->c_last = 0; if (obp == NULL) p->c_cf = bp; else obp->c_next = bp; p->c_cl = bp; } bp->c_data[bp->c_last++] = c; p->c_cc++; splx(s); return(0); } struct cblock * getcf() { register struct cblock *bp; register int s; s = spl6(); if ((bp = cfreelist.c_next) != NULL) { cfreelist.c_next = bp->c_next; bp->c_next = NULL; bp->c_first = 0; bp->c_last = cfreelist.c_size; } splx(s); return(bp); } putcf(bp) register struct cblock *bp; { register int s; s = spl6(); bp->c_next = cfreelist.c_next; cfreelist.c_next = bp; splx(s); } struct cblock * getcb(p) register struct clist *p; { register struct cblock *bp; register int s; s = spl6(); if ((bp = p->c_cf) != NULL) { p->c_cc -= bp->c_last - bp->c_first; if ((p->c_cf = bp->c_next) == NULL) p->c_cl = NULL; } splx(s); return(bp); } putcb(bp, p) register struct cblock *bp; register struct clist *p; { register struct cblock *obp; register int s; s = spl6(); if ((obp = p->c_cl) == NULL) p->c_cf = bp; else obp->c_next = bp; p->c_cl = bp; bp->c_next = NULL; p->c_cc += bp->c_last - bp->c_first; splx(s); return(0); }