home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume25 / tcsh-6.01 / part03 / tc.disc.c < prev    next >
C/C++ Source or Header  |  1991-12-19  |  5KB  |  194 lines

  1. /* $Header: /home/hyperion/mu/christos/src/sys/tcsh-6.01/RCS/tc.disc.c,v 3.2 1991/10/12 04:23:51 christos 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.  
  40. RCSID("$Id: tc.disc.c,v 3.2 1991/10/12 04:23:51 christos Exp $")
  41.  
  42. #ifdef OREO
  43. #include <compat.h>
  44. #endif    /* OREO */
  45.  
  46. static bool add_discipline = 0;    /* Did we add a line discipline     */
  47.  
  48. #if defined(IRIS4D) || defined(OREO)
  49. # define HAVE_DISC
  50. # ifndef POSIX
  51. static struct termio otermiob;
  52. # else
  53. static struct termios otermiob;
  54. # endif /* POSIX */
  55. #endif    /* IRIS4D || OREO */
  56.  
  57. #ifdef _IBMR2
  58. # define HAVE_DISC
  59. char    strPOSIX[] = "posix";
  60. #endif    /* _IBMR2 */
  61.  
  62. #if !defined(HAVE_DISC) && defined(TIOCGETD) && defined(NTTYDISC)
  63. static int oldisc;
  64. #endif /* !HAVE_DISC && TIOCGETD && NTTYDISC */
  65.  
  66. int
  67. /*ARGSUSED*/
  68. setdisc(f)
  69. int     f;
  70. {
  71. #ifdef IRIS4D
  72. # ifndef POSIX
  73.     struct termio termiob;
  74. # else
  75.     struct termios termiob;
  76. # endif
  77.  
  78.     if (ioctl(f, TCGETA, (ioctl_t) & termiob) == 0) {
  79.     otermiob = termiob;
  80.     if (termiob.c_line != NTTYDISC || termiob.c_cc[VSWTCH] == 0) {
  81.         termiob.c_line = NTTYDISC;
  82.         termiob.c_cc[VSWTCH] = CSWTCH;
  83.         if (ioctl(f, TCSETA, (ioctl_t) & termiob) != 0)
  84.         return (-1);
  85.     }
  86.     }
  87.     else
  88.     return (-1);
  89.     add_discipline = 1;
  90.     return (0);
  91. #endif                /* IRIS4D */
  92.  
  93.  
  94. #ifdef OREO
  95. # ifndef POSIX
  96.     struct termio termiob;
  97. # else
  98.     struct termios termiob;
  99. # endif
  100.  
  101.     struct ltchars ltcbuf;
  102.  
  103.     if (ioctl(f, TCGETA, (ioctl_t) & termiob) == 0) {
  104.     otermiob = termiob;
  105.     if ((getcompat(COMPAT_BSDTTY) & COMPAT_BSDTTY) != COMPAT_BSDTTY) {
  106.         setcompat(COMPAT_BSDTTY);
  107.         if (ioctl(f, TIOCGLTC, (ioctl_t) & ltcbuf) != 0)
  108.         xprintf("Couldn't get local chars.\n");
  109.         else {
  110.         ltcbuf.t_suspc = '\032';    /* ^Z */
  111.         ltcbuf.t_dsuspc = '\031';    /* ^Y */
  112.         ltcbuf.t_rprntc = '\022';    /* ^R */
  113.         ltcbuf.t_flushc = '\017';    /* ^O */
  114.         ltcbuf.t_werasc = '\027';    /* ^W */
  115.         ltcbuf.t_lnextc = '\026';    /* ^V */
  116.         if (ioctl(f, TIOCSLTC, (ioctl_t) & ltcbuf) != 0)
  117.             xprintf("Couldn't set local chars.\n");
  118.         }
  119.         termiob.c_cc[VSWTCH] = '\0';
  120.         if (ioctl(f, TCSETAF, (ioctl_t) & termiob) != 0)
  121.         return (-1);
  122.     }
  123.     }
  124.     else
  125.     return (-1);
  126.     add_discipline = 1;
  127.     return (0);
  128. #endif                /* OREO */
  129.  
  130.  
  131. #ifdef _IBMR2
  132.     union txname tx;
  133.  
  134.     tx.tx_which = 0;
  135.  
  136.     if (ioctl(f, TXGETLD, (ioctl_t) & tx) == 0) {
  137.     if (strcmp(tx.tx_name, strPOSIX) != 0)
  138.         if (ioctl(f, TXADDCD, (ioctl_t) strPOSIX) == 0) {
  139.         add_discipline = 1;
  140.         return (0);
  141.         }
  142.     return (0);
  143.     }
  144.     else
  145.     return (-1);
  146. #endif    /* _IBMR2 */
  147.  
  148. #ifndef HAVE_DISC
  149. # if defined(TIOCGETD) && defined(NTTYDISC)
  150.     if (ioctl(f, TIOCGETD, (ioctl_t) & oldisc) == 0) {
  151.     if (oldisc != NTTYDISC) {
  152.         int     ldisc = NTTYDISC;
  153.  
  154.         if (ioctl(f, TIOCSETD, (ioctl_t) & ldisc) != 0)
  155.         return (-1);
  156.         add_discipline = 1;
  157.     }
  158.     else
  159.         oldisc = -1;
  160.     return (0);
  161.     }
  162.     else
  163.     return (-1);
  164. # else
  165.     return (0);
  166. # endif    /* TIOCGETD && NTTYDISC */
  167. #endif    /* !HAVE_DISC */
  168. } /* end setdisc */
  169.  
  170.  
  171. int
  172. /*ARGSUSED*/
  173. resetdisc(f)
  174. int f;
  175. {
  176.     if (add_discipline) {
  177.     add_discipline = 0;
  178. #if defined(OREO) || defined(IRIS4D)
  179.     return (ioctl(f, TCSETAF, &otermiob));
  180. #endif /* OREO || IRIS4D */
  181.  
  182. #ifdef _IBMR2
  183.     return (ioctl(f, TXDELCD, (ioctl_t) strPOSIX));
  184. #endif /* _IBMR2 */
  185.  
  186. #ifndef HAVE_DISC
  187. # if defined(TIOCSETD) && defined(NTTYDISC)
  188.     return (ioctl(f, TIOCSETD, (ioctl_t) & oldisc));
  189. # endif /* TIOCSETD && NTTYDISC */
  190. #endif /* !HAVE_DISC */
  191.     }
  192.     return (0);
  193. } /* end resetdisc */
  194.