home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume3 / lib_term / TermSetUp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  1.7 KB  |  94 lines

  1. #include <stdio.h>
  2. #include <sgtty.h>
  3. #include <sys/ioctl.h>
  4.  
  5. char TermSetUp()
  6.  
  7. /*
  8.  ---------------------------------------------------------------------------
  9.  
  10.    Last revision - 
  11.      11 April 1984 - GWS
  12.  
  13.  
  14.    NAME
  15.      TermSetUp - set/clear terminal no echo, raw mode
  16.  
  17.    SYNOPSIS
  18.     char TermSetUp()
  19.  
  20.    DESCRIPTION
  21.     This routine is a toggle function which places the terminal
  22.     into RAW and !ECHO modes on odd calls and back to the original
  23.     state on even-number calls.  The return character is the terminal's
  24.     erase character.
  25.  
  26.    SEE ALSO
  27.  
  28.  
  29.    DIAGNOSTICS
  30.     Will exit(1) on any error. 
  31.  
  32.    BUGS
  33.     none known 
  34.  
  35.    AUTHOR
  36.      George W. Sherouse
  37.      9 April 1984
  38.  
  39.  ---------------------------------------------------------------------------
  40. */
  41.  
  42. {
  43.     struct sgttyb params;
  44.     int ret;
  45.     static int count=0;
  46.     static struct sgttyb old_params;
  47.     int ioctl();
  48.  
  49.     if (!count)
  50.     {
  51.     ret = ioctl(0, TIOCGETP, &old_params);
  52.     if (ret == -1)
  53.     {
  54.         fprintf(stderr, "ioctl fail\n");
  55.         perror("TermSetUp");
  56.         exit(1);
  57.     }
  58.     ret = ioctl(0, TIOCGETP, ¶ms);
  59.     if (ret == -1)
  60.     {
  61.         fprintf(stderr, "ioctl fail\n");
  62.         perror("TermSetUp");
  63.         exit(1);
  64.     }
  65.  
  66.     /* single-character activation, disable all character processing */
  67.     params.sg_flags |= RAW;
  68.     if (params.sg_flags & ECHO)
  69.         params.sg_flags ^= ECHO;
  70.     ret = ioctl(0, TIOCSETP, ¶ms);
  71.     if (ret == -1)
  72.     {
  73.         fprintf(stderr, "ioctl fail\n");
  74.         perror("TermSetUp");
  75.         exit(1);
  76.     }
  77.     count++;
  78.     }
  79.     else
  80.     {
  81. /* put it back the way you found it */
  82.     ret = ioctl(0, TIOCSETP, &old_params);
  83.     if (ret == -1)
  84.     {
  85.         fprintf(stderr, "ioctl fail\n");
  86.         perror("TermSetUp");
  87.         exit(1);
  88.     }
  89.     count = 0;
  90.     }
  91.  
  92.     return(params.sg_erase);
  93. }
  94.