[comp.lang.c] VAX-C immediate char reading

seaotter@athena.mit.edu (12/15/90)

Another question I'm sure has been posted before...

Is there a way under VMS 5.x using Curses (yes, NOT smg$stuff)
to write some function next_avail_char() such that I could write
a code fragment like

	for(;;) {
	  if ((c = next_avail_char()) != '\0') {
	    dostuff();
	  } else {
	    update_something();
	  }
	}

In other words I need to know if there is input waiting and if so,
what it is.

Post or email c/o seaotter@athena.mit.edu or mzraly@ldbvax.dnet.lotus.com
The MIT address is probably better, though.


Thanks,
 Mike



--

| Mike Zraly                     | You should never wear your best trousers |
|                                | when you go out to fight for freedom and |
| via: seaotter@athena.mit.edu   | liberty. -- Henrick Ibson                |

gceych@juliet.caltech.edu (Eychaner, Glenn C.) (12/15/90)

In article <1990Dec14.191104.7874@athena.mit.edu>, seaotter@athena.mit.edu writes...
> 
>Another question I'm sure has been posted before...
> 
>Is there a way under VMS 5.x using Curses (yes, NOT smg$stuff)
>to write some function next_avail_char() such that I could write
>a code fragment like
> 
>	for(;;) {
>	  if ((c = next_avail_char()) != '\0') {
>	    dostuff();
>	  } else {
>	    update_something();
>	  }
>	}
> 
>In other words I need to know if there is input waiting and if so,
>what it is.
> 
>Post or email c/o seaotter@athena.mit.edu or mzraly@ldbvax.dnet.lotus.com
>The MIT address is probably better, though.
> 
> 
>Thanks,
> Mike
> 
> 
> 
>--
> 
>| Mike Zraly                     | You should never wear your best trousers |
>|                                | when you go out to fight for freedom and |
>| via: seaotter@athena.mit.edu   | liberty. -- Henrick Ibson                |

I wanted to post this to see what OTHER people have gotten...my solution is
really weird.
I found that if I ABSOLUTELY COVERED stdscr with windows, performed a
nocrmode() and a noecho(), and then tried a getch() or getstr() (I believe
those are the calls), I get the type of behaviour you described.  However, I
found it difficult to actually enter a key, and it ate up CPU like a demon.
I don't recommend this at all.  I eventually gave up on it.
BTW, according to my CURSES manual, the functions raw() and noraw() are
supposed to return after something like 5 seconds OR a key is pressed.
I ended up calling SMG$CREATE_VIRTUAL_KEYBOARD and SMG$READ_KEYSTROKE.  These
also allow you to read the function keys and arrows and numeric keypad in
applications mode.  In fact, some of my programs are rapidly becoming
curses/smg$ hybrids...seems safe enough as long as you're careful, i.e. use
only one of them for terminal screen output (I hate string descriptors and
passing lots of things by reference).

Glenn Eychaner   |Eychaner@SunCub.Caltech.edu |Remember: It is easier to ride a
40386 N Shore Ln |gceych@iago.caltech.edu     |camel through the eye of a needle
Big Bear City, CA| Big Bear Solar Observatory |than to drive a Buick through the
            92314| !*** G O  N I N E R S ***! |hole in a doughnut.

corwin@sparky.cis.ufl.edu (Jack Rusher) (12/15/90)

The best way to perform the sort of I/O you have mentioned is to
set up an $QIO call that specifies an AST handler to call when your
routine gets input.

As Per (excuse my pseudo-code):

volatile char Ch;

ProcessChar()
{
   DoStuff(Ch);
   $QIO (IO$READVBLK, Channel, etc, Ch, etc, ProcessChar, etc);
}

main()
{
   $QIO (IO$READVBLK, Channel, etc, Ch, etc, ProcessChar, etc);
   while (!done)
      do_non_player_stuff();
}


   Which will call "ProcessChar" when there is stuff to input, and 
will continue to execute in the meantime.  Check out the docs for
$QIO, $ASSIGN and the other stuff in the System Services section of
the VMSHELP files for more information on exact syntax.

   If you do not grok what it has to say, do not dispair!  There will
soon be another solution to your problem.  The GameLib project here
at UF is producing an object library for just this sort of thing.

-Jack Rusher,
corwin@ufl.edu