Home | History | Annotate | Line # | Download | only in kern
tty_subr.c revision 1.1.4.1
      1      1.1  mycroft /*
      2      1.1  mycroft  * Copyright (c) 1993 Theo de Raadt
      3      1.1  mycroft  * All rights reserved.
      4      1.1  mycroft  *
      5      1.1  mycroft  * Per Lindqvist <pgd (at) compuram.bbt.se> supplied an almost fully working
      6      1.1  mycroft  * set of true clist functions that this is very loosely based on.
      7      1.1  mycroft  *
      8      1.1  mycroft  * Redistribution and use in source and binary forms, with or without
      9      1.1  mycroft  * modification, are permitted provided that the following conditions
     10      1.1  mycroft  * are met:
     11      1.1  mycroft  * 1. Redistributions of source code must retain the above copyright
     12      1.1  mycroft  *    notice, this list of conditions and the following disclaimer.
     13      1.1  mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     14      1.1  mycroft  *    notice, this list of conditions and the following disclaimer in the
     15      1.1  mycroft  *    documentation and/or other materials provided with the distribution.
     16      1.1  mycroft  * 3. All advertising materials mentioning features or use of this software
     17      1.1  mycroft  *    must display the following acknowledgement:
     18      1.1  mycroft  *	This product includes software developed by Theo de Raadt.
     19      1.1  mycroft  * 4. The name of Theo de Raadt may not be used to endorse or promote products
     20      1.1  mycroft  *    derived from this software without specific prior written permission.
     21      1.1  mycroft  *
     22  1.1.4.1  mycroft  *	$Id: tty_subr.c,v 1.1.4.1 1993/09/24 08:51:49 mycroft Exp $
     23      1.1  mycroft  */
     24      1.1  mycroft 
     25      1.1  mycroft #include "param.h"
     26      1.1  mycroft #include "systm.h"
     27      1.1  mycroft #include "buf.h"
     28      1.1  mycroft #include "ioctl.h"
     29      1.1  mycroft #include "tty.h"
     30      1.1  mycroft #include "clist.h"
     31      1.1  mycroft #include "malloc.h"
     32  1.1.4.1  mycroft 
     33  1.1.4.1  mycroft #include "machine/cpu.h"
     34      1.1  mycroft 
     35      1.1  mycroft /*
     36      1.1  mycroft  * At compile time, choose:
     37      1.1  mycroft  * There are two ways the TTY_QUOTE bit can be stored. If QBITS is
     38      1.1  mycroft  * defined we allocate an array of bits -- 1/8th as much memory but
     39      1.1  mycroft  * setbit(), clrbit(), and isset() take more cpu. If QBITS is
     40      1.1  mycroft  * undefined, we just use an array of bytes.
     41      1.1  mycroft  *
     42      1.1  mycroft  * If TTY_QUOTE functionality isn't required by a line discipline,
     43      1.1  mycroft  * it can free c_cq and set it to NULL. This speeds things up,
     44      1.1  mycroft  * and also does not use any extra memory. This is useful for (say)
     45      1.1  mycroft  * a SLIP line discipline that wants a 32K ring buffer for data
     46      1.1  mycroft  * but doesn't need quoting.
     47      1.1  mycroft  */
     48      1.1  mycroft #define QBITS
     49      1.1  mycroft 
     50      1.1  mycroft #ifdef QBITS
     51      1.1  mycroft #define QMEM(n)		((((n)-1)/NBBY)+1)
     52      1.1  mycroft #else
     53      1.1  mycroft #define QMEM(n)		(n)
     54      1.1  mycroft #endif
     55      1.1  mycroft 
     56      1.1  mycroft 
     57      1.1  mycroft /*
     58      1.1  mycroft  * Initialize clists.
     59      1.1  mycroft  */
     60      1.1  mycroft void
     61      1.1  mycroft cinit()
     62      1.1  mycroft {
     63      1.1  mycroft }
     64      1.1  mycroft 
     65      1.1  mycroft /*
     66      1.1  mycroft  * Initialize a particular clist. Ok, they are really ring buffers,
     67      1.1  mycroft  * of the specified length, with/without quoting support.
     68      1.1  mycroft  */
     69      1.1  mycroft int
     70      1.1  mycroft clalloc(clp, size, quot)
     71      1.1  mycroft 	struct clist *clp;
     72      1.1  mycroft 	int size;
     73      1.1  mycroft 	int quot;
     74      1.1  mycroft {
     75      1.1  mycroft 
     76      1.1  mycroft 	MALLOC(clp->c_cs, u_char *, size, M_TTYS, M_WAITOK);
     77      1.1  mycroft 	if (!clp->c_cs)
     78      1.1  mycroft 		return (-1);
     79      1.1  mycroft 	bzero(clp->c_cs, size);
     80      1.1  mycroft 
     81      1.1  mycroft 	if(quot) {
     82      1.1  mycroft 		MALLOC(clp->c_cq, u_char *, QMEM(size), M_TTYS, M_WAITOK);
     83      1.1  mycroft 		if (!clp->c_cq) {
     84      1.1  mycroft 			FREE(clp->c_cs, M_TTYS);
     85      1.1  mycroft 			return (-1);
     86      1.1  mycroft 		}
     87      1.1  mycroft 		bzero(clp->c_cs, QMEM(size));
     88      1.1  mycroft 	} else
     89      1.1  mycroft 		clp->c_cq = (u_char *)0;
     90      1.1  mycroft 
     91      1.1  mycroft 	clp->c_cf = clp->c_cl = (u_char *)0;
     92      1.1  mycroft 	clp->c_ce = clp->c_cs + size;
     93      1.1  mycroft 	clp->c_cn = size;
     94      1.1  mycroft 	clp->c_cc = 0;
     95      1.1  mycroft 	return (0);
     96      1.1  mycroft }
     97      1.1  mycroft 
     98      1.1  mycroft void
     99      1.1  mycroft clfree(clp)
    100      1.1  mycroft 	struct clist *clp;
    101      1.1  mycroft {
    102      1.1  mycroft 	if(clp->c_cs)
    103      1.1  mycroft 		FREE(clp->c_cs, M_TTYS);
    104      1.1  mycroft 	if(clp->c_cq)
    105      1.1  mycroft 		FREE(clp->c_cq, M_TTYS);
    106      1.1  mycroft 	clp->c_cs = clp->c_cq = (u_char *)0;
    107      1.1  mycroft }
    108      1.1  mycroft 
    109      1.1  mycroft 
    110      1.1  mycroft /*
    111      1.1  mycroft  * Get a character from a clist.
    112      1.1  mycroft  */
    113      1.1  mycroft int
    114      1.1  mycroft getc(clp)
    115      1.1  mycroft 	struct clist *clp;
    116      1.1  mycroft {
    117      1.1  mycroft 	register int c = -1;
    118      1.1  mycroft 	int s;
    119      1.1  mycroft 
    120      1.1  mycroft 	s = spltty();
    121      1.1  mycroft 	if (clp->c_cc == 0)
    122      1.1  mycroft 		goto out;
    123      1.1  mycroft 
    124      1.1  mycroft 	c = *clp->c_cf & 0xff;
    125      1.1  mycroft 	if (clp->c_cq) {
    126      1.1  mycroft #ifdef QBITS
    127      1.1  mycroft 		if (isset(clp->c_cq, clp->c_cf - clp->c_cs) )
    128      1.1  mycroft 			c |= TTY_QUOTE;
    129      1.1  mycroft #else
    130      1.1  mycroft 		if (*(clp->c_cf - clp->c_cs + clp->c_cq))
    131      1.1  mycroft 			c |= TTY_QUOTE;
    132      1.1  mycroft #endif
    133      1.1  mycroft 	}
    134      1.1  mycroft 	if (++clp->c_cf == clp->c_ce)
    135      1.1  mycroft 		clp->c_cf = clp->c_cs;
    136      1.1  mycroft 	if (--clp->c_cc == 0)
    137      1.1  mycroft 		clp->c_cf = clp->c_cl = (u_char *)0;
    138      1.1  mycroft out:
    139      1.1  mycroft 	splx(s);
    140      1.1  mycroft 	return c;
    141      1.1  mycroft }
    142      1.1  mycroft 
    143      1.1  mycroft /*
    144      1.1  mycroft  * Copy clist to buffer.
    145      1.1  mycroft  * Return number of bytes moved.
    146      1.1  mycroft  */
    147      1.1  mycroft int
    148      1.1  mycroft q_to_b(clp, cp, count)
    149      1.1  mycroft 	struct clist *clp;
    150      1.1  mycroft 	u_char *cp;
    151      1.1  mycroft 	int count;
    152      1.1  mycroft {
    153      1.1  mycroft 	register int cc;
    154      1.1  mycroft 	u_char *p = cp;
    155      1.1  mycroft 	int s;
    156      1.1  mycroft 
    157      1.1  mycroft 	s = spltty();
    158      1.1  mycroft 	/* optimize this while loop */
    159      1.1  mycroft 	while (count > 0 && clp->c_cc > 0) {
    160      1.1  mycroft 		cc = clp->c_cl - clp->c_cf;
    161      1.1  mycroft 		if (clp->c_cf >= clp->c_cl)
    162      1.1  mycroft 			cc = clp->c_ce - clp->c_cf;
    163      1.1  mycroft 		if (cc > count)
    164      1.1  mycroft 			cc = count;
    165      1.1  mycroft 		bcopy(clp->c_cf, p, cc);
    166      1.1  mycroft 		count -= cc;
    167      1.1  mycroft 		p += cc;
    168      1.1  mycroft 		clp->c_cc -= cc;
    169      1.1  mycroft 		clp->c_cf += cc;
    170      1.1  mycroft 		if (clp->c_cf == clp->c_ce)
    171      1.1  mycroft 			clp->c_cf = clp->c_cs;
    172      1.1  mycroft 	}
    173      1.1  mycroft 	if (clp->c_cc == 0)
    174      1.1  mycroft 		clp->c_cf = clp->c_cl = (u_char *)0;
    175      1.1  mycroft 	splx(s);
    176      1.1  mycroft 	return p - cp;
    177      1.1  mycroft }
    178      1.1  mycroft 
    179      1.1  mycroft /*
    180      1.1  mycroft  * Return count of contiguous characters in clist.
    181      1.1  mycroft  * Stop counting if flag&character is non-null.
    182      1.1  mycroft  */
    183      1.1  mycroft ndqb(clp, flag)
    184      1.1  mycroft 	struct clist *clp;
    185      1.1  mycroft 	int flag;
    186      1.1  mycroft {
    187      1.1  mycroft 	int count = 0;
    188      1.1  mycroft 	register int i;
    189      1.1  mycroft 	register int cc;
    190      1.1  mycroft 	int s;
    191      1.1  mycroft 
    192      1.1  mycroft 	s = spltty();
    193      1.1  mycroft 	if ((cc = clp->c_cc) == 0 || flag == 0)
    194      1.1  mycroft 		goto out;
    195      1.1  mycroft 
    196      1.1  mycroft 	i = clp->c_cf - clp->c_cs;
    197      1.1  mycroft 	while (cc-- > 0 && (clp->c_cs[i++] & flag) == 0) {
    198      1.1  mycroft 		count++;
    199      1.1  mycroft 		if (i == clp->c_cn)
    200      1.1  mycroft 			break;
    201      1.1  mycroft 	}
    202      1.1  mycroft out:
    203      1.1  mycroft 	splx(s);
    204      1.1  mycroft 	return count;
    205      1.1  mycroft }
    206      1.1  mycroft 
    207      1.1  mycroft /*
    208      1.1  mycroft  * Flush count bytes from clist.
    209      1.1  mycroft  */
    210      1.1  mycroft void
    211      1.1  mycroft ndflush(clp, count)
    212      1.1  mycroft 	struct clist *clp;
    213      1.1  mycroft 	int count;
    214      1.1  mycroft {
    215      1.1  mycroft 	register int cc;
    216      1.1  mycroft 	int s;
    217      1.1  mycroft 
    218      1.1  mycroft 	s = spltty();
    219      1.1  mycroft 	if (count == clp->c_cc) {
    220      1.1  mycroft 		clp->c_cc = 0;
    221      1.1  mycroft 		clp->c_cf = clp->c_cl = (u_char *)0;
    222      1.1  mycroft 		goto out;
    223      1.1  mycroft 	}
    224      1.1  mycroft 	/* optimize this while loop */
    225      1.1  mycroft 	while (count > 0 && clp->c_cc > 0) {
    226      1.1  mycroft 		cc = clp->c_cl - clp->c_cf;
    227      1.1  mycroft 		if (clp->c_cf >= clp->c_cl)
    228      1.1  mycroft 			cc = clp->c_ce - clp->c_cf;
    229      1.1  mycroft 		if (cc > count)
    230      1.1  mycroft 			cc = count;
    231      1.1  mycroft 		count -= cc;
    232      1.1  mycroft 		clp->c_cc -= cc;
    233      1.1  mycroft 		clp->c_cf += cc;
    234      1.1  mycroft 		if (clp->c_cf == clp->c_ce)
    235      1.1  mycroft 			clp->c_cf = clp->c_cs;
    236      1.1  mycroft 	}
    237      1.1  mycroft 	if (clp->c_cc == 0)
    238      1.1  mycroft 		clp->c_cf = clp->c_cl = (u_char *)0;
    239      1.1  mycroft out:
    240      1.1  mycroft 	splx(s);
    241      1.1  mycroft }
    242      1.1  mycroft 
    243      1.1  mycroft /*
    244      1.1  mycroft  * Put a character into the output queue.
    245      1.1  mycroft  */
    246      1.1  mycroft int
    247      1.1  mycroft putc(c, clp)
    248      1.1  mycroft 	int c;
    249      1.1  mycroft 	struct clist *clp;
    250      1.1  mycroft {
    251      1.1  mycroft 	register u_char *q;
    252      1.1  mycroft 	register int i;
    253      1.1  mycroft 	int r = -1;
    254      1.1  mycroft 	int s;
    255      1.1  mycroft 
    256      1.1  mycroft 	s = spltty();
    257      1.1  mycroft 	if (clp->c_cc == clp->c_cn)
    258      1.1  mycroft 		goto out;
    259      1.1  mycroft 
    260      1.1  mycroft 	if (clp->c_cc == 0) {
    261      1.1  mycroft 		if (!clp->c_cs) {
    262      1.1  mycroft #if defined(DIAGNOSTIC) || 1
    263      1.1  mycroft 			printf("b_to_q: required clalloc\n");
    264      1.1  mycroft #endif
    265      1.1  mycroft 			if(clalloc(clp, 1024, 1)) {
    266      1.1  mycroft out:
    267      1.1  mycroft 				splx(s);
    268      1.1  mycroft 				return -1;
    269      1.1  mycroft 			}
    270      1.1  mycroft 		}
    271      1.1  mycroft 		clp->c_cf = clp->c_cl = clp->c_cs;
    272      1.1  mycroft 	}
    273      1.1  mycroft 
    274      1.1  mycroft 	*clp->c_cl = c & 0xff;
    275      1.1  mycroft 	i = clp->c_cl - clp->c_cs;
    276      1.1  mycroft 	if (clp->c_cq) {
    277      1.1  mycroft #ifdef QBITS
    278      1.1  mycroft 		if (c & TTY_QUOTE)
    279      1.1  mycroft 			setbit(clp->c_cq, i);
    280      1.1  mycroft 		else
    281      1.1  mycroft 			clrbit(clp->c_cq, i);
    282      1.1  mycroft #else
    283      1.1  mycroft 		q = clp->c_cq + i;
    284      1.1  mycroft 		*q = (c & TTY_QUOTE) ? 1 : 0;
    285      1.1  mycroft #endif
    286      1.1  mycroft 	}
    287      1.1  mycroft 	clp->c_cc++;
    288      1.1  mycroft 	clp->c_cl++;
    289      1.1  mycroft 	if (clp->c_cl == clp->c_ce)
    290      1.1  mycroft 		clp->c_cl = clp->c_cs;
    291      1.1  mycroft 	splx(s);
    292      1.1  mycroft 	return 0;
    293      1.1  mycroft }
    294      1.1  mycroft 
    295      1.1  mycroft #ifdef QBITS
    296      1.1  mycroft /*
    297      1.1  mycroft  * optimized version of
    298      1.1  mycroft  *
    299      1.1  mycroft  * for (i = 0; i < len; i++)
    300      1.1  mycroft  *	clrbit(cp, off + len);
    301      1.1  mycroft  */
    302      1.1  mycroft void
    303      1.1  mycroft clrbits(cp, off, len)
    304      1.1  mycroft 	u_char *cp;
    305      1.1  mycroft 	int off;
    306      1.1  mycroft 	int len;
    307      1.1  mycroft {
    308      1.1  mycroft 	int sby, sbi, eby, ebi;
    309      1.1  mycroft 	register int i;
    310      1.1  mycroft 	u_char mask;
    311      1.1  mycroft 
    312      1.1  mycroft 	if(len==1) {
    313      1.1  mycroft 		clrbit(cp, off);
    314      1.1  mycroft 		return;
    315      1.1  mycroft 	}
    316      1.1  mycroft 
    317      1.1  mycroft 	sby = off / NBBY;
    318      1.1  mycroft 	sbi = off % NBBY;
    319      1.1  mycroft 	eby = (off+len) / NBBY;
    320      1.1  mycroft 	ebi = (off+len) % NBBY;
    321      1.1  mycroft 	if (sby == eby) {
    322      1.1  mycroft 		mask = ((1 << (ebi - sbi)) - 1) << sbi;
    323      1.1  mycroft 		cp[sby] &= ~mask;
    324      1.1  mycroft 	} else {
    325      1.1  mycroft 		mask = (1<<sbi) - 1;
    326      1.1  mycroft 		cp[sby++] &= mask;
    327      1.1  mycroft 
    328      1.1  mycroft 		mask = (1<<ebi) - 1;
    329      1.1  mycroft 		cp[eby] &= ~mask;
    330      1.1  mycroft 
    331      1.1  mycroft 		for (i = sby; i < eby; i++)
    332      1.1  mycroft 			cp[i] = 0x00;
    333      1.1  mycroft 	}
    334      1.1  mycroft }
    335      1.1  mycroft #endif
    336      1.1  mycroft 
    337      1.1  mycroft /*
    338      1.1  mycroft  * Copy buffer to clist.
    339      1.1  mycroft  * Return number of bytes not transfered.
    340      1.1  mycroft  */
    341      1.1  mycroft int
    342      1.1  mycroft b_to_q(cp, count, clp)
    343      1.1  mycroft 	u_char *cp;
    344      1.1  mycroft 	int count;
    345      1.1  mycroft 	struct clist *clp;
    346      1.1  mycroft {
    347      1.1  mycroft 	register int i, cc;
    348      1.1  mycroft 	register u_char *p = cp;
    349      1.1  mycroft 	int off, s;
    350      1.1  mycroft 
    351      1.1  mycroft 	if (count <= 0)
    352      1.1  mycroft 		return 0;
    353      1.1  mycroft 
    354      1.1  mycroft 	s = spltty();
    355      1.1  mycroft 	if (clp->c_cc == clp->c_cn)
    356      1.1  mycroft 		goto out;
    357      1.1  mycroft 
    358      1.1  mycroft 	if (clp->c_cc == 0) {
    359      1.1  mycroft 		if (!clp->c_cs) {
    360      1.1  mycroft #if defined(DIAGNOSTIC) || 1
    361      1.1  mycroft 			printf("b_to_q: required clalloc\n");
    362      1.1  mycroft #endif
    363      1.1  mycroft 			if(clalloc(clp, 1024, 1))
    364      1.1  mycroft 				goto out;
    365      1.1  mycroft 		}
    366      1.1  mycroft 		clp->c_cf = clp->c_cl = clp->c_cs;
    367      1.1  mycroft 	}
    368      1.1  mycroft 
    369      1.1  mycroft 	/* optimize this while loop */
    370      1.1  mycroft 	while (count > 0 && clp->c_cc < clp->c_cn) {
    371      1.1  mycroft 		cc = clp->c_ce - clp->c_cl;
    372      1.1  mycroft 		if (clp->c_cf > clp->c_cl)
    373      1.1  mycroft 			cc = clp->c_cf - clp->c_cl;
    374      1.1  mycroft 		if (cc > count)
    375      1.1  mycroft 			cc = count;
    376      1.1  mycroft 		bcopy(p, clp->c_cl, cc);
    377      1.1  mycroft 		if (clp->c_cq) {
    378      1.1  mycroft #ifdef QBITS
    379      1.1  mycroft 			clrbits(clp->c_cq, clp->c_cl - clp->c_cs, cc);
    380      1.1  mycroft #else
    381      1.1  mycroft 			bzero(clp->c_cl - clp->c_cs + clp->c_cq, cc);
    382      1.1  mycroft #endif
    383      1.1  mycroft 		}
    384      1.1  mycroft 		p += cc;
    385      1.1  mycroft 		count -= cc;
    386      1.1  mycroft 		clp->c_cc += cc;
    387      1.1  mycroft 		clp->c_cl += cc;
    388      1.1  mycroft 		if (clp->c_cl == clp->c_ce)
    389      1.1  mycroft 			clp->c_cl = clp->c_cs;
    390      1.1  mycroft 	}
    391      1.1  mycroft out:
    392      1.1  mycroft 	splx(s);
    393      1.1  mycroft 	return count;
    394      1.1  mycroft }
    395      1.1  mycroft 
    396      1.1  mycroft static int cc;
    397      1.1  mycroft 
    398      1.1  mycroft /*
    399      1.1  mycroft  * Given a non-NULL pointer into the clist return the pointer
    400      1.1  mycroft  * to the next character in the list or return NULL if no more chars.
    401      1.1  mycroft  *
    402      1.1  mycroft  * Callers must not allow getc's to happen between firstc's and getc's
    403      1.1  mycroft  * so that the pointer becomes invalid.  Note that interrupts are NOT
    404      1.1  mycroft  * masked.
    405      1.1  mycroft  */
    406      1.1  mycroft u_char *
    407      1.1  mycroft nextc(clp, cp, c)
    408      1.1  mycroft 	struct clist *clp;
    409      1.1  mycroft 	register u_char *cp;
    410      1.1  mycroft 	int *c;
    411      1.1  mycroft {
    412      1.1  mycroft 
    413      1.1  mycroft 	if (clp->c_cf == cp) {
    414      1.1  mycroft 		/*
    415      1.1  mycroft 		 * First time initialization.
    416      1.1  mycroft 		 */
    417      1.1  mycroft 		cc = clp->c_cc;
    418      1.1  mycroft 	}
    419      1.1  mycroft 	if (cc == 0 || cp == NULL)
    420      1.1  mycroft 		return NULL;
    421      1.1  mycroft 	if (--cc == 0)
    422      1.1  mycroft 		return NULL;
    423      1.1  mycroft 	if (++cp == clp->c_ce)
    424      1.1  mycroft 		cp = clp->c_cs;
    425      1.1  mycroft 	*c = *cp & 0xff;
    426      1.1  mycroft 	if (clp->c_cq) {
    427      1.1  mycroft #ifdef QBITS
    428      1.1  mycroft 		if (isset(clp->c_cq, cp - clp->c_cs))
    429      1.1  mycroft 			*c |= TTY_QUOTE;
    430      1.1  mycroft #else
    431      1.1  mycroft 		if (*(clp->c_cf - clp->c_cs + clp->c_cq))
    432      1.1  mycroft 			*c |= TTY_QUOTE;
    433      1.1  mycroft #endif
    434      1.1  mycroft 	}
    435      1.1  mycroft 	return cp;
    436      1.1  mycroft }
    437      1.1  mycroft 
    438      1.1  mycroft /*
    439      1.1  mycroft  * Given a non-NULL pointer into the clist return the pointer
    440      1.1  mycroft  * to the first character in the list or return NULL if no more chars.
    441      1.1  mycroft  *
    442      1.1  mycroft  * Callers must not allow getc's to happen between firstc's and getc's
    443      1.1  mycroft  * so that the pointer becomes invalid.  Note that interrupts are NOT
    444      1.1  mycroft  * masked.
    445      1.1  mycroft  *
    446      1.1  mycroft  * *c is set to the NEXT character
    447      1.1  mycroft  */
    448      1.1  mycroft u_char *
    449      1.1  mycroft firstc(clp, c)
    450      1.1  mycroft 	struct clist *clp;
    451      1.1  mycroft 	int *c;
    452      1.1  mycroft {
    453      1.1  mycroft 	int empty = 0;
    454      1.1  mycroft 	register u_char *cp;
    455      1.1  mycroft 	register int i;
    456      1.1  mycroft 
    457      1.1  mycroft 	cc = clp->c_cc;
    458      1.1  mycroft 	if (cc == 0)
    459      1.1  mycroft 		return NULL;
    460      1.1  mycroft 	cp = clp->c_cf;
    461      1.1  mycroft 	*c = *cp & 0xff;
    462      1.1  mycroft 	if(clp->c_cq) {
    463      1.1  mycroft #ifdef QBITS
    464      1.1  mycroft 		if (isset(clp->c_cq, cp - clp->c_cs))
    465      1.1  mycroft 			*c |= TTY_QUOTE;
    466      1.1  mycroft #else
    467      1.1  mycroft 		if (*(cp - clp->c_cs + clp->c_cq))
    468      1.1  mycroft 			*c |= TTY_QUOTE;
    469      1.1  mycroft #endif
    470      1.1  mycroft 	}
    471      1.1  mycroft 	return clp->c_cf;
    472      1.1  mycroft }
    473      1.1  mycroft 
    474      1.1  mycroft /*
    475      1.1  mycroft  * Remove the last character in the clist and return it.
    476      1.1  mycroft  */
    477      1.1  mycroft int
    478      1.1  mycroft unputc(clp)
    479      1.1  mycroft 	struct clist *clp;
    480      1.1  mycroft {
    481      1.1  mycroft 	unsigned int c = -1;
    482      1.1  mycroft 	int s;
    483      1.1  mycroft 
    484      1.1  mycroft 	s = spltty();
    485      1.1  mycroft 	if (clp->c_cc == 0)
    486      1.1  mycroft 		goto out;
    487      1.1  mycroft 
    488      1.1  mycroft 	if (clp->c_cl == clp->c_cs)
    489      1.1  mycroft 		clp->c_cl = clp->c_ce - 1;
    490      1.1  mycroft 	else
    491      1.1  mycroft 		--clp->c_cl;
    492      1.1  mycroft 	clp->c_cc--;
    493      1.1  mycroft 
    494      1.1  mycroft 	c = *clp->c_cl & 0xff;
    495      1.1  mycroft 	if (clp->c_cq) {
    496      1.1  mycroft #ifdef QBITS
    497      1.1  mycroft 		if (isset(clp->c_cq, clp->c_cl - clp->c_cs))
    498      1.1  mycroft 			c |= TTY_QUOTE;
    499      1.1  mycroft #else
    500      1.1  mycroft 		if (*(clp->c_cf - clp->c_cs + clp->c_cq))
    501      1.1  mycroft 			c | TTY_QUOTE;
    502      1.1  mycroft #endif
    503      1.1  mycroft 	}
    504      1.1  mycroft 	if (clp->c_cc == 0)
    505      1.1  mycroft 		clp->c_cf = clp->c_cl = (u_char *)0;
    506      1.1  mycroft out:
    507      1.1  mycroft 	splx(s);
    508      1.1  mycroft 	return c;
    509      1.1  mycroft }
    510      1.1  mycroft 
    511      1.1  mycroft /*
    512      1.1  mycroft  * Put the chars in the from queue on the end of the to queue.
    513      1.1  mycroft  */
    514      1.1  mycroft void
    515      1.1  mycroft catq(from, to)
    516      1.1  mycroft 	struct clist *from, *to;
    517      1.1  mycroft {
    518      1.1  mycroft 	int c;
    519      1.1  mycroft 
    520      1.1  mycroft 	while ((c = getc(from)) != -1)
    521      1.1  mycroft 		putc(c, to);
    522      1.1  mycroft }
    523