home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!math.fu-berlin.de!news.th-darmstadt.de!rbg.informatik.th-darmstadt.de!misar
- From: misar@rbg.informatik.th-darmstadt.de (Walter Misar)
- Subject: Re: How to read without echo.
- Sender: news@news.th-darmstadt.de (The News System)
- Message-ID: <1993Jan5.172545@rbg.informatik.th-darmstadt.de>
- Date: Tue, 5 Jan 1993 16:25:45 GMT
- References: <1i9pi5INN972@taloa.unice.fr> <1993Jan4.182945@rbg.informatik.th-darmstadt.de>
- Nntp-Posting-Host: rbhp87.rbg.informatik.th-darmstadt.de
- Organization: TH Darmstadt
- Lines: 54
-
- In article <1993Jan4.182945@rbg.informatik.th-darmstadt.de>, misar@rbg.informatik.th-darmstadt.de (walter misar) writes:
- > #include <sgtty.h>
- > main()
- > { struct sgttyb *ttyio;
- > ...
- > gtty(0,ttyio);
- > (ttyio->sg_flags)&=(~ECHO); /* echo off */
- > stty(0,ttyio);
- > ... /* read without echo */
- > (ttyio->sg_flags)|=(ECHO); /* echo on */
- > stty(0,ttyio);
- > .....
- > }
-
- Oops, there was an error (the pointer of ttyio never gets initialized).
- Strange enough, it worked for me.
- This could be fixed as follows:
-
- #include <sgtty.h>
- main()
- { struct sgttyb ttyio;
- ...
- gtty(0,&ttyio);
- (ttyio.sg_flags)&=(~ECHO); /* echo off */
- stty(0,&ttyio);
- ... /* read without echo */
- (ttyio.sg_flags)|=(ECHO); /* echo on */
- stty(0,&ttyio);
- .....
- }
-
- However a more portable way would be to use ioctl:
-
- #include <sys/ioctl.h>
- #include <termio.h>
- /* Hm, my manpage says to use termios instead, but that didn't work (HPUX8.0) */
-
- main()
- { struct termio ttyio;
-
- ioctl(0,TCGETA,&ttyio);
- ttyio.c_lflag &= ~ECHO;
- ioctl(0,TCSETA,&ttyio);
- ... /* read without echo */
- ttyio.c_lflag |= ECHO;
- ioctl(0,TCSETA,&ttyio);
- ...
- }
-
- Thanks to the people, who told me about the error.
-
- --
- Walter Misar It is impossible to enjoy idling thoroughly
- misar@rbg.informatik.th-darmstadt.de unless one has plenty of work to do.
-