home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3281 / rawmode.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-03  |  1.6 KB  |  58 lines

  1.  
  2. /*
  3.  * Copyright (C) 1991 by Jay Konigsberg. mail: jak@sactoh0
  4.  *
  5.  * Permission to use, copy, modify, and distribute this  software  and  its
  6.  * documentation is hereby  granted,  provided  that  the  above  copyright
  7.  * notice appear in all copies  and that  both  the  copyright  notice  and
  8.  * this permission notice appear in supporting documentation. This software
  9.  * is provided "as is" without express or implied  warranty.  However,  the
  10.  * author retains all Copyright priviliges and rights  to  renumeration  if
  11.  * this software is sold.
  12.  *
  13.  * Also, and very important. This game is for recrecation ONLY and is NOT
  14.  * to be used for gambling in any way. 
  15.  */
  16.  
  17. /*
  18.  * rawmode.c - enter character at a time processing. I ripped this off
  19.  * from one of my other programs because the one in curses didn't work
  20.  * the way _I_ wanted :-)
  21.  */
  22.  
  23. #include    <stdio.h>
  24. #include    <termio.h>
  25. #include    <signal.h>
  26. #include    "vid_extern.h"
  27. #include    "vid_local.h"
  28.  
  29. extern    int    errno;
  30.  
  31. /* Global for interrupt routine: cleanup() */
  32. struct      termio  ttyset;    /* terminal settings */
  33. unsigned  short   c_lflag_hold;    /* hold original values for reset */
  34. unsigned  char    VEOF_hold;    /* hold original value for reset */
  35.  
  36. /*
  37.  *enter raw mode
  38.  */
  39. void    rawmode()
  40. {
  41. if ( ioctl(0, TCGETA, &ttyset) == -1 )
  42.     {
  43.     fprintf(stderr, "ioctl: error=%d\n", errno);
  44.     (void)exit(2);
  45.     }
  46. c_lflag_hold=ttyset.c_lflag;
  47. VEOF_hold = ttyset.c_cc[4];
  48.  
  49. ttyset.c_cc[4] = (unsigned char)1;
  50. ttyset.c_lflag &= ~(ICANON | ECHO);
  51.  
  52. if ( ioctl(0, TCSETAW, &ttyset) == -1 )
  53.     {
  54.     fprintf(stderr, "ioctl: error=%d\n",errno);
  55.     }
  56. signal(SIGINT, cleanup);
  57. }
  58.