home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / nethack-3.1 / sys / unix / ioctl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-06  |  3.5 KB  |  159 lines

  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. #   include <sgtty.h>
  27. #  endif
  28. # endif
  29. struct ltchars ltchars;
  30. struct ltchars ltchars0 = { -1, -1, -1, -1, -1, -1 }; /* turn all off */
  31. #else
  32.  
  33. # ifdef POSIX_TYPES
  34. #include <termios.h>
  35. struct termios termio;
  36. #  ifdef BSD
  37. #include <sys/ioctl.h>
  38. #  endif
  39. # else
  40. #include <termio.h>    /* also includes part of <sgtty.h> */
  41. #  if defined(TCSETS) && !defined(AIX_31)
  42. struct termios termio;
  43. #  else
  44. struct termio termio;
  45. #  endif
  46. # endif
  47. # ifdef AMIX
  48. #include <sys/ioctl.h>
  49. # endif /* AMIX */
  50. #endif
  51.  
  52. #ifdef SUSPEND    /* BSD isn't alone anymore... */
  53. #include    <signal.h>
  54. #endif
  55.  
  56. #if defined(TIOCGWINSZ) && (defined(BSD) || defined(ULTRIX) || defined(AIX_31) || defined(_BULL_SOURCE) || defined(SVR4))
  57. #define USE_WIN_IOCTL
  58. #include "termcap.h"    /* for LI and CO */
  59. #endif
  60.  
  61. #ifdef AUX
  62. void *
  63. catch_stp ( )
  64. {
  65.     signal ( SIGTSTP , SIG_DFL ) ;
  66.     dosuspend ( ) ;
  67. }
  68. #endif /* AUX */
  69.  
  70. #ifdef USE_WIN_IOCTL
  71. void
  72. getwindowsz()
  73. {
  74.     /*
  75.      * ttysize is found on Suns and BSD
  76.      * winsize is found on Suns, BSD, and Ultrix
  77.      */
  78.     struct winsize ttsz;
  79.  
  80.     if (ioctl(fileno(stdin), (int)TIOCGWINSZ, (char *)&ttsz) != -1) {
  81.     /*
  82.      * Use the kernel's values for lines and columns if it has
  83.      * any idea.
  84.      */
  85.     if (ttsz.ws_row)
  86.         LI = ttsz.ws_row;
  87.     if (ttsz.ws_col)
  88.         CO = ttsz.ws_col;
  89.     }
  90. }
  91. #endif
  92.  
  93. void
  94. getioctls()
  95. {
  96. #ifdef BSD_JOB_CONTROL
  97.     (void) ioctl(fileno(stdin), (int) TIOCGLTC, (char *) <chars);
  98.     (void) ioctl(fileno(stdin), (int) TIOCSLTC, (char *) <chars0);
  99. #else
  100. # ifdef POSIX_TYPES
  101.     (void) tcgetattr(fileno(stdin), &termio);
  102. # else
  103. #  if defined(TCSETS) && !defined(AIX_31)
  104.     (void) ioctl(fileno(stdin), (int) TCGETS, &termio);
  105. #  else
  106.     (void) ioctl(fileno(stdin), (int) TCGETA, &termio);
  107. #  endif
  108. # endif
  109. #endif
  110. #ifdef USE_WIN_IOCTL
  111.     getwindowsz();
  112. #endif
  113. #ifdef AUX
  114.     ( void ) signal ( SIGTSTP , catch_stp ) ;
  115. #endif
  116. }
  117.  
  118. void
  119. setioctls()
  120. {
  121. #ifdef BSD_JOB_CONTROL
  122.     (void) ioctl(fileno(stdin), (int) TIOCSLTC, (char *) <chars);
  123. #else
  124. # ifdef POSIX_TYPES
  125.     (void) tcsetattr(fileno(stdin), TCSADRAIN, &termio);
  126. # else
  127. #  if defined(TCSETS) && !defined(AIX_31)
  128.     (void) ioctl(fileno(stdin), (int) TCSETSW, &termio);
  129. #  else
  130.     (void) ioctl(fileno(stdin), (int) TCSETAW, &termio);
  131. #  endif
  132. # endif
  133. #endif
  134. }
  135.  
  136. #ifdef SUSPEND        /* Does not imply BSD */
  137. int
  138. dosuspend()
  139. {
  140. #ifdef SIGTSTP
  141.     if(signal(SIGTSTP, SIG_IGN) == SIG_DFL) {
  142.         suspend_nhwindows(NULL);
  143.         (void) signal(SIGTSTP, SIG_DFL);
  144. #ifdef AUX
  145.         ( void ) kill ( 0 , SIGSTOP ) ;
  146. #else
  147.         (void) kill(0, SIGTSTP);
  148. #endif
  149.         resume_nhwindows();
  150.     } else {
  151.         pline("I don't think your shell has job control.");
  152.     }
  153. #else
  154.     pline("Sorry, it seems we have no SIGTSTP here.  Try ! or S.");
  155. #endif
  156.     return(0);
  157. }
  158. #endif /* SUSPEND */
  159.