- register int ccp;
- register struct cblock *cp;
- register struct cdevsw *cdp;
-
- ccp = (int)cfree;
- ccp = (ccp+CROUND) & ~CROUND;
- for(cp=(struct cblock *)ccp; cp <= &cfree[NCLIST-1]; cp++) {
- cp->c_next = cfreelist;
- cfreelist = cp;
+
+ if (p->c_cc && ++cp != p->c_cl) {
+ if (((int)cp & CROUND) == 0)
+ return (((struct cblock *)cp)[-1].c_next->c_info);
+ return (cp);
+ }
+ return (0);
+}
+
+/*
+ * Remove the last character in the list and return it.
+ */
+unputc(p)
+register struct clist *p;
+{
+ register struct cblock *bp;
+ register int c, s;
+ struct cblock *obp;
+
+ s = spl5();
+ if (p->c_cc <= 0)
+ c = -1;
+ else {
+ c = *--p->c_cl;
+ if (--p->c_cc <= 0) {
+ bp = (struct cblock *)p->c_cl;
+ bp = (struct cblock *)((int)bp & ~CROUND);
+ p->c_cl = p->c_cf = NULL;
+ bp->c_next = cfreelist;
+ cfreelist = bp;
+ cfreecount += CBSIZE;
+ } else if (((int)p->c_cl & CROUND) == sizeof(bp->c_next)) {
+ p->c_cl = (char *)((int)p->c_cl & ~CROUND);
+ bp = (struct cblock *)p->c_cf;
+ bp = (struct cblock *)((int)bp & ~CROUND);
+ while (bp->c_next != (struct cblock *)p->c_cl)
+ bp = bp->c_next;
+ obp = bp;
+ p->c_cl = (char *)(bp + 1);
+ bp = bp->c_next;
+ bp->c_next = cfreelist;
+ cfreelist = bp;
+ cfreecount += CBSIZE;
+ obp->c_next = NULL;
+ }