Mail Archives: djgpp/2000/08/08/03:37:39
On Mon, 7 Aug 2000, David Witbrodt wrote:
> From reading some of the info docs, it seems like those termios
> functions only affect iostreams behavior because of the way DJGPP
> iostreams are implemented using stdio streams.
Close, but not accurate enough. The DJGPP termios emulation affects
any function that uses DOS I/O to/from the console device. In
particular, this means that not only buffered stdio functions, but
also `read', `write', `_read', `_write', and anything that uses those,
is affected.
This is the same as on Unix, except that Unix termios can be used with
non-terminal devices as well.
> Will modifying termios settings really cause the same effect on cin
> on, say, a GNU/Linux system?
It should have the same effect; if you find otherwise, please report
that here as a possible bug.
> Are the iostreams libraries implemented the same way in UNIX?
Of course, not! The implementation of termios on Unix cannot possibly
be close to the DJGPP implementation, because the Unix terminal device
driver provides all the termios functionality directly. So on Unix,
termios functions are just wrappers around the appropriate ioctl
system calls. In contrast, the DJGPP emulation of termios needs to
provide all the functionality by itself, since the DOS console device
driver is much more limited.
For more details, download the DJGPP library sources (v2/djlsr203.zip)
and study the file src/libc/posix/termios/tminit.c.
The significant differences in implementation notwithstanding, the
effect of using termios in DJGPP and on Unix should be the same (give
or take some limitations of the current DJGPP implementation which are
documented in the library reference).
> After looking at the docs you suggested, I think I understand what
> to try. Did you have something like this in mind?:
>
> // fragment: trying to keep cin from echoing to the screen
>
> struct termios oldsettings, newsettings;
>
> tcgetattr (fileno(stdin), &oldsettings); // save old termios settings
>
> newsettings = oldsettings; // copy current termios config
> newsettings.c_lflag = (ISIG | ICANON | IEXTEN); // no ECHO* flags set
>
> tcsetattr (fileno(stdin), TCSADRAIN, &newsettings); // load new
> // settings
>
> /* ... [program code here] ... */
>
> tcsetattr (fileno(stdin), TCSANOW, &oldsettings);
Yes, that's what I had in mind, except that IEXTEN might not be
required for what you want (in the DJGPP implementation, it is
currently ignored). You will find that any Unix-born interactive
program which supports arbitrary key sequences does something similar
in its initialization code.
- Raw text -