[fa.info-vax] Single character input to a C program

info-vax@ucbvax.ARPA (06/23/85)

From: John M Sellens <jmsellens%waterloo.csnet@csnet-relay.ARPA>

Under VMS 4.1, I want to write a C program that can obtain single character
input from the keyboard, without any editing, and without waiting for the
user to press return.  The character should not be echoed on the screen,
my program will do all the necessary echoing.

I am using the SMG$ routines for screen output.  I tried using
SMG$ENABLE_UNSOLICITED_INPUT to enable a routine that will be activated
each time a key is pressed.  I tried to make it reasonably intelligent,
but I seemed to have very little luck.  One problem that I ran into was
that I couldn't convince it to accept an escape character without a
following escape sequence (our program uses escape to indicate "undo"
or "stop what I'm doing").

I would also like to be able to inquire whather or not a character or
characters is waiting (or alternatively, do something like a non-blocking
getchar()).

There is only a small amount of VMS expertise here a Waterloo, so asking
around hasn't been too successful.  I will greatly appreciate any help
that you can offer me.

Thanks!

John

UUCP:  {decvax|utzoo|ihnp4|allegra|clyde}!watmath!jmsellens
CSNET: jmsellens%watmath@waterloo.csnet
ARPA:  jmsellens%watmath%waterloo.csnet@csnet-relay.arpa

info-vax@ucbvax.ARPA (06/24/85)

From: stew%lhasa@harvard.ARPA

I have long wished that dec would make crmode() and nocrmode() work
by setting a flag in the C runtimes which would make them do single
character qio's.  Is this not easy?  Would this not work?

To get escapes through, you have to turn off the TT$M_ESCAPE bit in
your terminal's basic characteristics word, typically with the
IO$_SENSEMODE and IO$_SETMODE functions of SYS$QIO.  A good example
of this can be found in the support for vms that I wrote for the
new version of C-KERMIT, which is available by anonymous ftp from
CU20A.  This implements, entirely in C, the necessary calls to
system services to do single character IO and other useful things
like typeahead sensing.  It is in KER:CKVTIO.C.  You may be able
to use this directly, or at least it will show you how to do such
things from C.  If I remember correctly, it does not turn off
TT$M_ESCAPE, it uses pasthru mode instead, but perhaps this is
what you want anyway.

Stew

info-vax@ucbvax.ARPA (06/25/85)

From: stew%lhasa@harvard.ARPA

Whoops!  I said that kermit is available from CU20A via ftp.  I meant
to say CU20B (ecc chip blew in my brain).  It is also available from
CUVMA via bitnet, from the columbia computer center on a tape, and
from okstate via uucp.  If you smother him with thankyous and goodjobs,
you might even get INFO-KERMIT-REQUEST@CU20B to mail you you the
distribution info or even the CKVTIO.C file itself (last resort!).

Stew

info-vax@ucbvax.ARPA (07/16/85)

From: ecsvax!jerryr%mcnc.csnet@csnet-relay.ARPA

I am wondering if the SMG$READ_STRING routine wouldn't be sufficient for this.
I don't think it will give you character waiting information, but from what
I've read (unfortunately not enough time to test it yet) it appears that this
routine uses qio's since you can give it max lengths, io modifiers and custom
terminator blocks.  You should be able to set up a terminator mask which
indicates that all ASCII characters are valid terminators, and receive which
terminator in the separate TERMINATOR-CODE parameter.  There are some rather
cryptic limitations for its use listed under the DISPLAY-ID parameter in the
RUN-TIME LIBRARY REFERENCE which need more investigation on my part.  But
I'd be happy to have someone experiment and report the results.

In fact, I'd be interested in any comments regarding the absence of usable
raw(), etc. routines in the VMS Curses package that comes with VMS "C" V.2.
I'd think (and was going to test this out) that one could use the above
routine for standard input, with the use of a few others to set the
terminator masks and the read modifiers in pre-defined fields which then
would be used by SMG$READ_STRING.  raw() would set the terminator mask
suggested above as well as set the IO$M_NOFILTR read bit, noraw() back
to defaults, echo() reset the IO$M_NOECHO read bit, noecho() set it, etc.
I'm suspecting that it's not as simple as it seems, but then again
*knowing DEC...*

					Jerry Robinson
				    UNC School of Medicine
				    UUCP: ...mcnc!ecsvax!jerryr