home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / NetHack 3.1.3 / source / sys / unix / ioctl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-01  |  3.7 KB  |  174 lines  |  [TEXT/R*ch]

  1. /*    SCCS Id: @(#)ioctl.c    3.1    90/22/02
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. /* This cannot be part of hack.tty.c (as it was earlier) since on some
  6.    systems (e.g. MUNIX) the include files <termio.h> and <sgtty.h>
  7.    define the same constants, and the C preprocessor complains. */
  8.  
  9. #include "hack.h"
  10.  
  11. #if defined(BSD_JOB_CONTROL) || defined(_BULL_SOURCE)
  12. # ifdef HPUX
  13. #include <bsdtty.h>
  14. # else
  15. #  if defined(AIX_31) && !defined(_ALL_SOURCE)
  16. #   define _ALL_SOURCE    /* causes struct winsize to be present */
  17. #  endif
  18. #  if defined(_BULL_SOURCE)
  19. #   include <termios.h>
  20. struct termios termio;
  21. #   undef TIMEOUT        /* defined in you.h and sys/tty.h */
  22. #   include <sys/tty.h>        /* define winsize */
  23. #   include <sys/ttold.h>    /* define struct ltchars */
  24. #   include <sys/bsdioctl.h>    /* define TIOGWINSZ */
  25. #  else
  26. #   ifdef LINUX
  27. #    include <bsd/sgtty.h>
  28. #   else
  29. #    include <sgtty.h>
  30. #   endif
  31. #  endif
  32. # endif
  33. struct ltchars ltchars;
  34. struct ltchars ltchars0 = { -1, -1, -1, -1, -1, -1 }; /* turn all off */
  35. #else
  36.  
  37. # ifdef POSIX_TYPES
  38. #include <termios.h>
  39. struct termios termio;
  40. #  ifdef BSD
  41. #include <sys/ioctl.h>
  42. #  endif
  43. # else
  44. #include <termio.h>    /* also includes part of <sgtty.h> */
  45. #  if defined(TCSETS) && !defined(AIX_31)
  46. struct termios termio;
  47. #  else
  48. struct termio termio;
  49. #  endif
  50. # endif
  51. # ifdef AMIX
  52. #include <sys/ioctl.h>
  53. # endif /* AMIX */
  54. #endif
  55.  
  56. #ifdef SUSPEND    /* BSD isn't alone anymore... */
  57. #include    <signal.h>
  58. #endif
  59.  
  60. #if defined(TIOCGWINSZ) && (defined(BSD) || defined(ULTRIX) || defined(AIX_31) || defined(_BULL_SOURCE) || defined(SVR4))
  61. #define USE_WIN_IOCTL
  62. #include "termcap.h"    /* for LI and CO */
  63. #endif
  64.  
  65. #ifdef _M_UNIX
  66. extern void NDECL(sco_mapon);
  67. extern void NDECL(sco_mapoff);
  68. #endif
  69.  
  70. #ifdef AUX
  71. void *
  72. catch_stp ( )
  73. {
  74.     signal ( SIGTSTP , SIG_DFL ) ;
  75.     dosuspend ( ) ;
  76. }
  77. #endif /* AUX */
  78.  
  79. #ifdef USE_WIN_IOCTL
  80. void
  81. getwindowsz()
  82. {
  83.     /*
  84.      * ttysize is found on Suns and BSD
  85.      * winsize is found on Suns, BSD, and Ultrix
  86.      */
  87.     struct winsize ttsz;
  88.  
  89.     if (ioctl(fileno(stdin), (int)TIOCGWINSZ, (char *)&ttsz) != -1) {
  90.     /*
  91.      * Use the kernel's values for lines and columns if it has
  92.      * any idea.
  93.      */
  94.     if (ttsz.ws_row)
  95.         LI = ttsz.ws_row;
  96.     if (ttsz.ws_col)
  97.         CO = ttsz.ws_col;
  98.     }
  99. }
  100. #endif
  101.  
  102. void
  103. getioctls()
  104. {
  105. #ifdef BSD_JOB_CONTROL
  106.     (void) ioctl(fileno(stdin), (int) TIOCGLTC, (char *) <chars);
  107.     (void) ioctl(fileno(stdin), (int) TIOCSLTC, (char *) <chars0);
  108. #else
  109. # ifdef POSIX_TYPES
  110.     (void) tcgetattr(fileno(stdin), &termio);
  111. # else
  112. #  if defined(TCSETS) && !defined(AIX_31)
  113.     (void) ioctl(fileno(stdin), (int) TCGETS, &termio);
  114. #  else
  115.     (void) ioctl(fileno(stdin), (int) TCGETA, &termio);
  116. #  endif
  117. # endif
  118. #endif
  119. #ifdef USE_WIN_IOCTL
  120.     getwindowsz();
  121. #endif
  122. #ifdef AUX
  123.     ( void ) signal ( SIGTSTP , catch_stp ) ;
  124. #endif
  125. }
  126.  
  127. void
  128. setioctls()
  129. {
  130. #ifdef BSD_JOB_CONTROL
  131.     (void) ioctl(fileno(stdin), (int) TIOCSLTC, (char *) <chars);
  132. #else
  133. # ifdef POSIX_TYPES
  134.     (void) tcsetattr(fileno(stdin), TCSADRAIN, &termio);
  135. # else
  136. #  if defined(TCSETS) && !defined(AIX_31)
  137.     (void) ioctl(fileno(stdin), (int) TCSETSW, &termio);
  138. #  else
  139.     (void) ioctl(fileno(stdin), (int) TCSETAW, &termio);
  140. #  endif
  141. # endif
  142. #endif
  143. }
  144.  
  145. #ifdef SUSPEND        /* No longer implies BSD */
  146. int
  147. dosuspend()
  148. {
  149. # ifdef SIGTSTP
  150.     if(signal(SIGTSTP, SIG_IGN) == SIG_DFL) {
  151.         suspend_nhwindows(NULL);
  152. #  ifdef _M_UNIX
  153.         sco_mapon();
  154. #  endif
  155.         (void) signal(SIGTSTP, SIG_DFL);
  156. #  ifdef AUX
  157.         ( void ) kill ( 0 , SIGSTOP ) ;
  158. #  else
  159.         (void) kill(0, SIGTSTP);
  160. #  endif
  161. #  ifdef _M_UNIX
  162.         sco_mapoff();
  163. #  endif
  164.         resume_nhwindows();
  165.     } else {
  166.         pline("I don't think your shell has job control.");
  167.     }
  168. # else
  169.     pline("Sorry, it seems we have no SIGTSTP here.  Try ! or S.");
  170. # endif
  171.     return(0);
  172. }
  173. #endif /* SUSPEND */
  174.