home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!hal.com!darkstar.UCSC.EDU!cats.ucsc.edu!mmcohen
- From: mmcohen@cats.ucsc.edu (Michael M Cohen)
- Newsgroups: comp.sys.sgi
- Subject: Re: tty query
- Message-ID: <1eiok9INN9l6@darkstar.UCSC.EDU>
- Date: 20 Nov 92 13:19:05 GMT
- References: <1ei0hrINN3om@darkstar.UCSC.EDU>
- Organization: University of California; Santa Cruz
- Lines: 48
- NNTP-Posting-Host: si.ucsc.edu
-
-
- In article <1ei0hrINN3om@darkstar.UCSC.EDU> mmcohen@cats.ucsc.edu (Michael M Cohen) writes:
- >
- >Within a C or f77 program, wondering how to temporarily switch
- >whatever tty i'm on to mode which will cause getc to return immediately
- >if nothing has been entered. I want to do some activity
- >until a key press, then go back to usual tty mode.
- >Code fragments or pointers appreciated...
- >
-
- Well, since no one responded in the last hour or so I had to
- hack up some code to get it done. But there is a small
- mystery I can't figure out. After the code is executed
- ^C does not act to interrupt program unless one includes
- final "stty" line. Question is why?
- ---------------------------------------
-
- struct termio sert;
- tcflag_t slf;
-
- ....
- ioctl(0, TCGETA, &sert);
- slf = sert.c_lflag;
- sert.c_lflag &= ~(ICANON|ISIG|ECHO);
- sert.c_cc[VMIN] = 0;
- sert.c_cc[VTIME] = 0;
- ioctl(0, TCSETA, &sert);
- while(getchar() != 'd'){
-
- ... PLAY SOME SOUNDS...
-
- }
-
- sert.c_lflag = slf;
- sert.c_cc[VMIN] = 1;
- sert.c_cc[VTIME] = 1;
- ioctl(0, TCSETA, &sert);
- system("stty intr '\03'"); /* WHY IS THIS NEEDED ??? */
- ...
- --
-
- ======================================================================
- = Dr. Michael M. Cohen mmcohen@dewi.ucsc.edu =
- = Program in Experimental Psychology mmcohen@fuzzy.ucsc.edu =
- = 433 Clark Kerr Hall 408-459-2655 LAB =
- = University of California - Santa Cruz 408-459-2700 MSGS =
- = Santa Cruz, CA 95064 408-459-3519 FAX =
- ======================================================================
-