Behaviour of setjmp/longjmp and registers

Michael Meissner meissner at tiktok.dg.com
Tue Jan 31 04:29:22 AEST 1989


In article <470 at maxim.ERBE.SE> prc at maxim.ERBE.SE (Robert Claeson) writes:
| Okay, all you portable code types, maybe you can help me with making
| this more portable (ie, to not use setjmp/longjmp).
| 
| In a single-key (not character) keyboard read routine I've written,
| I recognizes function keys and returns a single, generic value for them
| instead of the usual character. I do this by setting an alarm(1) and
| reading character by character until I've got a non-redundant string, which
| in the case of a printable character (an 'a' for example) is that single
| character.

Both of the modern UNIX varients have methods to do timed reads
from a character device without resorting to alarm.

In Berkeley-based UNIXes (UNICI?), you do a select on the file
descriptor(s) with the given timeout specified in the struct timeval
structure.  This will also work on pipes.  Note there are some
additional macros to use in setting up the bit array of file
descriptors for 4.3 based systems that were not available in 4.2, but
they are easy enough to provide.

In System V based UNIXes, you do an ioctl to set MIN/TIME to be the
minimum number of characters to read and the timeout in tenths of a
second.  This only works on terminals (and pty's if provided).

Some version of System V.3 (V.3.1?) is susposed to have rewritten the
terminal subsystem into streams (and pipes?).  If so, you can then use
poll, which provides the same basic functionality as select, except
that it is limited to streams devices.

Given that you set an appropriate timeout, non of the above solutions
are CPU intensive, and they don't have the gapping holes of
interrupting the main task at possibly the wrong time that alarm, and
signal open up.

| I could  probably read the clock, do a tight  loop  that reads the
| keyboard non-blocking and check the clock on each iteration, but  that
| would probably take too much CPU, so I don't want to do that.
| 
| Now, make this portable and non  CPU-intensive. If you think the
| algorithm needs to be changed, just tell me.

As an aside, I've used systems at times, where the latency between
characters could be really high, and such simple minded function key
mappings would break occansionally.  For example, when I was in our
Mass. plant, I would find times when the main network down to our
North Carolina plant would be out.  I eventually resorted to calling a
California site, and from there calling North Carolina.  I think I
went through about 5-10 hosts, with each host sometimes buffering the
I/O...
--
Michael Meissner, Data General.
Uucp:	...!mcnc!rti!xyzzy!meissner
Arpa:	meissner at dg-rtp.DG.COM   (or) meissner%dg-rtp.DG.COM at relay.cs.net



More information about the Comp.lang.c mailing list