Re: your mail

Search this archive.

From: Dr. Michael Weller (eowmob@exp-math.uni-essen.de)
Date: Mon 28 Aug 2000 - 13:00:56 IDT


On Sat, 26 Aug 2000, Nicolas Raitman wrote:

> I want to do something like
> this
> 
> scanf("%f", &x);
> 
> do u understand?
> 
> When i use scanf while using the vga graphics scanf seems not to work. In
> the first place no character is printed to the screen while im typing,
> besides, when after ttying to do the scanf i do a gl_copyscreen call the
> number doesnt appear.

Matan's answer is correct, but here are some more details:

As long as you are not in raw keyboard mode, the scanf *should* more or
less work.  However, normally you are coding a games style application and
you want something like vga_getkey for a non-blocking check for key
pressed. Thus, the keyboard is in an unbuffered mode. Normally the kernel
would collect keyboard presses until you hit return and then give a whole
line to scanf. Here, scanf will get a single character or an error
telling: 'No key yet, try again later'. It might well be that the scanf in
the standard libc is not able to cope with these 'kind of' errors and will
fail.

In raw keyboard mode, no ascii codes but scan codes are presented and
scanf can not work.

The echoing of input characters is normally done by the kernel. It cannot
work because svgalib overtook the console handling. svgalib makes no
attempt to emulate this standard behaviour. It would be rather involved
to do and is not among the things svgalib was intended to be used for.

I see two (ok, two and a half) workarounds:

1) Similar to what Matan said, use vga_getch (blocking) or
   vga_getkey (non blocking) to read characters one by one and build a
   text string in memory. You can echo/print these characters yourself
   with gl_printf or gl_write (note that you need to set a font first =>
   see man page). If you want basic line editing (Backspace) you need to
   add this yourself. Convert the text string to float with sscanf or
   atof or whatelse you like.

   I would strongly discourage using raw keyboard mode for this as I'm
   sure you do not want to do the scan code -> ascii code conversion
   yourself (you need to deal with keyboard press/release events and
   national keyboard layouts yourself).
 
2) At anytime in svgalib you can do vga_setmode(TEXT) to return to plain
   textmode. AFAIK even the keyboard is returned to default line editing
   mode in text mode (Please check). Then you could just normally do
   scanf().

2.5) It might suffice to give the input only the first time the program
   starts. If so you can do the scanf() before your first vga_setmode
   call. The vgatest demo works like this.

2.75) If the svgalib application is run from under an X11 window, things
   are different. Svgalib will seek and open a free virtual console itself
   and switch to it. Character and text processing in the original
   X-Window cannot be and is not affected. At any time in svgalib you can
   switch back to the X-Window virtual console with the right Alt-F<n>
   hotkey.

   On exit svgalib will attempt to return to that one too, but I'm unsure
   if it will switch VC's nicely with vga_setmode(TEXT) and
   vga_setmode(<graphics>) on the fly.

   In this case a major problem will be that while the X-Window where the
   svgalib application was started is still fully functional that svgalib
   closed and repointed to the new virtual console all std file handles.

   To cope with that, make your own copy of stdin (unix filehandle 0) with
   the syscall dup() and associate a FILE * pointer to it with fdopen()
   prior to vga_init(). Then use fscanf on that one.

Ok, so that was 2 3/4 possibilities.

Michael.

--

Michael Weller: eowmob@exp-math.uni-essen.de, eowmob@ms.exp-math.uni-essen.de,
or even mat42b@spi.power.uni-essen.de. If you encounter an eowmob account on
any machine in the net, it's very likely it's me.


This archive was generated by hypermail 2.1.4 : Wed 21 Jan 2004 - 22:10:23 IST