/user/tcsh/tc.disc.c

https://github.com/rhuitl/uClinux · C · 200 lines · 138 code · 23 blank · 39 comment · 44 complexity · 4de46e97eef445845cbf0b2265b35656 MD5 · raw file

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