+char *
+wb_to_q(cp, cc, q)
+register char *cp;
+register struct clist *q;
+register cc;
+{
+char *f;
+register s;
+
+ s = spl6();
+ while (cc > cfreecount) {
+ cwaiting = 1;
+ sleep(&cwaiting, TTOPRI);
+ }
+ if (q->c_cc==0) {
+ b_to_q(cp, cc, q);
+ f = q->c_cf;
+ } else {
+ (void) putc(*cp++, q);
+ f = q->c_cl;
+ f--;
+ b_to_q(cp, --cc, q);
+ }
+ splx(s);
+ return(f);
+}
+
+#ifdef notdef
+char *
+nb_to_q(cp, cc, q)
+register char *cp;
+register struct clist *q;
+register cc;
+{
+char *f;
+register s;
+
+ s = spl6();
+ if (cc > cfreecount) {
+ f = NULL;
+ goto out;
+ }
+ if (q->c_cc==0) {
+ b_to_q(cp, cc, q);
+ f = q->c_cf;
+ } else {
+ (void) putc(*cp++, q);
+ f = q->c_cl;
+ f--;
+ b_to_q(cp, --cc, q);
+ }
+out:
+ splx(s);
+ return(f);
+}
+#endif
+
+/*
+ * Given a non-NULL pointter into the list (like c_cf which
+ * always points to a real character if non-NULL) return the pointer
+ * to the next character in the list or return NULL if no more chars.
+ *
+ * Callers must not allow getc's to happen between nextc's so that the
+ * pointer becomes invalid. Note that interrupts are NOT masked.
+ */
+char *
+nextc(p, cp)
+register struct clist *p;
+register char *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 = spl6();
+ 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;
+ }
+ }
+ splx(s);
+ return (c);
+}
+
+/*
+ * Put the chars in the from que
+ * on the end of the to que.
+ *
+ * SHOULD JUST USE q_to_b AND THEN b_to_q HERE.
+ */
+catq(from, to)
+struct clist *from, *to;
+{
+ register c;
+
+ while ((c = getc(from)) >= 0)
+ (void) putc(c, to);
+}
+