home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_06_02 / v6n2070a.txt < prev   
Text File  |  1989-09-28  |  1KB  |  34 lines

  1. /* sample unix system 5 set and reset raw mode with zero read delay */
  2.  
  3. #include <termio.h>
  4. #define SGTTY struct termio
  5. #include <term.h>
  6. struct termio ttyold, ttynew;
  7.  
  8. setraw ()
  9. {
  10.     iocttl (0, TCGETA, &ttyold); /* get termio structure for terminal */
  11.     ttynew = ttyold; /* copy termio structure for modification */
  12.     ttynew.c_oflag = ttynew.c_lflag = 0; /* raw mode */
  13.     /* omit "| IXON | IXOFF" on next line for full raw mode */
  14.     ttynew.c_iflag = IGNBRK | IGNPAR | IXON | IXOFF; /* with xon/xoff */
  15.     ttynew.c_cc[VTIME] = 0; /* max time to wait for a char ( in 0.1 sec) */
  16.     ttynew.c_cc[VMIN] = 0; /* number of chaaracters in shortest message */
  17.     ioctl (0, TCSETA, &ttynew); /* set termi structure for terminal */
  18. }
  19.  
  20. resetraw ()
  21. {
  22.     ioctl (0, TCSETA, &ttyold); /* reset termi structure for terminal */
  23. }
  24.  
  25. main()
  26. {
  27.     setraw(); /* set terminal into raw mode, zero read delay */
  28.     /* in a statement of the following form:
  29.     cur_bytes = read (0, buffer, max_bytes);
  30.         cur_bytes will indicate the number of bytes
  31.         (from 0 to max_bytes) transferred to buffer. */
  32.     resetraw(); /* if terminal is not reset, it will remain in raw mode */
  33. }
  34.