Local "echo" during input from keyboard

Requests for features
Post Reply
siggi
Well known member
Posts: 344
Joined: Thu Jul 26, 2007 9:06 am

Local "echo" during input from keyboard

Post by siggi »

Using the current implementation of Z88DK makes input from keyboard using "scanf" hard, because there is no echo of the typed characters on the screen. And it is also not possible to correct/edit the input, before <cr> is pressed.

Example:

#include <stdio.h>

void main(void)
{
int wert;
printf("Wert=");
scanf("%d", &wert);
printf("\nRead: %d\n", wert);
}


This program (compiled with Borland C++ V3.1 and running on a pc) gives that result on the screen:

Wert=351

Read: 351


During reading (scanf) "wert" the typed characters are echoed to the screen and editing (at least backspace) that value during input is possible. After pressing <return> the last value remains on the screen.

Note: the typed <cr> after "351" seems also to be echoed -> 1 empty line

On systems with a real OS (OS-9, Unix), the line echo/edit function is embedded in the OS and is used on every read access (not only "scanf") to "terminal/console devices" (of course not, when files from disk are read).

The OS normally offers also a system-calls to enable/disable echoing (AFAIK "ss_opt" on OS-9 and "ioctl" on Unix), so that a program reading a password (e. g. "login") has the chance to hide the typed password.

Siggi
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

I think outside of z88dk scanf() cooks the terminal into line mode, but as you've spotted there's no such facility in z88dk.

All the z88dk scanf() does is to eventually call fgetc_cons() which is silent.

A way around this is to call fgets() which does offer primitive line editing facilities (fgets() calls fgets_cons() which for most platforms is a fairly noddy editor, but for those platforms with a bit more support (eg z88) you get quite a lot of facilities).

So, effectively what we'd do to fix this is for scanf() to call fgets(stdin...) with a fixed buffer size and then call sscanf() on the string.

It's the presence of the fixed buffer size which makes me slightly reticent to "fix" it in this simple way.
Post Reply