Getchar w/wout echo

Karl Heuer karl at haddock.ima.isc.com
Sat Aug 27 01:36:03 AEST 1988


In article <3761 at bsu-cs.UUCP> dhesi at bsu-cs.UUCP (Rahul Dhesi) writes:
>In article <6589 at haddock.ima.isc.com> karl at haddock (Karl Heuer) writes:
>>The system is always in one of two states, cooked or raw
>
>It would be nice if we applied the concept of raw-versus-cooked to the
>current input request rather than to the terminal.  This way there is
>no danger of programming carelessness (or having to kill a runaway
>process) leaving the terminal in a funny state.  This happens more
>often than I like on UNIX systems.

While this behavior may be more desirable for some applications, insisting on
it would require too much overhead on UNIX.  My proposal was designed so that
	rawenable();
	while ((c = getrawchar()) != QUIT_CMD) do_command(c);
	rawdisable();
could be implemented with just one system call (instead of three) for each
iteration of the loop.

To defend against the "funny state" problem, you can set up traps:
	signal(SIGINT, rawdisable);
	atexit(rawdisable);
(My "tio" package has an option to automatically do this when you call the
equivalent of rawenable().)

Alternately, you could get the exact behavior you described by wrapping
another layer around the primitives:
	int getch(void) {
		int c;
		rawenable(); c = getrawchar(); rawdisable();
		return c;
	}

If what you're really saying is that UNIX should be changed, then I agree (a
"/dev/rtty" would be within the Spirit).  But that's not a C issue.

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list