tc.disc.c revision 100616
1229970Sadrian/* $Header: /src/pub/tcsh/tc.disc.c,v 3.13 2002/07/06 22:28:13 christos Exp $ */ 2229970Sadrian/* 3229970Sadrian * tc.disc.c: Functions to set/clear line disciplines 4229970Sadrian * 5229970Sadrian */ 6229970Sadrian/*- 7229970Sadrian * Copyright (c) 1980, 1991 The Regents of the University of California. 8230273Sadrian * All rights reserved. 9229970Sadrian * 10229970Sadrian * Redistribution and use in source and binary forms, with or without 11229970Sadrian * modification, are permitted provided that the following conditions 12229970Sadrian * are met: 13229970Sadrian * 1. Redistributions of source code must retain the above copyright 14229970Sadrian * notice, this list of conditions and the following disclaimer. 15229970Sadrian * 2. Redistributions in binary form must reproduce the above copyright 16229970Sadrian * notice, this list of conditions and the following disclaimer in the 17229970Sadrian * documentation and/or other materials provided with the distribution. 18229970Sadrian * 3. Neither the name of the University nor the names of its contributors 19229970Sadrian * may be used to endorse or promote products derived from this software 20229970Sadrian * without specific prior written permission. 21229970Sadrian * 22229970Sadrian * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23229970Sadrian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24229970Sadrian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25229970Sadrian * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26229970Sadrian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27229970Sadrian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28229970Sadrian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29229970Sadrian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30229970Sadrian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 */ 34#include "sh.h" 35 36RCSID("$Id: tc.disc.c,v 3.13 2002/07/06 22:28:13 christos Exp $") 37 38#ifdef OREO 39#include <compat.h> 40#endif /* OREO */ 41 42#include "ed.h" 43 44static bool add_discipline = 0; /* Did we add a line discipline */ 45 46#if defined(IRIS4D) || defined(OREO) || defined(sonyrisc) 47# define HAVE_DISC 48# ifndef POSIX 49static struct termio otermiob; 50# else 51static struct termios otermiob; 52# endif /* POSIX */ 53#endif /* IRIS4D || OREO */ 54 55#ifdef _IBMR2 56# define HAVE_DISC 57char strPOSIX[] = "posix"; 58#endif /* _IBMR2 */ 59 60#if !defined(HAVE_DISC) && defined(TIOCGETD) && defined(NTTYDISC) 61static int oldisc; 62#endif /* !HAVE_DISC && TIOCGETD && NTTYDISC */ 63 64int 65/*ARGSUSED*/ 66setdisc(f) 67int f; 68{ 69#ifdef IRIS4D 70# ifndef POSIX 71 struct termio termiob; 72# else 73 struct termios termiob; 74# endif 75 76 if (ioctl(f, TCGETA, (ioctl_t) & termiob) == 0) { 77 otermiob = termiob; 78#if (SYSVREL < 4) || !defined(IRIS4D) 79 if (termiob.c_line != NTTYDISC || termiob.c_cc[VSWTCH] == 0) { /*}*/ 80 termiob.c_line = NTTYDISC; 81#else 82 if (termiob.c_cc[VSWTCH] == 0) { 83#endif 84 termiob.c_cc[VSWTCH] = CSWTCH; 85 if (ioctl(f, TCSETA, (ioctl_t) & termiob) != 0) 86 return (-1); 87 } 88 } 89 else 90 return (-1); 91 add_discipline = 1; 92 return (0); 93#endif /* IRIS4D */ 94 95 96#ifdef OREO 97# ifndef POSIX 98 struct termio termiob; 99# else 100 struct termios termiob; 101# endif 102 103 struct ltchars ltcbuf; 104 105 if (ioctl(f, TCGETA, (ioctl_t) & termiob) == 0) { 106 int comp = getcompat(COMPAT_BSDTTY); 107 otermiob = termiob; 108 if ((comp & COMPAT_BSDTTY) != COMPAT_BSDTTY) { 109 (void) setcompat(comp | COMPAT_BSDTTY); 110 if (ioctl(f, TIOCGLTC, (ioctl_t) & ltcbuf) != 0) 111 xprintf(CGETS(21, 1, "Couldn't get local chars.\n")); 112 else { 113 ltcbuf.t_suspc = CTL_ESC('\032'); /* ^Z */ 114 ltcbuf.t_dsuspc = CTL_ESC('\031'); /* ^Y */ 115 ltcbuf.t_rprntc = CTL_ESC('\022'); /* ^R */ 116 ltcbuf.t_flushc = CTL_ESC('\017'); /* ^O */ 117 ltcbuf.t_werasc = CTL_ESC('\027'); /* ^W */ 118 ltcbuf.t_lnextc = CTL_ESC('\026'); /* ^V */ 119 if (ioctl(f, TIOCSLTC, (ioctl_t) & ltcbuf) != 0) 120 xprintf(CGETS(21, 2, "Couldn't set local chars.\n")); 121 } 122 termiob.c_cc[VSWTCH] = '\0'; 123 if (ioctl(f, TCSETAF, (ioctl_t) & termiob) != 0) 124 return (-1); 125 } 126 } 127 else 128 return (-1); 129 add_discipline = 1; 130 return (0); 131#endif /* OREO */ 132 133 134#ifdef _IBMR2 135 union txname tx; 136 137 tx.tx_which = 0; 138 139 if (ioctl(f, TXGETLD, (ioctl_t) & tx) == 0) { 140 if (strcmp(tx.tx_name, strPOSIX) != 0) 141 if (ioctl(f, TXADDCD, (ioctl_t) strPOSIX) == 0) { 142 add_discipline = 1; 143 return (0); 144 } 145 return (0); 146 } 147 else 148 return (-1); 149#endif /* _IBMR2 */ 150 151#ifndef HAVE_DISC 152# if defined(TIOCGETD) && defined(NTTYDISC) 153 if (ioctl(f, TIOCGETD, (ioctl_t) & oldisc) == 0) { 154 if (oldisc != NTTYDISC) { 155 int ldisc = NTTYDISC; 156 157 if (ioctl(f, TIOCSETD, (ioctl_t) & ldisc) != 0) 158 return (-1); 159 add_discipline = 1; 160 } 161 else 162 oldisc = -1; 163 return (0); 164 } 165 else 166 return (-1); 167# else 168 return (0); 169# endif /* TIOCGETD && NTTYDISC */ 170#endif /* !HAVE_DISC */ 171} /* end setdisc */ 172 173 174int 175/*ARGSUSED*/ 176resetdisc(f) 177int f; 178{ 179 if (add_discipline) { 180 add_discipline = 0; 181#if defined(OREO) || defined(IRIS4D) 182 return (ioctl(f, TCSETAF, (ioctl_t) & otermiob)); 183#endif /* OREO || IRIS4D */ 184 185#ifdef _IBMR2 186 return (ioctl(f, TXDELCD, (ioctl_t) strPOSIX)); 187#endif /* _IBMR2 */ 188 189#ifndef HAVE_DISC 190# if defined(TIOCSETD) && defined(NTTYDISC) 191 return (ioctl(f, TIOCSETD, (ioctl_t) & oldisc)); 192# endif /* TIOCSETD && NTTYDISC */ 193#endif /* !HAVE_DISC */ 194 } 195 return (0); 196} /* end resetdisc */ 197