home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / shells / tcshsrc.zoo / tcsh / tc.disc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-25  |  5.2 KB  |  195 lines

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