source: trunk/third/tcsh/tc.disc.c @ 12039

Revision 12039, 5.5 KB checked in by danw, 26 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r12038, which included commits to RCS files with non-trunk default branches.
Line 
1/* $Header: /afs/dev.mit.edu/source/repository/third/tcsh/tc.disc.c,v 1.1.1.2 1998-10-03 21:10:11 danw Exp $ */
2/*
3 * tc.disc.c: Functions to set/clear line disciplines
4 *
5 */
6/*-
7 * Copyright (c) 1980, 1991 The Regents of the University of California.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 *    must display the following acknowledgement:
20 *      This product includes software developed by the University of
21 *      California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 *    may be used to endorse or promote products derived from this software
24 *    without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 */
38#include "sh.h"
39
40RCSID("$Id: tc.disc.c,v 1.1.1.2 1998-10-03 21:10:11 danw Exp $")
41
42#ifdef OREO
43#include <compat.h>
44#endif  /* OREO */
45
46#include "ed.term.h"
47
48static bool add_discipline = 0; /* Did we add a line discipline  */
49
50#if defined(IRIS4D) || defined(OREO) || defined(sonyrisc)
51# define HAVE_DISC
52# ifndef POSIX
53static struct termio otermiob;
54# else
55static struct termios otermiob;
56# endif /* POSIX */
57#endif  /* IRIS4D || OREO */
58
59#ifdef _IBMR2
60# define HAVE_DISC
61char    strPOSIX[] = "posix";
62#endif  /* _IBMR2 */
63
64#if !defined(HAVE_DISC) && defined(TIOCGETD) && defined(NTTYDISC)
65static int oldisc;
66#endif /* !HAVE_DISC && TIOCGETD && NTTYDISC */
67
68int
69/*ARGSUSED*/
70setdisc(f)
71int     f;
72{
73#ifdef IRIS4D
74# ifndef POSIX
75    struct termio termiob;
76# else
77    struct termios termiob;
78# endif
79
80    if (ioctl(f, TCGETA, (ioctl_t) & termiob) == 0) {
81        otermiob = termiob;
82#if (SYSVREL < 4) || !defined(IRIS4D)
83        if (termiob.c_line != NTTYDISC || termiob.c_cc[VSWTCH] == 0) { /*}*/
84            termiob.c_line = NTTYDISC;
85#else
86        if (termiob.c_cc[VSWTCH] == 0) {
87#endif
88            termiob.c_cc[VSWTCH] = CSWTCH;
89            if (ioctl(f, TCSETA, (ioctl_t) & termiob) != 0)
90                return (-1);
91        }
92    }
93    else
94        return (-1);
95    add_discipline = 1;
96    return (0);
97#endif /* IRIS4D */
98
99
100#ifdef OREO
101# ifndef POSIX
102    struct termio termiob;
103# else
104    struct termios termiob;
105# endif
106
107    struct ltchars ltcbuf;
108
109    if (ioctl(f, TCGETA, (ioctl_t) & termiob) == 0) {
110        int comp = getcompat(COMPAT_BSDTTY);
111        otermiob = termiob;
112        if ((comp & COMPAT_BSDTTY) != COMPAT_BSDTTY) {
113            (void) setcompat(comp | COMPAT_BSDTTY);
114            if (ioctl(f, TIOCGLTC, (ioctl_t) & ltcbuf) != 0)
115                xprintf(CGETS(21, 1, "Couldn't get local chars.\n"));
116            else {
117                ltcbuf.t_suspc = CTL_ESC('\032');        /* ^Z */
118                ltcbuf.t_dsuspc = CTL_ESC('\031');       /* ^Y */
119                ltcbuf.t_rprntc = CTL_ESC('\022');       /* ^R */
120                ltcbuf.t_flushc = CTL_ESC('\017');       /* ^O */
121                ltcbuf.t_werasc = CTL_ESC('\027');       /* ^W */
122                ltcbuf.t_lnextc = CTL_ESC('\026');       /* ^V */
123                if (ioctl(f, TIOCSLTC, (ioctl_t) & ltcbuf) != 0)
124                    xprintf(CGETS(21, 2, "Couldn't set local chars.\n"));
125            }
126            termiob.c_cc[VSWTCH] = '\0';
127            if (ioctl(f, TCSETAF, (ioctl_t) & termiob) != 0)
128                return (-1);
129        }
130    }
131    else
132        return (-1);
133    add_discipline = 1;
134    return (0);
135#endif                          /* OREO */
136
137
138#ifdef _IBMR2
139    union txname tx;
140
141    tx.tx_which = 0;
142
143    if (ioctl(f, TXGETLD, (ioctl_t) & tx) == 0) {
144        if (strcmp(tx.tx_name, strPOSIX) != 0)
145            if (ioctl(f, TXADDCD, (ioctl_t) strPOSIX) == 0) {
146                add_discipline = 1;
147                return (0);
148            }
149        return (0);
150    }
151    else
152        return (-1);
153#endif  /* _IBMR2 */
154
155#ifndef HAVE_DISC
156# if defined(TIOCGETD) && defined(NTTYDISC)
157    if (ioctl(f, TIOCGETD, (ioctl_t) & oldisc) == 0) {
158        if (oldisc != NTTYDISC) {
159            int     ldisc = NTTYDISC;
160
161            if (ioctl(f, TIOCSETD, (ioctl_t) & ldisc) != 0)
162                return (-1);
163            add_discipline = 1;
164        }
165        else
166            oldisc = -1;
167        return (0);
168    }
169    else
170        return (-1);
171# else
172    return (0);
173# endif /* TIOCGETD && NTTYDISC */
174#endif  /* !HAVE_DISC */
175} /* end setdisc */
176
177
178int
179/*ARGSUSED*/
180resetdisc(f)
181int f;
182{
183    if (add_discipline) {
184        add_discipline = 0;
185#if defined(OREO) || defined(IRIS4D)
186        return (ioctl(f, TCSETAF, (ioctl_t) & otermiob));
187#endif /* OREO || IRIS4D */
188
189#ifdef _IBMR2
190        return (ioctl(f, TXDELCD, (ioctl_t) strPOSIX));
191#endif /* _IBMR2 */
192
193#ifndef HAVE_DISC
194# if defined(TIOCSETD) && defined(NTTYDISC)
195        return (ioctl(f, TIOCSETD, (ioctl_t) & oldisc));
196# endif /* TIOCSETD && NTTYDISC */
197#endif /* !HAVE_DISC */
198    }
199    return (0);
200} /* end resetdisc */
Note: See TracBrowser for help on using the repository browser.