* Copyright (c) 1982, 1986 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
* @(#)tty_subr.c 7.6 (Berkeley) %G%
setbit(((char *)((int)(cp)&~CROUND)+sizeof(struct cblock *)), \
isset(((char *)((int)(cp)&~CROUND)+sizeof(struct cblock *)), \
#define cbptr(x) ((struct cblock *)(x))
* Initialize clist by freeing all character blocks.
register struct cblock
*cp
;
ccp
= (ccp
+ CROUND
) & ~CROUND
;
for(cp
= (struct cblock
*) ccp
; cp
< &cfree
[nclist
- 1]; cp
++) {
register struct clist
*p
;
register struct cblock
*bp
;
p
->c_cf
= p
->c_cl
= NULL
;
bp
= cbptr((int)bp
& ~CROUND
);
} else if (((int)p
->c_cf
& CROUND
) == 0){
p
->c_cf
= bp
->c_next
->c_info
;
* return number of bytes moved.
register struct clist
*q
;
register struct cblock
*bp
;
q
->c_cf
= q
->c_cl
= NULL
;
nc
= sizeof (struct cblock
) - ((int)q
->c_cf
& CROUND
);
(void) bcopy(q
->c_cf
, cp
, (unsigned)nc
);
bp
= cbptr((int)bp
& ~CROUND
);
q
->c_cf
= q
->c_cl
= NULL
;
if (((int)q
->c_cf
& CROUND
) == 0) {
q
->c_cf
= bp
->c_next
->c_info
;
* Return count of contiguous characters
* in clist starting at q->c_cf.
* Stop counting if flag&character is non-null.
register struct clist
*q
;
cc
= ((int)q
->c_cf
+ CBSIZE
) & ~CROUND
;
register struct clist
*q
;
register struct cblock
*bp
;
while (cc
>0 && q
->c_cc
) {
bp
= cbptr((int)q
->c_cf
& ~CROUND
);
if ((int)bp
== (((int)q
->c_cl
-1) & ~CROUND
)) {
end
= (char *)((int)bp
+ sizeof (struct cblock
));
q
->c_cf
= bp
->c_next
->c_info
;
q
->c_cf
= q
->c_cl
= NULL
;
register struct clist
*p
;
register struct cblock
*bp
;
if ((cp
= p
->c_cl
) == NULL
|| p
->c_cc
< 0 ) { /* no cblocks yet */
if ((bp
= cfreelist
) == NULL
) {
bzero(bp
->c_quote
, CBQSIZE
);
p
->c_cf
= cp
= bp
->c_info
;
} else if (((int)cp
& CROUND
) == 0) {
bp
= cbptr(cp
) - 1; /* pointer arith */
if ((bp
->c_next
= cfreelist
) == NULL
) {
* return number of bytes not transfered.
register struct cblock
*bp
;
if ((cq
= q
->c_cl
) == NULL
|| q
->c_cc
< 0) {
if ((bp
= cfreelist
) == NULL
)
bzero(bp
->c_quote
, CBQSIZE
);
q
->c_cf
= cq
= bp
->c_info
;
if (((int)cq
& CROUND
) == 0) {
if ((bp
->c_next
= cfreelist
) == NULL
)
bzero(bp
->c_quote
, CBQSIZE
);
nc
= MIN(cc
, sizeof (struct cblock
) - ((int)cq
& CROUND
));
(void) bcopy(cp
, cq
, (unsigned)nc
);
* 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.
register struct clist
*p
;
if (p
->c_cc
&& ++cp
!= p
->c_cl
) {
if (((int)cp
& CROUND
) == 0) {
cp
= (cbptr(cp
))[-1].c_next
->c_info
;
* Remove the last character in the list and return it.
register struct clist
*p
;
register struct cblock
*bp
;
bp
= cbptr((int)bp
& ~CROUND
);
p
->c_cl
= p
->c_cf
= NULL
;
} else if (p
->c_cl
== (cbptr((int)p
->c_cl
& ~CROUND
))->c_info
) {
p
->c_cl
= (char *)((int)p
->c_cl
& ~CROUND
);
bp
= cbptr((int)bp
& ~CROUND
);
while (bp
->c_next
!= cbptr(p
->c_cl
))
p
->c_cl
= (char *)(bp
+ 1);
* Put the chars in the from que
* on the end of the to que.
c
= q_to_b(from
, bbuf
, sizeof bbuf
);
(void) b_to_q(bbuf
, c
, to
);
while ((c
= getc(from
)) >= 0)
* Integer (short) get/put using clists.
register struct clist
*p
;
register struct cblock
*bp
;
#if BYTE_ORDER == LITTLE_ENDIAN
return (c
| (getc(p
)<<8));
return (getc(p
) | (c
<<8));
#if BYTE_ORDER == LITTLE_ENDIAN
c
= (((u_char
*)p
->c_cf
)[0] << 8) | ((u_char
*)p
->c_cf
)[1];
c
= (((u_char
*)p
->c_cf
)[1] << 8) | ((u_char
*)p
->c_cf
)[0];
p
->c_cf
+= sizeof (word_t
);
p
->c_cc
-= sizeof (word_t
);
bp
= cbptr((int)bp
& ~CROUND
);
} else if (((int)p
->c_cf
& CROUND
) == 0) {
p
->c_cf
= bp
->c_next
->c_info
;
register struct clist
*p
;
register struct cblock
*bp
;
#if BYTE_ORDER == LITTLE_ENDIAN
if ((cp
= p
->c_cl
) == NULL
|| p
->c_cc
< 0 ) {
if ((bp
= cfreelist
) == NULL
) {
p
->c_cf
= cp
= bp
->c_info
;
} else if (((int)cp
& CROUND
) == 0) {
if ((bp
->c_next
= cfreelist
) == NULL
) {
((u_char
*)cp
)[0] = c
>>8;
p
->c_cl
= cp
+ sizeof (word_t
);
p
->c_cc
+= sizeof (word_t
);