tc.disc.c revision 59243
159243Sobrien/* $Header: /src/pub/tcsh/tc.disc.c,v 3.11 1997/10/02 16:36:31 christos Exp $ */ 259243Sobrien/* 359243Sobrien * tc.disc.c: Functions to set/clear line disciplines 459243Sobrien * 559243Sobrien */ 659243Sobrien/*- 759243Sobrien * Copyright (c) 1980, 1991 The Regents of the University of California. 859243Sobrien * All rights reserved. 959243Sobrien * 1059243Sobrien * Redistribution and use in source and binary forms, with or without 1159243Sobrien * modification, are permitted provided that the following conditions 1259243Sobrien * are met: 1359243Sobrien * 1. Redistributions of source code must retain the above copyright 1459243Sobrien * notice, this list of conditions and the following disclaimer. 1559243Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1659243Sobrien * notice, this list of conditions and the following disclaimer in the 1759243Sobrien * documentation and/or other materials provided with the distribution. 1859243Sobrien * 3. All advertising materials mentioning features or use of this software 1959243Sobrien * must display the following acknowledgement: 2059243Sobrien * This product includes software developed by the University of 2159243Sobrien * California, Berkeley and its contributors. 2259243Sobrien * 4. Neither the name of the University nor the names of its contributors 2359243Sobrien * may be used to endorse or promote products derived from this software 2459243Sobrien * without specific prior written permission. 2559243Sobrien * 2659243Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2759243Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2859243Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2959243Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 3059243Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3159243Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3259243Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3359243Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3459243Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3559243Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3659243Sobrien * SUCH DAMAGE. 3759243Sobrien */ 3859243Sobrien#include "sh.h" 3959243Sobrien 4059243SobrienRCSID("$Id: tc.disc.c,v 3.11 1997/10/02 16:36:31 christos Exp $") 4159243Sobrien 4259243Sobrien#ifdef OREO 4359243Sobrien#include <compat.h> 4459243Sobrien#endif /* OREO */ 4559243Sobrien 4659243Sobrien#include "ed.term.h" 4759243Sobrien 4859243Sobrienstatic bool add_discipline = 0; /* Did we add a line discipline */ 4959243Sobrien 5059243Sobrien#if defined(IRIS4D) || defined(OREO) || defined(sonyrisc) 5159243Sobrien# define HAVE_DISC 5259243Sobrien# ifndef POSIX 5359243Sobrienstatic struct termio otermiob; 5459243Sobrien# else 5559243Sobrienstatic struct termios otermiob; 5659243Sobrien# endif /* POSIX */ 5759243Sobrien#endif /* IRIS4D || OREO */ 5859243Sobrien 5959243Sobrien#ifdef _IBMR2 6059243Sobrien# define HAVE_DISC 6159243Sobrienchar strPOSIX[] = "posix"; 6259243Sobrien#endif /* _IBMR2 */ 6359243Sobrien 6459243Sobrien#if !defined(HAVE_DISC) && defined(TIOCGETD) && defined(NTTYDISC) 6559243Sobrienstatic int oldisc; 6659243Sobrien#endif /* !HAVE_DISC && TIOCGETD && NTTYDISC */ 6759243Sobrien 6859243Sobrienint 6959243Sobrien/*ARGSUSED*/ 7059243Sobriensetdisc(f) 7159243Sobrienint f; 7259243Sobrien{ 7359243Sobrien#ifdef IRIS4D 7459243Sobrien# ifndef POSIX 7559243Sobrien struct termio termiob; 7659243Sobrien# else 7759243Sobrien struct termios termiob; 7859243Sobrien# endif 7959243Sobrien 8059243Sobrien if (ioctl(f, TCGETA, (ioctl_t) & termiob) == 0) { 8159243Sobrien otermiob = termiob; 8259243Sobrien#if (SYSVREL < 4) || !defined(IRIS4D) 8359243Sobrien if (termiob.c_line != NTTYDISC || termiob.c_cc[VSWTCH] == 0) { /*}*/ 8459243Sobrien termiob.c_line = NTTYDISC; 8559243Sobrien#else 8659243Sobrien if (termiob.c_cc[VSWTCH] == 0) { 8759243Sobrien#endif 8859243Sobrien termiob.c_cc[VSWTCH] = CSWTCH; 8959243Sobrien if (ioctl(f, TCSETA, (ioctl_t) & termiob) != 0) 9059243Sobrien return (-1); 9159243Sobrien } 9259243Sobrien } 9359243Sobrien else 9459243Sobrien return (-1); 9559243Sobrien add_discipline = 1; 9659243Sobrien return (0); 9759243Sobrien#endif /* IRIS4D */ 9859243Sobrien 9959243Sobrien 10059243Sobrien#ifdef OREO 10159243Sobrien# ifndef POSIX 10259243Sobrien struct termio termiob; 10359243Sobrien# else 10459243Sobrien struct termios termiob; 10559243Sobrien# endif 10659243Sobrien 10759243Sobrien struct ltchars ltcbuf; 10859243Sobrien 10959243Sobrien if (ioctl(f, TCGETA, (ioctl_t) & termiob) == 0) { 11059243Sobrien int comp = getcompat(COMPAT_BSDTTY); 11159243Sobrien otermiob = termiob; 11259243Sobrien if ((comp & COMPAT_BSDTTY) != COMPAT_BSDTTY) { 11359243Sobrien (void) setcompat(comp | COMPAT_BSDTTY); 11459243Sobrien if (ioctl(f, TIOCGLTC, (ioctl_t) & ltcbuf) != 0) 11559243Sobrien xprintf(CGETS(21, 1, "Couldn't get local chars.\n")); 11659243Sobrien else { 11759243Sobrien ltcbuf.t_suspc = CTL_ESC('\032'); /* ^Z */ 11859243Sobrien ltcbuf.t_dsuspc = CTL_ESC('\031'); /* ^Y */ 11959243Sobrien ltcbuf.t_rprntc = CTL_ESC('\022'); /* ^R */ 12059243Sobrien ltcbuf.t_flushc = CTL_ESC('\017'); /* ^O */ 12159243Sobrien ltcbuf.t_werasc = CTL_ESC('\027'); /* ^W */ 12259243Sobrien ltcbuf.t_lnextc = CTL_ESC('\026'); /* ^V */ 12359243Sobrien if (ioctl(f, TIOCSLTC, (ioctl_t) & ltcbuf) != 0) 12459243Sobrien xprintf(CGETS(21, 2, "Couldn't set local chars.\n")); 12559243Sobrien } 12659243Sobrien termiob.c_cc[VSWTCH] = '\0'; 12759243Sobrien if (ioctl(f, TCSETAF, (ioctl_t) & termiob) != 0) 12859243Sobrien return (-1); 12959243Sobrien } 13059243Sobrien } 13159243Sobrien else 13259243Sobrien return (-1); 13359243Sobrien add_discipline = 1; 13459243Sobrien return (0); 13559243Sobrien#endif /* OREO */ 13659243Sobrien 13759243Sobrien 13859243Sobrien#ifdef _IBMR2 13959243Sobrien union txname tx; 14059243Sobrien 14159243Sobrien tx.tx_which = 0; 14259243Sobrien 14359243Sobrien if (ioctl(f, TXGETLD, (ioctl_t) & tx) == 0) { 14459243Sobrien if (strcmp(tx.tx_name, strPOSIX) != 0) 14559243Sobrien if (ioctl(f, TXADDCD, (ioctl_t) strPOSIX) == 0) { 14659243Sobrien add_discipline = 1; 14759243Sobrien return (0); 14859243Sobrien } 14959243Sobrien return (0); 15059243Sobrien } 15159243Sobrien else 15259243Sobrien return (-1); 15359243Sobrien#endif /* _IBMR2 */ 15459243Sobrien 15559243Sobrien#ifndef HAVE_DISC 15659243Sobrien# if defined(TIOCGETD) && defined(NTTYDISC) 15759243Sobrien if (ioctl(f, TIOCGETD, (ioctl_t) & oldisc) == 0) { 15859243Sobrien if (oldisc != NTTYDISC) { 15959243Sobrien int ldisc = NTTYDISC; 16059243Sobrien 16159243Sobrien if (ioctl(f, TIOCSETD, (ioctl_t) & ldisc) != 0) 16259243Sobrien return (-1); 16359243Sobrien add_discipline = 1; 16459243Sobrien } 16559243Sobrien else 16659243Sobrien oldisc = -1; 16759243Sobrien return (0); 16859243Sobrien } 16959243Sobrien else 17059243Sobrien return (-1); 17159243Sobrien# else 17259243Sobrien return (0); 17359243Sobrien# endif /* TIOCGETD && NTTYDISC */ 17459243Sobrien#endif /* !HAVE_DISC */ 17559243Sobrien} /* end setdisc */ 17659243Sobrien 17759243Sobrien 17859243Sobrienint 17959243Sobrien/*ARGSUSED*/ 18059243Sobrienresetdisc(f) 18159243Sobrienint f; 18259243Sobrien{ 18359243Sobrien if (add_discipline) { 18459243Sobrien add_discipline = 0; 18559243Sobrien#if defined(OREO) || defined(IRIS4D) 18659243Sobrien return (ioctl(f, TCSETAF, (ioctl_t) & otermiob)); 18759243Sobrien#endif /* OREO || IRIS4D */ 18859243Sobrien 18959243Sobrien#ifdef _IBMR2 19059243Sobrien return (ioctl(f, TXDELCD, (ioctl_t) strPOSIX)); 19159243Sobrien#endif /* _IBMR2 */ 19259243Sobrien 19359243Sobrien#ifndef HAVE_DISC 19459243Sobrien# if defined(TIOCSETD) && defined(NTTYDISC) 19559243Sobrien return (ioctl(f, TIOCSETD, (ioctl_t) & oldisc)); 19659243Sobrien# endif /* TIOCSETD && NTTYDISC */ 19759243Sobrien#endif /* !HAVE_DISC */ 19859243Sobrien } 19959243Sobrien return (0); 20059243Sobrien} /* end resetdisc */ 201