Home | History | Annotate | Line # | Download | only in telnetd
slc.c revision 1.1.1.2
      1      1.1      cgd /*
      2  1.1.1.2  mycroft  * Copyright (c) 1989, 1993
      3  1.1.1.2  mycroft  *	The Regents of the University of California.  All rights reserved.
      4      1.1      cgd  *
      5      1.1      cgd  * Redistribution and use in source and binary forms, with or without
      6      1.1      cgd  * modification, are permitted provided that the following conditions
      7      1.1      cgd  * are met:
      8      1.1      cgd  * 1. Redistributions of source code must retain the above copyright
      9      1.1      cgd  *    notice, this list of conditions and the following disclaimer.
     10      1.1      cgd  * 2. Redistributions in binary form must reproduce the above copyright
     11      1.1      cgd  *    notice, this list of conditions and the following disclaimer in the
     12      1.1      cgd  *    documentation and/or other materials provided with the distribution.
     13      1.1      cgd  * 3. All advertising materials mentioning features or use of this software
     14      1.1      cgd  *    must display the following acknowledgement:
     15      1.1      cgd  *	This product includes software developed by the University of
     16      1.1      cgd  *	California, Berkeley and its contributors.
     17      1.1      cgd  * 4. Neither the name of the University nor the names of its contributors
     18      1.1      cgd  *    may be used to endorse or promote products derived from this software
     19      1.1      cgd  *    without specific prior written permission.
     20      1.1      cgd  *
     21      1.1      cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22      1.1      cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23      1.1      cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24      1.1      cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25      1.1      cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26      1.1      cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27      1.1      cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28      1.1      cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29      1.1      cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30      1.1      cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31      1.1      cgd  * SUCH DAMAGE.
     32      1.1      cgd  */
     33      1.1      cgd 
     34      1.1      cgd #ifndef lint
     35  1.1.1.2  mycroft static char sccsid[] = "@(#)slc.c	8.1 (Berkeley) 6/4/93";
     36      1.1      cgd #endif /* not lint */
     37      1.1      cgd 
     38      1.1      cgd #include "telnetd.h"
     39      1.1      cgd 
     40      1.1      cgd #ifdef	LINEMODE
     41      1.1      cgd /*
     42      1.1      cgd  * local varibles
     43      1.1      cgd  */
     44      1.1      cgd static unsigned char	*def_slcbuf = (unsigned char *)0;
     45      1.1      cgd static int		def_slclen = 0;
     46      1.1      cgd static int		slcchange;	/* change to slc is requested */
     47      1.1      cgd static unsigned char	*slcptr;	/* pointer into slc buffer */
     48      1.1      cgd static unsigned char	slcbuf[NSLC*6];	/* buffer for slc negotiation */
     49      1.1      cgd 
     50      1.1      cgd /*
     51      1.1      cgd  * send_slc
     52      1.1      cgd  *
     53      1.1      cgd  * Write out the current special characters to the client.
     54      1.1      cgd  */
     55      1.1      cgd 	void
     56      1.1      cgd send_slc()
     57      1.1      cgd {
     58      1.1      cgd 	register int i;
     59      1.1      cgd 
     60      1.1      cgd 	/*
     61      1.1      cgd 	 * Send out list of triplets of special characters
     62      1.1      cgd 	 * to client.  We only send info on the characters
     63      1.1      cgd 	 * that are currently supported.
     64      1.1      cgd 	 */
     65      1.1      cgd 	for (i = 1; i <= NSLC; i++) {
     66      1.1      cgd 		if ((slctab[i].defset.flag & SLC_LEVELBITS) == SLC_NOSUPPORT)
     67      1.1      cgd 			continue;
     68      1.1      cgd 		add_slc((unsigned char)i, slctab[i].current.flag,
     69      1.1      cgd 							slctab[i].current.val);
     70      1.1      cgd 	}
     71      1.1      cgd 
     72      1.1      cgd }  /* end of send_slc */
     73      1.1      cgd 
     74      1.1      cgd /*
     75      1.1      cgd  * default_slc
     76      1.1      cgd  *
     77      1.1      cgd  * Set pty special characters to all the defaults.
     78      1.1      cgd  */
     79      1.1      cgd 	void
     80      1.1      cgd default_slc()
     81      1.1      cgd {
     82      1.1      cgd 	register int i;
     83      1.1      cgd 
     84      1.1      cgd 	for (i = 1; i <= NSLC; i++) {
     85      1.1      cgd 		slctab[i].current.val = slctab[i].defset.val;
     86      1.1      cgd 		if (slctab[i].current.val == (cc_t)(_POSIX_VDISABLE))
     87      1.1      cgd 			slctab[i].current.flag = SLC_NOSUPPORT;
     88      1.1      cgd 		else
     89      1.1      cgd 			slctab[i].current.flag = slctab[i].defset.flag;
     90      1.1      cgd 		if (slctab[i].sptr) {
     91      1.1      cgd 			*(slctab[i].sptr) = slctab[i].defset.val;
     92      1.1      cgd 		}
     93      1.1      cgd 	}
     94      1.1      cgd 	slcchange = 1;
     95      1.1      cgd 
     96      1.1      cgd }  /* end of default_slc */
     97      1.1      cgd #endif	/* LINEMODE */
     98      1.1      cgd 
     99      1.1      cgd /*
    100      1.1      cgd  * get_slc_defaults
    101      1.1      cgd  *
    102      1.1      cgd  * Initialize the slc mapping table.
    103      1.1      cgd  */
    104      1.1      cgd 	void
    105      1.1      cgd get_slc_defaults()
    106      1.1      cgd {
    107      1.1      cgd 	register int i;
    108      1.1      cgd 
    109      1.1      cgd 	init_termbuf();
    110      1.1      cgd 
    111      1.1      cgd 	for (i = 1; i <= NSLC; i++) {
    112      1.1      cgd 		slctab[i].defset.flag =
    113      1.1      cgd 			spcset(i, &slctab[i].defset.val, &slctab[i].sptr);
    114      1.1      cgd 		slctab[i].current.flag = SLC_NOSUPPORT;
    115      1.1      cgd 		slctab[i].current.val = 0;
    116      1.1      cgd 	}
    117      1.1      cgd 
    118      1.1      cgd }  /* end of get_slc_defaults */
    119      1.1      cgd 
    120      1.1      cgd #ifdef	LINEMODE
    121      1.1      cgd /*
    122      1.1      cgd  * add_slc
    123      1.1      cgd  *
    124      1.1      cgd  * Add an slc triplet to the slc buffer.
    125      1.1      cgd  */
    126      1.1      cgd 	void
    127      1.1      cgd add_slc(func, flag, val)
    128      1.1      cgd 	register char func, flag;
    129      1.1      cgd 	register cc_t val;
    130      1.1      cgd {
    131      1.1      cgd 
    132      1.1      cgd 	if ((*slcptr++ = (unsigned char)func) == 0xff)
    133      1.1      cgd 		*slcptr++ = 0xff;
    134      1.1      cgd 
    135      1.1      cgd 	if ((*slcptr++ = (unsigned char)flag) == 0xff)
    136      1.1      cgd 		*slcptr++ = 0xff;
    137      1.1      cgd 
    138      1.1      cgd 	if ((*slcptr++ = (unsigned char)val) == 0xff)
    139      1.1      cgd 		*slcptr++ = 0xff;
    140      1.1      cgd 
    141      1.1      cgd }  /* end of add_slc */
    142      1.1      cgd 
    143      1.1      cgd /*
    144      1.1      cgd  * start_slc
    145      1.1      cgd  *
    146      1.1      cgd  * Get ready to process incoming slc's and respond to them.
    147      1.1      cgd  *
    148      1.1      cgd  * The parameter getit is non-zero if it is necessary to grab a copy
    149      1.1      cgd  * of the terminal control structures.
    150      1.1      cgd  */
    151      1.1      cgd 	void
    152      1.1      cgd start_slc(getit)
    153      1.1      cgd 	register int getit;
    154      1.1      cgd {
    155      1.1      cgd 
    156      1.1      cgd 	slcchange = 0;
    157      1.1      cgd 	if (getit)
    158      1.1      cgd 		init_termbuf();
    159      1.1      cgd 	(void) sprintf((char *)slcbuf, "%c%c%c%c",
    160      1.1      cgd 					IAC, SB, TELOPT_LINEMODE, LM_SLC);
    161      1.1      cgd 	slcptr = slcbuf + 4;
    162      1.1      cgd 
    163      1.1      cgd }  /* end of start_slc */
    164      1.1      cgd 
    165      1.1      cgd /*
    166      1.1      cgd  * end_slc
    167      1.1      cgd  *
    168      1.1      cgd  * Finish up the slc negotiation.  If something to send, then send it.
    169      1.1      cgd  */
    170      1.1      cgd 	int
    171      1.1      cgd end_slc(bufp)
    172      1.1      cgd 	register unsigned char **bufp;
    173      1.1      cgd {
    174      1.1      cgd 	register int len;
    175      1.1      cgd 	void netflush();
    176      1.1      cgd 
    177      1.1      cgd 	/*
    178      1.1      cgd 	 * If a change has occured, store the new terminal control
    179      1.1      cgd 	 * structures back to the terminal driver.
    180      1.1      cgd 	 */
    181      1.1      cgd 	if (slcchange) {
    182      1.1      cgd 		set_termbuf();
    183      1.1      cgd 	}
    184      1.1      cgd 
    185      1.1      cgd 	/*
    186      1.1      cgd 	 * If the pty state has not yet been fully processed and there is a
    187      1.1      cgd 	 * deferred slc request from the client, then do not send any
    188      1.1      cgd 	 * sort of slc negotiation now.  We will respond to the client's
    189      1.1      cgd 	 * request very soon.
    190      1.1      cgd 	 */
    191      1.1      cgd 	if (def_slcbuf && (terminit() == 0)) {
    192      1.1      cgd 		return(0);
    193      1.1      cgd 	}
    194      1.1      cgd 
    195      1.1      cgd 	if (slcptr > (slcbuf + 4)) {
    196      1.1      cgd 		if (bufp) {
    197      1.1      cgd 			*bufp = &slcbuf[4];
    198      1.1      cgd 			return(slcptr - slcbuf - 4);
    199      1.1      cgd 		} else {
    200      1.1      cgd 			(void) sprintf((char *)slcptr, "%c%c", IAC, SE);
    201      1.1      cgd 			slcptr += 2;
    202      1.1      cgd 			len = slcptr - slcbuf;
    203      1.1      cgd 			writenet(slcbuf, len);
    204      1.1      cgd 			netflush();  /* force it out immediately */
    205  1.1.1.2  mycroft 			DIAG(TD_OPTIONS, printsub('>', slcbuf+2, len-2););
    206      1.1      cgd 		}
    207      1.1      cgd 	}
    208      1.1      cgd 	return (0);
    209      1.1      cgd 
    210      1.1      cgd }  /* end of end_slc */
    211      1.1      cgd 
    212      1.1      cgd /*
    213      1.1      cgd  * process_slc
    214      1.1      cgd  *
    215      1.1      cgd  * Figure out what to do about the client's slc
    216      1.1      cgd  */
    217      1.1      cgd 	void
    218      1.1      cgd process_slc(func, flag, val)
    219      1.1      cgd 	register unsigned char func, flag;
    220      1.1      cgd 	register cc_t val;
    221      1.1      cgd {
    222      1.1      cgd 	register int hislevel, mylevel, ack;
    223      1.1      cgd 
    224      1.1      cgd 	/*
    225      1.1      cgd 	 * Ensure that we know something about this function
    226      1.1      cgd 	 */
    227      1.1      cgd 	if (func > NSLC) {
    228      1.1      cgd 		add_slc(func, SLC_NOSUPPORT, 0);
    229      1.1      cgd 		return;
    230      1.1      cgd 	}
    231      1.1      cgd 
    232      1.1      cgd 	/*
    233      1.1      cgd 	 * Process the special case requests of 0 SLC_DEFAULT 0
    234      1.1      cgd 	 * and 0 SLC_VARIABLE 0.  Be a little forgiving here, don't
    235      1.1      cgd 	 * worry about whether the value is actually 0 or not.
    236      1.1      cgd 	 */
    237      1.1      cgd 	if (func == 0) {
    238      1.1      cgd 		if ((flag = flag & SLC_LEVELBITS) == SLC_DEFAULT) {
    239      1.1      cgd 			default_slc();
    240      1.1      cgd 			send_slc();
    241      1.1      cgd 		} else if (flag == SLC_VARIABLE) {
    242      1.1      cgd 			send_slc();
    243      1.1      cgd 		}
    244      1.1      cgd 		return;
    245      1.1      cgd 	}
    246      1.1      cgd 
    247      1.1      cgd 	/*
    248      1.1      cgd 	 * Appears to be a function that we know something about.  So
    249      1.1      cgd 	 * get on with it and see what we know.
    250      1.1      cgd 	 */
    251      1.1      cgd 
    252      1.1      cgd 	hislevel = flag & SLC_LEVELBITS;
    253      1.1      cgd 	mylevel = slctab[func].current.flag & SLC_LEVELBITS;
    254      1.1      cgd 	ack = flag & SLC_ACK;
    255      1.1      cgd 	/*
    256      1.1      cgd 	 * ignore the command if:
    257      1.1      cgd 	 * the function value and level are the same as what we already have;
    258      1.1      cgd 	 * or the level is the same and the ack bit is set
    259      1.1      cgd 	 */
    260      1.1      cgd 	if (hislevel == mylevel && (val == slctab[func].current.val || ack)) {
    261      1.1      cgd 		return;
    262      1.1      cgd 	} else if (ack) {
    263      1.1      cgd 		/*
    264      1.1      cgd 		 * If we get here, we got an ack, but the levels don't match.
    265      1.1      cgd 		 * This shouldn't happen.  If it does, it is probably because
    266      1.1      cgd 		 * we have sent two requests to set a variable without getting
    267      1.1      cgd 		 * a response between them, and this is the first response.
    268      1.1      cgd 		 * So, ignore it, and wait for the next response.
    269      1.1      cgd 		 */
    270      1.1      cgd 		return;
    271      1.1      cgd 	} else {
    272      1.1      cgd 		change_slc(func, flag, val);
    273      1.1      cgd 	}
    274      1.1      cgd 
    275      1.1      cgd }  /* end of process_slc */
    276      1.1      cgd 
    277      1.1      cgd /*
    278      1.1      cgd  * change_slc
    279      1.1      cgd  *
    280      1.1      cgd  * Process a request to change one of our special characters.
    281      1.1      cgd  * Compare client's request with what we are capable of supporting.
    282      1.1      cgd  */
    283      1.1      cgd 	void
    284      1.1      cgd change_slc(func, flag, val)
    285      1.1      cgd 	register char func, flag;
    286      1.1      cgd 	register cc_t val;
    287      1.1      cgd {
    288      1.1      cgd 	register int hislevel, mylevel;
    289      1.1      cgd 
    290      1.1      cgd 	hislevel = flag & SLC_LEVELBITS;
    291      1.1      cgd 	mylevel = slctab[func].defset.flag & SLC_LEVELBITS;
    292      1.1      cgd 	/*
    293      1.1      cgd 	 * If client is setting a function to NOSUPPORT
    294      1.1      cgd 	 * or DEFAULT, then we can easily and directly
    295      1.1      cgd 	 * accomodate the request.
    296      1.1      cgd 	 */
    297      1.1      cgd 	if (hislevel == SLC_NOSUPPORT) {
    298      1.1      cgd 		slctab[func].current.flag = flag;
    299      1.1      cgd 		slctab[func].current.val = (cc_t)_POSIX_VDISABLE;
    300      1.1      cgd 		flag |= SLC_ACK;
    301      1.1      cgd 		add_slc(func, flag, val);
    302      1.1      cgd 		return;
    303      1.1      cgd 	}
    304      1.1      cgd 	if (hislevel == SLC_DEFAULT) {
    305      1.1      cgd 		/*
    306      1.1      cgd 		 * Special case here.  If client tells us to use
    307      1.1      cgd 		 * the default on a function we don't support, then
    308      1.1      cgd 		 * return NOSUPPORT instead of what we may have as a
    309      1.1      cgd 		 * default level of DEFAULT.
    310      1.1      cgd 		 */
    311      1.1      cgd 		if (mylevel == SLC_DEFAULT) {
    312      1.1      cgd 			slctab[func].current.flag = SLC_NOSUPPORT;
    313      1.1      cgd 		} else {
    314      1.1      cgd 			slctab[func].current.flag = slctab[func].defset.flag;
    315      1.1      cgd 		}
    316      1.1      cgd 		slctab[func].current.val = slctab[func].defset.val;
    317      1.1      cgd 		add_slc(func, slctab[func].current.flag,
    318      1.1      cgd 						slctab[func].current.val);
    319      1.1      cgd 		return;
    320      1.1      cgd 	}
    321      1.1      cgd 
    322      1.1      cgd 	/*
    323      1.1      cgd 	 * Client wants us to change to a new value or he
    324      1.1      cgd 	 * is telling us that he can't change to our value.
    325      1.1      cgd 	 * Some of the slc's we support and can change,
    326      1.1      cgd 	 * some we do support but can't change,
    327      1.1      cgd 	 * and others we don't support at all.
    328      1.1      cgd 	 * If we can change it then we have a pointer to
    329      1.1      cgd 	 * the place to put the new value, so change it,
    330      1.1      cgd 	 * otherwise, continue the negotiation.
    331      1.1      cgd 	 */
    332      1.1      cgd 	if (slctab[func].sptr) {
    333      1.1      cgd 		/*
    334      1.1      cgd 		 * We can change this one.
    335      1.1      cgd 		 */
    336      1.1      cgd 		slctab[func].current.val = val;
    337      1.1      cgd 		*(slctab[func].sptr) = val;
    338      1.1      cgd 		slctab[func].current.flag = flag;
    339      1.1      cgd 		flag |= SLC_ACK;
    340      1.1      cgd 		slcchange = 1;
    341      1.1      cgd 		add_slc(func, flag, val);
    342      1.1      cgd 	} else {
    343      1.1      cgd 		/*
    344      1.1      cgd 		* It is not possible for us to support this
    345      1.1      cgd 		* request as he asks.
    346      1.1      cgd 		*
    347      1.1      cgd 		* If our level is DEFAULT, then just ack whatever was
    348      1.1      cgd 		* sent.
    349      1.1      cgd 		*
    350      1.1      cgd 		* If he can't change and we can't change,
    351      1.1      cgd 		* then degenerate to NOSUPPORT.
    352      1.1      cgd 		*
    353      1.1      cgd 		* Otherwise we send our level back to him, (CANTCHANGE
    354      1.1      cgd 		* or NOSUPPORT) and if CANTCHANGE, send
    355      1.1      cgd 		* our value as well.
    356      1.1      cgd 		*/
    357      1.1      cgd 		if (mylevel == SLC_DEFAULT) {
    358      1.1      cgd 			slctab[func].current.flag = flag;
    359      1.1      cgd 			slctab[func].current.val = val;
    360      1.1      cgd 			flag |= SLC_ACK;
    361      1.1      cgd 		} else if (hislevel == SLC_CANTCHANGE &&
    362      1.1      cgd 				    mylevel == SLC_CANTCHANGE) {
    363      1.1      cgd 			flag &= ~SLC_LEVELBITS;
    364      1.1      cgd 			flag |= SLC_NOSUPPORT;
    365      1.1      cgd 			slctab[func].current.flag = flag;
    366      1.1      cgd 		} else {
    367      1.1      cgd 			flag &= ~SLC_LEVELBITS;
    368      1.1      cgd 			flag |= mylevel;
    369      1.1      cgd 			slctab[func].current.flag = flag;
    370      1.1      cgd 			if (mylevel == SLC_CANTCHANGE) {
    371      1.1      cgd 				slctab[func].current.val =
    372      1.1      cgd 					slctab[func].defset.val;
    373      1.1      cgd 				val = slctab[func].current.val;
    374      1.1      cgd 			}
    375      1.1      cgd 
    376      1.1      cgd 		}
    377      1.1      cgd 		add_slc(func, flag, val);
    378      1.1      cgd 	}
    379      1.1      cgd 
    380      1.1      cgd }  /* end of change_slc */
    381      1.1      cgd 
    382      1.1      cgd #if	defined(USE_TERMIO) && (VEOF == VMIN)
    383      1.1      cgd cc_t oldeofc = '\004';
    384      1.1      cgd #endif
    385      1.1      cgd 
    386      1.1      cgd /*
    387      1.1      cgd  * check_slc
    388      1.1      cgd  *
    389      1.1      cgd  * Check the special characters in use and notify the client if any have
    390      1.1      cgd  * changed.  Only those characters that are capable of being changed are
    391      1.1      cgd  * likely to have changed.  If a local change occurs, kick the support level
    392      1.1      cgd  * and flags up to the defaults.
    393      1.1      cgd  */
    394      1.1      cgd 	void
    395      1.1      cgd check_slc()
    396      1.1      cgd {
    397      1.1      cgd 	register int i;
    398      1.1      cgd 
    399      1.1      cgd 	for (i = 1; i <= NSLC; i++) {
    400      1.1      cgd #if	defined(USE_TERMIO) && (VEOF == VMIN)
    401      1.1      cgd 		/*
    402      1.1      cgd 		 * In a perfect world this would be a neat little
    403      1.1      cgd 		 * function.  But in this world, we should not notify
    404      1.1      cgd 		 * client of changes to the VEOF char when
    405      1.1      cgd 		 * ICANON is off, because it is not representing
    406      1.1      cgd 		 * a special character.
    407      1.1      cgd 		 */
    408      1.1      cgd 		if (i == SLC_EOF) {
    409      1.1      cgd 			if (!tty_isediting())
    410      1.1      cgd 				continue;
    411      1.1      cgd 			else if (slctab[i].sptr)
    412      1.1      cgd 				oldeofc = *(slctab[i].sptr);
    413      1.1      cgd 		}
    414      1.1      cgd #endif	/* defined(USE_TERMIO) && defined(SYSV_TERMIO) */
    415      1.1      cgd 		if (slctab[i].sptr &&
    416      1.1      cgd 				(*(slctab[i].sptr) != slctab[i].current.val)) {
    417      1.1      cgd 			slctab[i].current.val = *(slctab[i].sptr);
    418      1.1      cgd 			if (*(slctab[i].sptr) == (cc_t)_POSIX_VDISABLE)
    419      1.1      cgd 				slctab[i].current.flag = SLC_NOSUPPORT;
    420      1.1      cgd 			else
    421      1.1      cgd 				slctab[i].current.flag = slctab[i].defset.flag;
    422      1.1      cgd 			add_slc((unsigned char)i, slctab[i].current.flag,
    423      1.1      cgd 						slctab[i].current.val);
    424      1.1      cgd 		}
    425      1.1      cgd 	}
    426      1.1      cgd 
    427      1.1      cgd }  /* check_slc */
    428      1.1      cgd 
    429      1.1      cgd /*
    430      1.1      cgd  * do_opt_slc
    431      1.1      cgd  *
    432      1.1      cgd  * Process an slc option buffer.  Defer processing of incoming slc's
    433      1.1      cgd  * until after the terminal state has been processed.  Save the first slc
    434      1.1      cgd  * request that comes along, but discard all others.
    435      1.1      cgd  *
    436      1.1      cgd  * ptr points to the beginning of the buffer, len is the length.
    437      1.1      cgd  */
    438      1.1      cgd 	void
    439      1.1      cgd do_opt_slc(ptr, len)
    440      1.1      cgd 	register unsigned char *ptr;
    441      1.1      cgd 	register int len;
    442      1.1      cgd {
    443      1.1      cgd 	register unsigned char func, flag;
    444      1.1      cgd 	cc_t val;
    445      1.1      cgd 	register unsigned char *end = ptr + len;
    446      1.1      cgd 
    447      1.1      cgd 	if (terminit()) {  /* go ahead */
    448      1.1      cgd 		while (ptr < end) {
    449      1.1      cgd 			func = *ptr++;
    450      1.1      cgd 			if (ptr >= end) break;
    451      1.1      cgd 			flag = *ptr++;
    452      1.1      cgd 			if (ptr >= end) break;
    453      1.1      cgd 			val = (cc_t)*ptr++;
    454      1.1      cgd 
    455      1.1      cgd 			process_slc(func, flag, val);
    456      1.1      cgd 
    457      1.1      cgd 		}
    458      1.1      cgd 	} else {
    459      1.1      cgd 		/*
    460      1.1      cgd 		 * save this slc buffer if it is the first, otherwise dump
    461      1.1      cgd 		 * it.
    462      1.1      cgd 		 */
    463      1.1      cgd 		if (def_slcbuf == (unsigned char *)0) {
    464      1.1      cgd 			def_slclen = len;
    465      1.1      cgd 			def_slcbuf = (unsigned char *)malloc((unsigned)len);
    466      1.1      cgd 			if (def_slcbuf == (unsigned char *)0)
    467      1.1      cgd 				return;  /* too bad */
    468      1.1      cgd 			bcopy(ptr, def_slcbuf, len);
    469      1.1      cgd 		}
    470      1.1      cgd 	}
    471      1.1      cgd 
    472      1.1      cgd }  /* end of do_opt_slc */
    473      1.1      cgd 
    474      1.1      cgd /*
    475      1.1      cgd  * deferslc
    476      1.1      cgd  *
    477      1.1      cgd  * Do slc stuff that was deferred.
    478      1.1      cgd  */
    479      1.1      cgd 	void
    480      1.1      cgd deferslc()
    481      1.1      cgd {
    482      1.1      cgd 	if (def_slcbuf) {
    483      1.1      cgd 		start_slc(1);
    484      1.1      cgd 		do_opt_slc(def_slcbuf, def_slclen);
    485      1.1      cgd 		(void) end_slc(0);
    486      1.1      cgd 		free(def_slcbuf);
    487      1.1      cgd 		def_slcbuf = (unsigned char *)0;
    488      1.1      cgd 		def_slclen = 0;
    489      1.1      cgd 	}
    490      1.1      cgd 
    491      1.1      cgd }  /* end of deferslc */
    492      1.1      cgd 
    493      1.1      cgd #endif	/* LINEMODE */
    494