tc.disc.c revision 100616
1100616Smp/* $Header: /src/pub/tcsh/tc.disc.c,v 3.13 2002/07/06 22:28:13 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. 18100616Smp * 3. Neither the name of the University nor the names of its contributors 1959243Sobrien * may be used to endorse or promote products derived from this software 2059243Sobrien * without specific prior written permission. 2159243Sobrien * 2259243Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2359243Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2459243Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2559243Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2659243Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2759243Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2859243Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2959243Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3059243Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3159243Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3259243Sobrien * SUCH DAMAGE. 3359243Sobrien */ 3459243Sobrien#include "sh.h" 3559243Sobrien 36100616SmpRCSID("$Id: tc.disc.c,v 3.13 2002/07/06 22:28:13 christos Exp $") 3759243Sobrien 3859243Sobrien#ifdef OREO 3959243Sobrien#include <compat.h> 4059243Sobrien#endif /* OREO */ 4159243Sobrien 42100616Smp#include "ed.h" 4359243Sobrien 4459243Sobrienstatic bool add_discipline = 0; /* Did we add a line discipline */ 4559243Sobrien 4659243Sobrien#if defined(IRIS4D) || defined(OREO) || defined(sonyrisc) 4759243Sobrien# define HAVE_DISC 4859243Sobrien# ifndef POSIX 4959243Sobrienstatic struct termio otermiob; 5059243Sobrien# else 5159243Sobrienstatic struct termios otermiob; 5259243Sobrien# endif /* POSIX */ 5359243Sobrien#endif /* IRIS4D || OREO */ 5459243Sobrien 5559243Sobrien#ifdef _IBMR2 5659243Sobrien# define HAVE_DISC 5759243Sobrienchar strPOSIX[] = "posix"; 5859243Sobrien#endif /* _IBMR2 */ 5959243Sobrien 6059243Sobrien#if !defined(HAVE_DISC) && defined(TIOCGETD) && defined(NTTYDISC) 6159243Sobrienstatic int oldisc; 6259243Sobrien#endif /* !HAVE_DISC && TIOCGETD && NTTYDISC */ 6359243Sobrien 6459243Sobrienint 6559243Sobrien/*ARGSUSED*/ 6659243Sobriensetdisc(f) 6759243Sobrienint f; 6859243Sobrien{ 6959243Sobrien#ifdef IRIS4D 7059243Sobrien# ifndef POSIX 7159243Sobrien struct termio termiob; 7259243Sobrien# else 7359243Sobrien struct termios termiob; 7459243Sobrien# endif 7559243Sobrien 7659243Sobrien if (ioctl(f, TCGETA, (ioctl_t) & termiob) == 0) { 7759243Sobrien otermiob = termiob; 7859243Sobrien#if (SYSVREL < 4) || !defined(IRIS4D) 7959243Sobrien if (termiob.c_line != NTTYDISC || termiob.c_cc[VSWTCH] == 0) { /*}*/ 8059243Sobrien termiob.c_line = NTTYDISC; 8159243Sobrien#else 8259243Sobrien if (termiob.c_cc[VSWTCH] == 0) { 8359243Sobrien#endif 8459243Sobrien termiob.c_cc[VSWTCH] = CSWTCH; 8559243Sobrien if (ioctl(f, TCSETA, (ioctl_t) & termiob) != 0) 8659243Sobrien return (-1); 8759243Sobrien } 8859243Sobrien } 8959243Sobrien else 9059243Sobrien return (-1); 9159243Sobrien add_discipline = 1; 9259243Sobrien return (0); 9359243Sobrien#endif /* IRIS4D */ 9459243Sobrien 9559243Sobrien 9659243Sobrien#ifdef OREO 9759243Sobrien# ifndef POSIX 9859243Sobrien struct termio termiob; 9959243Sobrien# else 10059243Sobrien struct termios termiob; 10159243Sobrien# endif 10259243Sobrien 10359243Sobrien struct ltchars ltcbuf; 10459243Sobrien 10559243Sobrien if (ioctl(f, TCGETA, (ioctl_t) & termiob) == 0) { 10659243Sobrien int comp = getcompat(COMPAT_BSDTTY); 10759243Sobrien otermiob = termiob; 10859243Sobrien if ((comp & COMPAT_BSDTTY) != COMPAT_BSDTTY) { 10959243Sobrien (void) setcompat(comp | COMPAT_BSDTTY); 11059243Sobrien if (ioctl(f, TIOCGLTC, (ioctl_t) & ltcbuf) != 0) 11159243Sobrien xprintf(CGETS(21, 1, "Couldn't get local chars.\n")); 11259243Sobrien else { 11359243Sobrien ltcbuf.t_suspc = CTL_ESC('\032'); /* ^Z */ 11459243Sobrien ltcbuf.t_dsuspc = CTL_ESC('\031'); /* ^Y */ 11559243Sobrien ltcbuf.t_rprntc = CTL_ESC('\022'); /* ^R */ 11659243Sobrien ltcbuf.t_flushc = CTL_ESC('\017'); /* ^O */ 11759243Sobrien ltcbuf.t_werasc = CTL_ESC('\027'); /* ^W */ 11859243Sobrien ltcbuf.t_lnextc = CTL_ESC('\026'); /* ^V */ 11959243Sobrien if (ioctl(f, TIOCSLTC, (ioctl_t) & ltcbuf) != 0) 12059243Sobrien xprintf(CGETS(21, 2, "Couldn't set local chars.\n")); 12159243Sobrien } 12259243Sobrien termiob.c_cc[VSWTCH] = '\0'; 12359243Sobrien if (ioctl(f, TCSETAF, (ioctl_t) & termiob) != 0) 12459243Sobrien return (-1); 12559243Sobrien } 12659243Sobrien } 12759243Sobrien else 12859243Sobrien return (-1); 12959243Sobrien add_discipline = 1; 13059243Sobrien return (0); 13159243Sobrien#endif /* OREO */ 13259243Sobrien 13359243Sobrien 13459243Sobrien#ifdef _IBMR2 13559243Sobrien union txname tx; 13659243Sobrien 13759243Sobrien tx.tx_which = 0; 13859243Sobrien 13959243Sobrien if (ioctl(f, TXGETLD, (ioctl_t) & tx) == 0) { 14059243Sobrien if (strcmp(tx.tx_name, strPOSIX) != 0) 14159243Sobrien if (ioctl(f, TXADDCD, (ioctl_t) strPOSIX) == 0) { 14259243Sobrien add_discipline = 1; 14359243Sobrien return (0); 14459243Sobrien } 14559243Sobrien return (0); 14659243Sobrien } 14759243Sobrien else 14859243Sobrien return (-1); 14959243Sobrien#endif /* _IBMR2 */ 15059243Sobrien 15159243Sobrien#ifndef HAVE_DISC 15259243Sobrien# if defined(TIOCGETD) && defined(NTTYDISC) 15359243Sobrien if (ioctl(f, TIOCGETD, (ioctl_t) & oldisc) == 0) { 15459243Sobrien if (oldisc != NTTYDISC) { 15559243Sobrien int ldisc = NTTYDISC; 15659243Sobrien 15759243Sobrien if (ioctl(f, TIOCSETD, (ioctl_t) & ldisc) != 0) 15859243Sobrien return (-1); 15959243Sobrien add_discipline = 1; 16059243Sobrien } 16159243Sobrien else 16259243Sobrien oldisc = -1; 16359243Sobrien return (0); 16459243Sobrien } 16559243Sobrien else 16659243Sobrien return (-1); 16759243Sobrien# else 16859243Sobrien return (0); 16959243Sobrien# endif /* TIOCGETD && NTTYDISC */ 17059243Sobrien#endif /* !HAVE_DISC */ 17159243Sobrien} /* end setdisc */ 17259243Sobrien 17359243Sobrien 17459243Sobrienint 17559243Sobrien/*ARGSUSED*/ 17659243Sobrienresetdisc(f) 17759243Sobrienint f; 17859243Sobrien{ 17959243Sobrien if (add_discipline) { 18059243Sobrien add_discipline = 0; 18159243Sobrien#if defined(OREO) || defined(IRIS4D) 18259243Sobrien return (ioctl(f, TCSETAF, (ioctl_t) & otermiob)); 18359243Sobrien#endif /* OREO || IRIS4D */ 18459243Sobrien 18559243Sobrien#ifdef _IBMR2 18659243Sobrien return (ioctl(f, TXDELCD, (ioctl_t) strPOSIX)); 18759243Sobrien#endif /* _IBMR2 */ 18859243Sobrien 18959243Sobrien#ifndef HAVE_DISC 19059243Sobrien# if defined(TIOCSETD) && defined(NTTYDISC) 19159243Sobrien return (ioctl(f, TIOCSETD, (ioctl_t) & oldisc)); 19259243Sobrien# endif /* TIOCSETD && NTTYDISC */ 19359243Sobrien#endif /* !HAVE_DISC */ 19459243Sobrien } 19559243Sobrien return (0); 19659243Sobrien} /* end resetdisc */ 197